ظهور الخطأ التالي أثناء قياس كفاءة النموذج ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].
قمت ببناء مودل LogisticRegression لكن عند محاولة قياس الكفاءة يظهر لي الخطأالتالي:
import numpy as np
from tensorflow.keras.datasets import mnist
from sklearn.linear_model importLogisticRegressionfrom sklearn.pipeline importPipelinefrom tensorflow.keras.utils import to_categorical
from sklearn.metrics import f1_score,precision_score,recall_score,accuracy_score,log_loss
(x_train, y_train),(x_test, y_test)= mnist.load_data()
x_train.shape
image_size = x_train.shape[1]
input_size = image_size * image_size
x_train = np.reshape(x_train,[-1, input_size])/255
x_test = np.reshape(x_test,[-1, input_size])/255#y_train = to_categorical(y_train)#y_test = to_categorical(y_test)
t =LogisticRegression()
t.fit(x_train, y_train)
f1_score(y_test,t.predict(x_test))---------------------------------------------------------------------------ValueErrorTraceback(most recent call last)<ipython-input-1-bbb2bd2287ff>in<module>15 t =LogisticRegression()16 t.fit(x_train, y_train)--->17 f1_score(y_test,t.predict(x_test))1819#ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in f1_score(y_true, y_pred, labels, pos_label, average, sample_weight, zero_division)1097 pos_label=pos_label, average=average,1098 sample_weight=sample_weight,->1099 zero_division=zero_division)11001101~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in fbeta_score(y_true, y_pred, beta, labels, pos_label, average, sample_weight, zero_division)1224 warn_for=('f-score',),1225 sample_weight=sample_weight,->1226 zero_division=zero_division)1227return f
1228~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight, zero_division)1482raiseValueError("beta should be >=0 in the F-beta score")1483 labels = _check_set_wise_labels(y_true, y_pred, average, labels,->1484 pos_label)14851486# Calculate tp_sum, pred_sum, true_sum ###~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in _check_set_wise_labels(y_true, y_pred, average, labels, pos_label)1314raiseValueError("Target is %s but average='binary'. Please "1315"choose another average setting, one of %r."->1316%(y_type, average_options))1317elif pos_label notin(None,1):1318 warnings.warn("Note that pos_label (set to %r) is ignored when "ValueError:Targetis multiclass but average='binary'.Please choose another average setting, one of [None,'micro','macro','weighted'].
السؤال
Meezo ML
قمت ببناء مودل LogisticRegression لكن عند محاولة قياس الكفاءة يظهر لي الخطأالتالي:
ما الحل؟
تم التعديل في بواسطة Meezo ML2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.