I am working with Kaggle's Churn Modeling Dataset (https://www.kaggle.com/shrutimechlearn/churn-modelling), trying to predict customers who are going to leave the service.
The initial dataset looks like this:
RowNumber CustomerId Surname CreditScore Geography Gender Age
0 1 15634602 Hargrave 619 France Female 42
After wrangling the data, the dataset looks like this:
CreditScore Age Tenure Balance NumOfProducts HasCrCard IsActiveMember EstimatedSalary Germany Spain Male
0 619 42 2 0.00 1 1 1 101348.88 0 0 0
I then split the data:
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y, test_size=0.25, random_state = 0)
... fit and predict the model:
from sklearn import tree
dectree_model = tree.DecisionTreeClassifier()
dectree_fit = dectree_model.fit(X_train, y_train)
dectree_prediction = dectree_fit.fit(X_train, y_train)
I then try to validate the model:
print(metrics.confusion_matrix(y_test, dectree_prediction))
print(metrics.classification_report(y_test, dectree_prediction))
but then I get this error:
TypeError Traceback (most recent call last)
<ipython-input-55-c8b0efbc711d> in <module>
1 # Decision tree
----> 2 print(metrics.confusion_matrix(y_test,
dectree_prediction))
3 print(metrics.classification_report(y_test,
dectree_prediction))
...
TypeError: Expected sequence or array-like, got <class 'sklearn.tree._classes.DecisionTreeClassifier'>
question from:
https://stackoverflow.com/questions/65863822/typeerrorexpected-sequence-or-array-like-when-assessing-decision-tree-model-in 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…