from sklearn import tree
#Just a basic program. I am just a beginner.
clf = tree.DecisionTreeClassifier()
X = [[190,84,9], [180,80,9], [175,67,8],[165,60,6],[180,64,7],[180,74,8],[154,56,5],[162,60,8],
[184,76,9],[142,46,5],[164,69,8]]
Y = ["Male", "Male", "Male", "Female", "Female", "Male", "Female", "Female", "Male", "Female",
"Female"]
clf = clf.fit(X,Y)
prediction = clf.predict([169,58,8])
print(prediction)
这是我的python代码。我已经成功安装了软件包,但是我收到了这个错误。我使用Spyder编辑器的Anaconda发行版。 请帮忙。谢谢!
答案 0 :(得分:0)
尝试更改导入语句
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
X = [[190,84,9], [180,80,9], [175,67,8],[165,60,6],[180,64,7],[180,74,8],[154,56,5],[162,60,8],
[184,76,9],[142,46,5],[164,69,8]]
Y = ["Male", "Male", "Male", "Female", "Female", "Male", "Female", "Female", "Male", "Female",
"Female"]
clf = clf.fit(X,Y)
prediction = clf.predict([169,58,8])
print(prediction)
答案 1 :(得分:0)
此代码的错误是使用为预测函数传递的参数。 更正的代码是
from sklearn import tree
#Just a basic program. I am just a beginner.
clf = tree.DecisionTreeClassifier()
X = [[190,84,9], [180,80,9], [175,67,8],[165,60,6],[180,64,7],[180,74,8],[154,56,5],[162,60,8],
[184,76,9],[142,46,5],[164,69,8]]
Y = ["Male", "Male", "Male", "Female", "Female", "Male", "Female", "Female", "Male", "Female",
"Female"]
clf = clf.fit(X,Y)
prediction = clf.predict([[169,58,8]])
print(prediction)
它给出了正确的输出['女性']。 感谢。