python - 使用 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)
感谢帮助!
解决方案
推荐阅读
- c# - 实体框架,如何使这个更通用以编写更少的代码
- javascript - 处理名称包含 @ 符号的 json 属性
- redux - 发布请求 redux thunk
- sql-server - Visual Studio 数据库项目 - 使用 SQLCMD 变量定义文件大小
- discord - 直到 Discord Bot 发送下一条消息的时间延迟
- css - 将文本溢出:省略号文本转换为全文的“浮动”视图
- python - 在 Python 线程中使用标准输出管道
- vaadin - 包括 vaadin-combo-box-item 的样式
- c# - 如何垂直引导我的数据网格查询
- java - Tomcat 6 中未部署 Soap Web 服务