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

huangapple go评论74阅读模式
英文:

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

问题

我使用下面的代码行在sklearn中拟合模型:

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

但是我遇到了这个错误:
ValueError: 无法将字符串转换为浮点数:'Male'

可能出了什么问题?

英文:

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?

答案1

得分: 0

y_train中包含字符串,它们应该是与类别相关的数字。

例如:0表示男性,1表示女性等。

在训练后获取预测结果后,您必须显示与数字相关的类别标签。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月24日 03:45:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定