提问人:frencis1 提问时间:10/20/2023 最后编辑:frencis1 更新时间:10/20/2023 访问量:24
预测始终多数类的 Lightgbm 模型
Lightgbm model that predicts always majority class
问:
我有一个带有 3 个类的 Lightgbm 分类器多类。
使用以下代码,我拟合了模型:
over = ADASYN(sampling_strategy='not majority', random_state=7, n_jobs=-1)
under = RandomUnderSampler(sampling_strategy='majority', random_state=7)
X_resampled, y_resampled = over.fit_resample(X_train, y_train)
X_resampled, y_resampled = under.fit_resample(X_resampled, y_resampled)
clf = lightgbm.LGBMClassifier(**lgbm_params, nthreads=-1)
clf.class_weight = {0.0: 1/dfc.loc[0.0], 1.0: 1/dfc.loc[1.0], 2.0: 1/dfc.loc[2.0]}
clf.fit(X_resampled.drop('weight', axis=1), y_resampled)#, sample_weight=X_resampled['weight'])
y_pred = clf.predict(X_val.drop('weight', axis=1))
print('========== CLF ONLY ==========')
print(classification_report(y_pred, y_val))
当我运行 fit 方法时,这是我classification_report:
========== CLF ONLY ==========
precision recall f1-score support
0.0 0.77 1.00 0.87 23130
1.0 0.91 0.46 0.61 6774
2.0 0.91 0.44 0.59 6769
accuracy 0.79 36673
macro avg 0.86 0.63 0.69 36673
weighted avg 0.82 0.79 0.77 36673
但是,使用此代码,即使使用训练分类器的相同数据,预测的类也始终为 0.0
num = pd.DataFrame(MinMaxScaler().fit_transform(X)).iloc[-1:].copy()
result = model.predict_proba(num, verbose=-1)
为什么会这样?提前致谢
答: 暂无答案
评论