# 匯入資料集
from sklearn import datasets
import warnings
warnings.filterwarnings(
'ignore'
)df = datasets.load_breast_cancer(
)x = df.data
y = df.target
x.shape # 檢視屬性維度
x # 檢視屬性標籤
y # 檢視類別標籤
# 劃分訓練集和測試集
from sklearn.linear_model import logisticregression # 匯入邏輯回歸模型
from sklearn.preprocessing import standardscaler # 歸一化
from sklearn.preprocessing import polynomialfeatures # 生成多項式
from sklearn.pipeline import pipeline # pipeline管道
# 直接用邏輯回歸模型進行訓練
logr = logisticregression(
)logr.fit(x_train, y_train)
# 訓練
logr.score(x_test, y_test)
# 測試
from sklearn.model_selection import gridsearchcv # 網格搜尋
import numpy as np
# 使用網格搜尋和pipeline管道進行引數調優
對於模型的調優,由於時間關係,大家可以根據邏輯回歸模型和polynomialfeatures的引數進行調優。
ROC PR案例 乳腺癌資料集
import warnings warnings.filterwarnings ignore import matplotlib.pyplot as plt plt.rcparams font.sans serif simhei 顯示中文 plt.rcparams axes.unicode minu...
sklearn之Knn實戰乳腺癌資料案例
from sklearn.datasets import load breast cancer from sklearn.neighbors import kneighborsclassifier from sklearn.model selection import train test spli...
邏輯回歸 breast cancer 資料集處理
coding utf 8 import pandas as pd import numpy as np from matplotlib import pyplot as plt from sklearn.model selection import train test split definit ...