I am trying to run a Multiple Linear Regression/Lasso/Ridge regression on Python and to do that I have to split my data into train and test. However, when I try to do this I get the following error message "ValueError: could not convert string to float: 'Azerbaijan'". My dataset contains GDP growth values for each country. The GDP growth value for this country does not seem to be different than the others, so I do not understand the reason behind the error. EF1 being the name of my dataset, my code is as follows:
X = EF1.iloc[:, :-1]
#output
Y = EF1.iloc[:, -1]
x_train, x_test, y_train, y_test = train_test_split(
EF1.iloc[:, :-1], EF1.iloc[:, -1],
test_size = 0.25)
print("Train data shape of X = % s and Y = % s : "%(
x_train.shape, y_train.shape))
print("Test data shape of X = % s and Y = % s : "%(
x_test.shape, y_test.shape))
# Apply multiple Linear Regression Model
lreg = LinearRegression()
lreg.fit(x_train, y_train)
# Generate Prediction on test set
lreg_y_pred = lreg.predict(x_test)
# calculating Mean Squared Error (mse)
mean_squared_error = np.mean((lreg_y_pred - y_test)**2)
print("Mean squared Error on test set : ", mean_squared_error)
# Putting together the coefficient and their corrsponding variable names
lreg_coefficient = pd.DataFrame()
lreg_coefficient["Columns"] = x_train.columns
lreg_coefficient['Coefficient Estimate'] = pd.Series(lreg.coef_)
print(lreg_coefficient) ```