如何在Python中拟合两个列表?
我想与Sklearn一起使用这两个列表,但最后说:无法将字符串转换为float ...您能帮我吗?
from sklearn import tree
x = ['BMW', '20000miles', '2010']
y = ['12000']
clf = tree.DecisionTreeClassifier()
clf = clf.fit(x, y)
I want to fit these two lists with sklearn but at the end it say : could not convert string to float... can you help me with that?
from sklearn import tree
x = ['BMW', '20000miles', '2010']
y = ['12000']
clf = tree.DecisionTreeClassifier()
clf = clf.fit(x, y)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
许多事情。
从文档中:
您的输入应为形状(n_samples,n_features)。您有1个具有3个功能的样本吗?我想这没关系,但是拟合1个样本并没有太多意义。
但是您的模型无法解释“ BMW”,它预计会有浮动。因此,如果您有3种类型的汽车,宝马,奥迪,梅赛德斯,将它们转换为一个数字,即1,2,3代表它们。
A number of things.
From the documentation:
Your input to fit should be an array of shape (n_samples, n_features). Do you have 1 sample with 3 features? I suppose that is ok, but fitting 1 sample doesn't make much sense.
But your model can't interpret "BMW", it expects a float. So if you have 3 types of cars, BMW, AUDI, MERCEDES, convert them to a number, i.e. 1,2,3 to represent them.