📊 混淆矩阵
分类评估的基础
|
预测正类 |
预测负类 |
| 实际正类 |
TP (真阳性) |
FN (假阴性) |
| 实际负类 |
FP (假阳性) |
TN (真阴性) |
from sklearn.metrics import confusion_matrix
y_pred = model.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
print(cm)
📉 回归指标
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
# 均方误差 (MSE)
mse = mean_squared_error(y_test, y_pred)
# 均方根误差 (RMSE)
rmse = np.sqrt(mse)
# 平均绝对误差 (MAE)
mae = mean_absolute_error(y_test, y_pred)
# R² 决定系数 (0-1, 越大越好)
r2 = r2_score(y_test, y_pred)
print(f"MSE: {mse:.4f}")
print(f"RMSE: {rmse:.4f}")
print(f"MAE: {mae:.4f}")
print(f"R²: {r2:.4f}")