Search code examples
pythonscikit-learnregressiondata-sciencedata-analysis

i want to fit a model in sklearn but it throws an error. below are the lines of code i used


I used the lines of code below to fit a model in sklearn.

linearmodel =LinearRegression()
linearmodel.fit(x_train, y_train)

but I get this error: ValueError: could not convert string to float: 'Male'

what could be wrong?


Solution

  • Your y_train contains Strings, they should be numbers associated to a class.

    Eg : 0 for Male, 1 for Female etc

    After you get the prediction out after training, you have to display the class label associated to the number.