多类分类cross_val_score的精度和召回率给我相同的结果

时间:2018-11-09 16:02:46

标签: python machine-learning scikit-learn neural-network multiclass-classification

在我的Y值中,我有4个类。因此,显然这是一个多类分类问题。

我正在使用MultinomialNB作为模型。而且我正在做10倍交叉验证,但是,我在Precision,Recall和F1上得到了相同的价值。

这是我的代码:

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.naive_bayes import MultinomialNB
from sklearn.multiclass import OneVsRestClassifier
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import LabelEncoder

scaler = MinMaxScaler()
X_train, X_test, y_train, y_test = train_test_split(yelp_joined_data, Y_label_encoded)


X_train=scaler.fit_transform(X_train)
X_test = scaler.fit_transform(X_test)

# fix random seed
seed = 7
numpy.random.seed(seed)

kfold = KFold(n_splits=10, shuffle=True, random_state=seed)

clf = OneVsRestClassifier(MultinomialNB(alpha=0.01))

prec_res_test=cross_val_score(clf, X_train, y_train.values.ravel(), cv=kfold, n_jobs=1,scoring='precision_micro')
prec_res_test.mean() ## value coming as 0.5090949570838452

recall_res_test=cross_val_score(clf, X_train, y_train.values.ravel(), cv=kfold, n_jobs=1,scoring='recall_micro')
recall_res_test.mean() # value coming as 0.5090949570838452

rf1_res_test=cross_val_score(clf, X_train, y_train.values.ravel(), cv=kfold, n_jobs=1,scoring='f1_micro')
rf1_res_test.mean() # value coming as 0.5090949570838452

在这里,我不能使用通常的精度作为scoring参数,因为这是一个多类问题。

有人可以在我做错事情的地方帮助我吗?

0 个答案:

没有答案