我正在尝试使用Logistic Regression from SciKit.预测一组标签。我的数据确实不平衡(“0”比“1”标签多得多),因此我必须在交叉验证步骤中使用F1 score metric来“平衡”结果。
[Input]
X_training, y_training, X_test, y_test = generate_datasets(df_X, df_y, 0.6)
logistic = LogisticRegressionCV(
Cs=50,
cv=4,
penalty='l2',
fit_intercept=True,
scoring='f1'
)
logistic.fit(X_training, y_training)
print('Predicted: %s' % str(logistic.predict(X_test)))
print('F1-score: %f'% f1_score(y_test, logistic.predict(X_test)))
print('Accuracy score: %f'% logistic.score(X_test, y_test))
[Output]
>> Predicted: [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
>> Actual: [0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 1]
>> F1-score: 0.285714
>> Accuracy score: 0.782609
>> C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:958:
UndefinedMetricWarning:
F-score is ill-defined and being set to 0.0 due to no predicted samples.
我当然知道这个问题与我的数据集有关:它太小了(它只是真实数据集的一个样本)。但是,有人可以解释我看到的“UndefinedMetricWarning”警告的含义吗?幕后实际上发生了什么?
最佳答案
看来这是一个已知的here错误,已经修复,我想您应该尝试更新sklearn。
关于python - Scikit F得分指标错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31677218/