日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

逻辑回归案例

發布時間:2023/12/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 逻辑回归案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注:本案例為黑馬的課堂案例,上傳僅為方便查看

邏輯回歸案例

import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression # 1.獲取數據 names = ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape','Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin','Normal Nucleoli', 'Mitoses', 'Class'] data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data',names=names) data.head() Sample code numberClump ThicknessUniformity of Cell SizeUniformity of Cell ShapeMarginal AdhesionSingle Epithelial Cell SizeBare NucleiBland ChromatinNormal NucleoliMitosesClass01234
10000255111213112
100294554457103212
10154253111223112
10162776881343712
10170234113213112
# 2.基本數據處理 # 2.1 缺失值處理 data = data.replace(to_replace='?',value=np.nan) data = data.dropna() data.describe() Sample code numberClump ThicknessUniformity of Cell SizeUniformity of Cell ShapeMarginal AdhesionSingle Epithelial Cell SizeBland ChromatinNormal NucleoliMitosesClasscountmeanstdmin25%50%75%max
6.830000e+02683.000000683.000000683.000000683.000000683.000000683.000000683.000000683.000000683.000000
1.076720e+064.4421673.1508053.2152272.8301613.2342613.4450952.8696931.6032212.699854
6.206440e+052.8207613.0651452.9885812.8645622.2230852.4496973.0526661.7326740.954592
6.337500e+041.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000002.000000
8.776170e+052.0000001.0000001.0000001.0000002.0000002.0000001.0000001.0000002.000000
1.171795e+064.0000001.0000001.0000001.0000002.0000003.0000001.0000001.0000002.000000
1.238705e+066.0000005.0000005.0000004.0000004.0000005.0000004.0000001.0000004.000000
1.345435e+0710.00000010.00000010.00000010.00000010.00000010.00000010.00000010.0000004.000000
data.head() Sample code numberClump ThicknessUniformity of Cell SizeUniformity of Cell ShapeMarginal AdhesionSingle Epithelial Cell SizeBare NucleiBland ChromatinNormal NucleoliMitosesClass01234
10000255111213112
100294554457103212
10154253111223112
10162776881343712
10170234113213112
# 2.2 確定特征值,目標值 x = data.iloc[:,1:-1] x.head() Clump ThicknessUniformity of Cell SizeUniformity of Cell ShapeMarginal AdhesionSingle Epithelial Cell SizeBare NucleiBland ChromatinNormal NucleoliMitoses01234
511121311
5445710321
311122311
688134371
411321311
y = data['Class'] y.head() 0 2 1 2 2 2 3 2 4 2 Name: Class, dtype: int64 # 2.3 分割數據 x_train,x_test,y_train,y_test = train_test_split(x,y,random_state=2,test_size=0.2) # 3.特征工程(標準化) transfer = StandardScaler() x_train = transfer.fit_transform(x_train) x_test = transfer.fit_transform(x_test) # 4.機器學習(邏輯回歸) estimator = LogisticRegression() estimator.fit(x_train,y_train) LogisticRegression() # 5.模型評估 y_pre = estimator.predict(x_test) print('預測值是:\n',y_pre)score = estimator.score(x_test,y_test) print('準確率是:\n',score) 預測值是:[4 4 2 4 2 2 2 2 2 4 2 2 4 2 2 2 4 2 2 2 2 2 4 4 4 2 2 4 2 4 4 4 4 2 4 2 42 2 4 2 2 4 2 2 4 2 2 4 2 2 2 4 2 2 2 2 2 4 4 2 2 2 2 2 2 2 4 4 4 2 2 2 22 2 2 2 4 4 4 4 4 2 4 4 4 2 4 2 2 4 4 4 2 4 2 4 2 2 4 2 2 2 2 4 4 2 2 2 22 4 4 2 2 4 2 2 2 2 2 2 4 2 2 4 4 4 4 2 4 2 4 2 2 2] 準確率是:0.9343065693430657

總結

以上是生活随笔為你收集整理的逻辑回归案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。