当前位置:   article > 正文

逻辑斯特回归---良性/恶性肿瘤的分类_sas编程判断肿瘤良性与恶性的关系

sas编程判断肿瘤良性与恶性的关系

逻辑斯特回归---良性/恶性肿瘤的分类

  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import pandas as pd
  4. import numpy as np
  5. from sklearn.model_selection import train_test_split
  6. from sklearn.preprocessing import StandardScaler
  7. from sklearn.linear_model import LogisticRegression
  8. from sklearn.metrics import classification_report
  9. def mylogistic():
  10. column = ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape',
  11. 'Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin', 'Normal Nucleoli',
  12. 'Mitoses', 'Class']
  13. data=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",names=column)
  14. # print(data.info())
  15. data=data.replace(to_replace="?",value=np.nan)
  16. print(data.shape)
  17. data=data.dropna()
  18. print(data.shape)
  19. 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)
  20. ss=StandardScaler()
  21. # 对目标值不进行分类
  22. x_train=ss.fit_transform(x_train)
  23. x_test=ss.transform(x_test)
  24. lr=LogisticRegression()
  25. lr.fit(x_train,y_train)
  26. y_predict=lr.predict(x_test)
  27. print("准确率:",lr.score(x_test,y_test))
  28. print("召回率:",classification_report(y_test,y_predict,labels=[2,4],target_names=["良性","恶性"]))
  29. pass
  30. if __name__ == '__main__':
  31. print("hello")
  32. mylogistic()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/477522
推荐阅读
相关标签
  

闽ICP备14008679号