Answers for "TypeError: Expected sequence or array-like, got <class 'sklearn.tree._classes.DecisionTreeClassifier'>"

1

TypeError: Expected sequence or array-like, got <class 'sklearn.tree._classes.DecisionTreeClassifier'>

#It depends on your case but for me it was this
#   WRONG CODE IS BELOW
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
acc = accuracy_score(y_test, predictions)
# you dont test the accuracy of the model directly what you need to do is this:
# RIGHT CODE
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
acc = accuracy_score(y_test, predictions)
print(acc)
# you can see that I made a prediction and then measured the (next line =>)
# accuracy of this prediction
#If you have any other issues checkout this link
https://stackoverflow.com/questions/39745807/typeerror-expected-sequence-or-array-like-got-estimator
Posted by: Guest on April-20-2022

Code answers related to "TypeError: Expected sequence or array-like, got <class 'sklearn.tree._classes.DecisionTreeClassifier'>"

Python Answers by Framework

Browse Popular Code Answers by Language