from sklearn.utils import shuffle
df_concat = shuffle(df_concat)
df = df_concat
X = df.loc[:, df.columns != 'NEWACCT_NO']
X = X.loc[:, X.columns != 'CURRENT_MTH_CHURN']
X = X.values
y = df.CURRENT_MTH_CHURN.values # Target variable
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.33, random_state = 1)
#Train the model with the help of DecisionTreeClassifie
clf = DecisionTreeClassifier(class_weight="balanced")
clf = clf.fit(X_train,y_train)
#At last we need to make prediction. It can be done with the help of following script −
y_pred = clf.predict(X_test)
#Next, we can get the accuracy score, confusion matrix and classification report as follows −
from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
result = confusion_matrix(y_test, y_pred)
print("Confusion Matrix:")
print(result)
result1 = classification_report(y_test, y_pred)
print("Classification Report:",)
print (result1)
result2 = accuracy_score(y_test,y_pred)
print("Accuracy:",result2)
Вывод:
Confusion Matrix:
[[8238 0]
[ 0 1066]]
Classification Report:
precision recall f1-score support
0 1.00 1.00 1.00 8238
1 1.00 1.00 1.00 1066
accuracy 1.00 9304
macro avg 1.00 1.00 1.00 9304
weighted avg 1.00 1.00 1.00 9304
Accuracy: 1.0
Несмотря на то, что train_test_split делит обучающие и тестовые данные случайным образом, кроме этого, я также использовал sklearn.utils shuffle, но все равно получаю 100% точность на тестовых данных.
Невозможно определить ошибку.
Также попытался удалить параметр class_weight = "сбалансированный", но результаты те же.
Требуется совет экспертов, пожалуйста .