Reputation:
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)
This is the python code that I have. I have successfully installed the packages, yet I am getting this error. I use the Anaconda distribution with the spyder editor. Please help. Thanks!
Upvotes: 0
Views: 4840
Reputation:
The error with this code is with the argument passed for the predict function. The corrected code is
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)
And it gives the correct output as ['Female']. Thanks.
Upvotes: 1
Reputation: 3310
Try changing the import statement
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)
Upvotes: 0