绘制用于机器学习的校准曲线

时间:2020-04-15 08:04:10

标签: python

我有下面的代码,该代码仅适用于二进制类,因此如何使用三个类。

from sklearn.tree import DecisionTreeClassifier
import pandas as pd
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import scikitplot as skp


orgnal_data = pd.read_excel("movie.xls")

# Program extracting first column
text = orgnal_data.iloc[:,0]
lable = orgnal_data.iloc[:,1]

x_train,x_test,y_train,y_test=train_test_split(fe,lable,test_size=0.30,random_state=40)


DT = DecisionTreeClassifier()
DT_y = DT.fit(x_train,y_train).predict(x_test)

clf_names = ['Decision Tree']
skp.metrics.plot_calibration_curve(y_test,DT_y,clf_names)
plt.show()

1 个答案:

答案 0 :(得分:1)

由于您使用scikit-plot模块,所以没有针对多类问题的功能。

阅读源代码here

此功能目前仅适用于二进制分类。

因此,您可以1)修改源代码或2)打开github问题并请求针对多类问题的函数。

编辑1:

使用scikit-learn,您可以使用一些ML模型来处理多类问题。例如,对于LinearSVC函数here,多类支持是根据“一对多休息”方案处理的。

因此,您实际上可以拥有这样的模型,然后分别针对每种情况(一个VS休止符)使用plot_calibration_curve函数。