我对ML相当陌生,现在我正在预测中型数据集中的员工流失.我已经能够顺利运行一切,但是,由于数据集不平衡,我一直在try 向模型添加权重,因此通过失go 一些精度,我在正类中获得更多召回.当我try 在scikit-learn
RandomForestClassifier
中这样做时,问题来了,我try 了不同的方法,通过为值创建独立的dict,将dict直接添加到参数中,但它根本不会影响模型.结果总是保持不变,多数阶级的成绩总是比少数阶级好.
对于其他型号,我完全没有问题.
我这里是不是做错了什么?
(这是我正在使用的数据集,如果它对任何人有帮助的话:https://www.kaggle.com/datasets/bhanupratapbiswas/hr-analytics-case-study)
模型代码:
#Running the model with the best hyperparameters
weight_dict = {0: 0.59, 1: 3.12}
model = RandomForestClassifier(bootstrap=False, criterion='gini', max_depth=24, max_features='log2', min_samples_leaf=1, min_samples_split=2, n_estimators=200, class_weight=weight_dict)
model.fit(X_train_smote, y_train_smote)
y_pred = model.predict(X_test_outliers)
#Printing the results
print('Accuracy:', accuracy_score(y_test, y_pred))
print('AUC-ROC Score:', roc_auc_score(y_test, y_pred))
print('Classification Report:', classification_report(y_test, y_pred))
#Plotting the confusion matrix
plt.figure()
sns.heatmap(confusion_matrix(y_test, y_pred), annot=True, fmt='d', cmap='Blues')
plt.xlabel('Predicted label')
plt.ylabel('True label')
plt.xticks(rotation=45)
我预计少数族裔阶层会有更多的回忆,而多数族裔阶层会失go 一些记忆和回忆.
我已经判断了过go 的问题和答案,但我已经应用了不同答案的解决方案,但没有成功.
谢谢!