复习笔记2——线性回归、决策树、聚类
文章目录
一、.线性回归
fit_intercept : 布尔型参数,表示是否计算该模型截距。可选参数。
normalize : 布尔型参数,若为True,则X在回归前进行归一化。可选参数。默认值为False。
copy_X : 布尔型参数,若为True,则X将被复制;否则将被覆盖。 可选参数。默认值为True。
n_jobs : 整型参数,表示用于计算的作业数量;若为-1,则用所有的CPU。可选参数。默认为1
positive=False#当设置为'True'时,强制系数为正。这选项仅支持密集阵列。
rint(model.coef_)#打印线性方程中的w
print(model.intercept_)#打印w0 就是线性方程中的截距b
3.sklearn.metrics
模块包括评分函数、性能指标和成对度量和距离计算。
F1-score: 2*(P*R)/(P+R)。参考《sklearn中 F1-micro 与 F1-macro区别和计算原理》
导入:from sklearn import metrics
分类指标
accuracy_score(y_true, y_pre)#精度
log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None, labels=None)交叉熵损失函数
auc(x, y, reorder=False)
ROC曲线下的面积;较大的AUC代表了较好的performance。
AUC:roc_auc_score(y_true, y_score, average=‘macro’, sample_weight=None)
f1_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’, sample_weight=None) F1值
precision_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’,) 查准率
recall_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’, sample_weight=None) 查全率
roc_curve(y_true, y_score, pos_label=None, sample_weight=None, drop_intermediate=True)
计算ROC曲线的横纵坐标值,TPR,FPR
TPR = TP/(TP+FN) = recall(真正例率,敏感度)
FPR = FP/(FP+TN)(假正例率,1-特异性)
classification_report(y_true, y_pred)#分类结果分析汇总
f1_score中关于参数average的用法描述:
‘micro’:Calculate metrics globally by counting the total true positives, false negatives and false positives.
‘micro’:通过先计算总体的TP,FN和FP的数量,再计算F1
‘macro’:Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
‘macro’:分布计算每个类别的F1,然后做平均(各类别F1的权重相同)
回归指标
explained_variance_sc