```真正(True Positive , TP)：被模型预测为正的正样本。

#### 1.1.1 sklearn相应的包

`sklearn.metrics.confusion_matrix`

```from sklearn.metrics import confusion_matrix
# y_pred是预测标签
y_pred, y_true =[1,0,1,0], [0,0,1,0]
confusion_matrix(y_true=y_true, y_pred=y_pred)
# array([[2, 1],
#        [0, 1]], dtype=int64)```

### 1.2 准确率(Accuracy)

#### 1.2.1 sklearn相应的包

`sklearn.metrics.accuracy_score`

```from sklearn.metrics import accuracy_score
# y_pred是预测标签
y_pred, y_true=[1,2,3,4], [2,2,3,4]
accuracy_score(y_true=y_true, y_pred=y_pred)
# 0.75```

### 1.3 精确率(Precision): 预测正确的正样本占所有预测为正样本的比例

#### 1.3.1 sklearn相应的包

`sklearn.metrics.precision_score`

```from sklearn.metrics import precision_score
# y_pred是预测标签
y_pred, y_true =[1,0,1,0], [0,0,1,0]
precision_score(y_true=y_true, y_pred=y_pred)
# 0.5```

### 1.4 召回率 (Recall): 预测正确的正样本占所有正样本比例

#### 1.4.1 sklearn

`sklearn.metrics.recall_score`

```from sklearn.metrics import recall_score
# y_pred是预测标签
y_pred, y_true =[1,0,1,0], [0,0,1,0]
recall_score(y_true=y_true, y_pred=y_pred)
# 1.0```

### 1.5 F1 score

#### 1.5.1 sklearn相应的包

`sklearn.metrics.f1_score`

```from sklearn.metrics import f1_score
# y_pred是预测标签
y_pred, y_true =[1,0,1,0], [0,0,1,0]
f1_score(y_true=y_true, y_pred=y_pred)
# classification_report可以直接输出各个类的precision recall f1-score support
from sklearn.metrics import classification_report
# y_pred是预测标签
y_pred, y_true =[1,0,1,0], [0,0,1,0]
print(classification_report(y_true=y_true, y_pred=y_pred))```

### 1.7 ROC曲线

#### 1.7.1 sklearn相应的包

`sklearn.metrics.roc_curve` , `sklearn.metrics.auc`

```import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
# y_test：实际的标签, dataset_pred：预测的概率值。
fpr, tpr, thresholds = roc_curve(y_test, dataset_pred)
roc_auc = auc(fpr, tpr)
#画图，只需要plt.plot(fpr,tpr),变量roc_auc只是记录auc的值，通过auc()函数能计算出来
plt.plot(fpr, tpr, lw=1, label='ROC(area = %0.2f)' % (roc_auc))
plt.xlabel("FPR (False Positive Rate)")
plt.ylabel("TPR (True Positive Rate)")
plt.title("Receiver Operating Characteristic, ROC(AUC = %0.2f)"% (roc_auc))
plt.show()```

### 1.8 AUC（Area Under Curve）

AUC即为ROC曲线下的面积(ROC的积分), 通常大于0.5小于1.
AUC值(面积)越大的分类器，性能越好.

#### 1.8.1 sklearn相应的包

`sklearn.metrics.roc_auc_score`

```from sklearn.metrics import roc_auc_score
# y_test：实际的标签, dataset_pred：预测的概率值。
roc_auc_score(y_test, dataset_pred)```

### 1.10 多分类

`precision_recall_fscore_support` : 计算每个分类的precision, recall, fscore和support

## 2. 回归问题

### 2.1 平均绝对误差（MAE）

#### 2.1.1 sklearn相应包

`sklearn.metrics.mean_absolute_error`

```from sklearn.metrics import mean_absolute_error
y_true, y_pred = [3, -0.5, 2, 7], [2.5, 0.0, 2, 8]
mean_absolute_error(y_true, y_pred)
# 0.5```

### 2.2 平均平方误差（MSE）

#### 2.2.1 sklearn相应包

`sklearn.metrics.mean_squared_error`

```from sklearn.metrics import mean_squared_error
y_true, y_pred = [3, -0.5, 2, 7], [2.5, 0.0, 2, 8]
mse = mean_squared_error(y_true, y_pred)
# 0.375
rmse = np.sqrt(mse)
# 0.6123724356957945```

### 2.4 均方对数误差(MSLE)

#### 2.4.1 sklearn对应包

`sklearn.metrics.mean_squared_log_error`

### 2.5 中值绝对误差(MedAE)

#### 2.5.1 sklearn对应包

`sklearn.metrics.mean_squared_log_error`

### 2.5 可释方差得分 (EVS)

#### 2.5.1 sklearn相关包

`sklearn.metrics.explained_variance_score`

### 2.6 决定系数(Coefficient of Determination)

R2 决定系数(r2_score) 判断回归方程的拟合程度.

#### 2.6.1 sklearn相关包

`sklearn.metrics.r2_score`

```from sklearn.metrics import r2_score
y_true, y_pred = [3, -0.5, 2, 7], [2.5, 0.0, 2, 8]
r2_score(y_true, y_pred)```

## 3. 聚类问题

### 3.1 外部指标

#### 3.1.1 常用外部指标

Jacccard系数(Jaccard Coeffient, 简称JC)

FM指数(Fowlkes and Mallows Index, 简称FMI)

Rand指数(Rand Index, 简称RI)

#### 3.1.3 sklearn相应包

```fowlkes_mallows_score

### 3.2 内部指标

#### 3.2.1 常用内部指标

DB指数(Davies-Bouldin Index, 简称DBI)
DBI的可能最小值为0, 值越小越好.
Dunn指数(Dunn Index, 简称DI)
DI值越大越好

#### 3.2.2 轮廓系数（Silhouette coefficient）

a(i)为样本i与簇内其它样本的平均距离, b(i)为样本i与其它某簇样本的平均距离, 多个簇b(i)取最小.

#### 3.2.3 sklearn相应包

```sklearn.metrics.davies_bouldin_score
sklearn.metrics.silhouette_score
sklearn.metrics.silhouette_score_samples```