【机器学习要点记录】实用代码
程序员文章站
2022-03-03 19:05:02
总是想不起来怎么查找,这里记录一下sklearn.metrics.SCORERS.keys()dict_keys(['explained_variance', 'r2', 'max_error', 'neg_median_absolute_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_mean_squared_log_error', 'neg_root_mean_squared_error', 'neg_mea...
1、cross_val_score 能用的分数指标
sklearn.metrics.SCORERS.keys()
dict_keys(['explained_variance', 'r2', 'max_error', 'neg_median_absolute_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_mean_squared_log_error', 'neg_root_mean_squared_error', 'neg_mean_poisson_deviance', 'neg_mean_gamma_deviance', 'accuracy', 'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted', 'balanced_accuracy', 'average_precision', 'neg_log_loss', 'neg_brier_score', 'adjusted_rand_score', 'homogeneity_score', 'completeness_score', 'v_measure_score', 'mutual_info_score', 'adjusted_mutual_info_score', 'normalized_mutual_info_score', 'fowlkes_mallows_score', 'precision', 'precision_macro', 'precision_micro', 'precision_samples', 'precision_weighted', 'recall', 'recall_macro', 'recall_micro', 'recall_samples', 'recall_weighted', 'f1', 'f1_macro', 'f1_micro', 'f1_samples', 'f1_weighted', 'jaccard', 'jaccard_macro', 'jaccard_micro', 'jaccard_samples', 'jaccard_weighted'])
2、目录下文件
root = os.getcwd()
files_list = []
for root,dirs,files in os.walk(root):
for file in files:
if '.csv' in file:
files_list.append(file)
files_list
3、上采样
from imblearn.over_sampling import SMOTE
sm = SMOTE(random_state=42)
X_train_bl, y_train_bl = sm.fit_sample(X_train, y_train)
4、分类报告
from sklearn.metrics import classification_report
print("\n分类报告:\n{0}".format(classification_report(y_test, y_predict_gbd, target_names=["0", "1"])))
5、方差过滤
X = X[(X.var() > 0).index]
6、互信息法
from sklearn.feature_selection import mutual_info_classif as MIC
X_mic = X.loc[:, MIC(X_var, y, random_state=42) > 0]
ps:一定要固定随机种子,否则每次运行结果都会不一样
本文地址:https://blog.csdn.net/lvhuike/article/details/109045995