赞
踩
逻辑斯特回归---良性/恶性肿瘤的分类
- #!/usr/bin/python
- # -*- coding:utf-8 -*-
- 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
- from sklearn.metrics import classification_report
- def mylogistic():
- column = ['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=column)
- # print(data.info())
- data=data.replace(to_replace="?",value=np.nan)
- print(data.shape)
- data=data.dropna()
- print(data.shape)
- x_train,x_test,y_train,y_test=train_test_split(data[column[1:10]],data[column[10]],test_size=0.25,random_state=30)
-
- ss=StandardScaler()
-
- # 对目标值不进行分类
- x_train=ss.fit_transform(x_train)
- x_test=ss.transform(x_test)
-
- lr=LogisticRegression()
- lr.fit(x_train,y_train)
-
- y_predict=lr.predict(x_test)
-
- print("准确率:",lr.score(x_test,y_test))
- print("召回率:",classification_report(y_test,y_predict,labels=[2,4],target_names=["良性","恶性"]))
-
- pass
-
- if __name__ == '__main__':
- print("hello")
- mylogistic()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。