首页 > 解决方案 > 使用 pandas crosstab 和 pandas_ml ConfusionMatrix 创建混淆矩阵的问题

问题描述

对于顺序模型,尝试将“实际”值与“预测”值进行比较。“实际”值包含在数据框中,而“预测”值是由 model.predict 函数生成的数组。我得到了很多不匹配,以及各种错误,包括“数据必须是一维的”、“ValueError:错误的项目数传递了 1,放置意味着 1406”等。
我尝试了 pd.values、pd.values 的各种组合。 values.tolist(),尝试制作数据框的数组等。

train_set_split, test_set_split = split_train_test(churn_no_NA, 0.2)
train_set_withID = train_set_split
test_set_withID = test_set_split
X_train = train_set_split.drop("customerID", axis=1)
y_train = train_set_split[["Churn"]]
X_test = test_set_split.drop("customerID", axis=1)
y_test = test_set_split[["Churn"]]
...
model = Sequential()
...
y_predict = model.predict_classes(X_test)
...
confusion_matrix = ConfusionMatrix(y_test, y_predict)
print("Confusion matrix:\n%s" % confusion_matrix) 

感谢帮助!

标签: pythonpandassklearn-pandas

解决方案


推荐阅读