【发布时间】:2018-10-18 05:09:31
【问题描述】:
如何找到通过运行决策树算法获得的输出的整体准确度。我能够获得活跃用户输入的前五个类别标签,但我获得了 X_train 和 Y_train 数据集的准确度使用 accuracy_score()。假设我得到了五个最佳推荐。我希望获得每个类别标签的准确度,并在这些标签的帮助下获得输出的整体准确度。请提出一些想法。
我的 python 脚本在这里: 这里的事件是不同的类标签
DTC= DecisionTreeClassifier()
DTC.fit(X_train_one_hot,y_train)
print("output from DTC:")
res=DTC.predict_proba(X_test_one_hot)
new=list(chain.from_iterable(res))
#Here I got the index value of top five probabilities
index=sorted(range(len(new)), key=lambda i: new[i], reverse=True)[:5]
for i in index:
print(event[i])
Here is the sample code which i tried to get the accuracy for the predicted class labels:
here index is the index for the top five probability of class label and event is the different class label.
for i in index:
DTC.fit(X_train_one_hot,y_train)
y_pred=event[i]
AC=accuracy_score((event,y_pred)*100)
print(AC)
【问题讨论】:
-
请分享您到目前为止尝试过的内容(代码和结果),否则您的问题太宽泛了。
-
我已经使用 predict_proba() 来获取类标签的概率,然后我检索了与这些概率相关的前 5 个类,现在我想要这些类中的每一个的准确性。我已经用示例代码编辑了我的帖子。
-
y_train 的形状是什么?
-
y_train的形状是-(21890,)
-
像这样构造一个 y_hat(class):y_hat(class) = 1 如果期望的类在前 5 个类中,否则为 0。然后计算 y_train 到 y_hat 的准确度分数
标签: python machine-learning scikit-learn