Logistic regression on One-hot encoding

Viewed 16409

I have a Dataframe (data) for which the head looks like the following:

          status      datetime    country    amount    city  
601766  received  1.453916e+09    France       4.5     Paris
669244  received  1.454109e+09    Italy        6.9     Naples

I would like to predict the status given datetime, country, amount and city

Since status, country, city are string, I one-hot-encoded them:

one_hot = pd.get_dummies(data['country'])
data = data.drop(item, axis=1) # Drop the column as it is now one_hot_encoded
data = data.join(one_hot)

I then create a simple LinearRegression model and fit my data:

y_data = data['status']
classifier = LinearRegression(n_jobs = -1)
X_train, X_test, y_train, y_test = train_test_split(data, y_data, test_size=0.2)
columns = X_train.columns.tolist()
classifier.fit(X_train[columns], y_train)

But I got the following error:

could not convert string to float: 'received'

I have the feeling I miss something here and I would like to have some inputs on how to proceed. Thank you for having read so far!

2 Answers
Related