Python 利用混淆矩阵评价决策树的性能

Python 利用混淆矩阵评价决策树的性能,python,pandas,dataframe,spyder,orange,Python,Pandas,Dataframe,Spyder,Orange,嗨,我想用混淆矩阵来评估决策树的性能。我已经为它编写了函数,但不确定如何使用预测标签和测试标签(不确定要创建或编码哪个数据帧)。请有人看看,并建议可以在这里做什么(看看最后几行代码) 代码: 谢谢 以下是树和混淆矩阵的代码: # Create the tree tree = DecisionTreeClassifier(max_depth=6, class_weight='balanced') tree.fit(X_train,y_train) #create array of probabi

嗨,我想用混淆矩阵来评估决策树的性能。我已经为它编写了函数,但不确定如何使用预测标签和测试标签(不确定要创建或编码哪个数据帧)。请有人看看,并建议可以在这里做什么(看看最后几行代码)

代码:


谢谢

以下是树和混淆矩阵的代码:

# Create the tree
tree = DecisionTreeClassifier(max_depth=6, class_weight='balanced')
tree.fit(X_train,y_train)

#create array of probabilities
y_test_predict_proba = tree1.predict_proba(X_test)

# calc confusion matrix
y_test_predict = tree.predict(X_test[columns])
print("Confusion Matrix Tree : \n", confusion_matrix(y_test, y_test_predict),"\n")
print("The precision for Tree is ",precision_score(y_test, y_test_predict)) 
print("The recall for Tree is ",recall_score(y_test, y_test_predict),"\n")  

您没有发布您的树代码,因此我无法在您的树上应用我的代码

我已使用SkltReelLearner作为决策树。@gtomer请再次查看代码。我试图使用你的代码,但没有成功。y_test_predict1=test_data_tab.predict(test_data_tab[:,5:])print(“混淆矩阵树1:\n”,混淆矩阵(预测的类别标签,y_test_predict1),“\n”)print(“树1的精度是”,精度分数(预测的类别标签,y_test_predict1))print(“树1的召回是”“\n”)我刚刚在上面的代码中添加了一行***************************************************************************************这里*********************************************************************************************************************************以突出显示树代码我在您的新代码中没有找到DecisionTreeClassifier。我已经修改了我的代码以包含树。我真的无法理解如何将此代码应用到我的树中。
# Create the tree
tree = DecisionTreeClassifier(max_depth=6, class_weight='balanced')
tree.fit(X_train,y_train)

#create array of probabilities
y_test_predict_proba = tree1.predict_proba(X_test)

# calc confusion matrix
y_test_predict = tree.predict(X_test[columns])
print("Confusion Matrix Tree : \n", confusion_matrix(y_test, y_test_predict),"\n")
print("The precision for Tree is ",precision_score(y_test, y_test_predict)) 
print("The recall for Tree is ",recall_score(y_test, y_test_predict),"\n")