天天看点

混淆矩阵 精准率 召回率 PR曲线

混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线
import numpy as np
from sklearn.pipeline import Pipeline
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error
from sklearn.linear_model import LogisticRegression
from sklearn import datasets
from sklearn.multiclass import OneVsRestClassifier
from sklearn.multiclass import OneVsOneClassifier
from sklearn.metrics import precision_recall_curve

def LassoRegression(degree):
    return Pipeline([
        ("poly", PolynomialFeatures(degree=degree)),
        ("std_scaler", StandardScaler()),
        ("logic", LogisticRegression())
    ])

digits=datasets.load_digits()
X=digits.data
y=digits.target.copy()
y[digits.target==9]=1
y[digits.target!=9]=0

train_X,test_X,train_y,test_y = train_test_split(X,y,test_size=0.2,random_state=666)
# logis=LogisticRegression(multi_class="multinomial",solver="newton-cg")
logis=LogisticRegression()
logis.fit(train_X,train_y)
print(logis.score(test_X, test_y))

precision,recall,thresholds=precision_recall_curve(test_y,logis.decision_function(test_X))

plt.plot(thresholds,precision[:-1])
plt.plot(thresholds,recall[:-1])
plt.show()


           
混淆矩阵 精准率 召回率 PR曲线
混淆矩阵 精准率 召回率 PR曲线

继续阅读