zoukankan      html  css  js  c++  java
  • 癌症分类预测

    1 背景介绍

    • 数据介绍

    原始数据的下载地址:https://archive.ics.uci.edu/ml/machine-learning-databases/

    数据描述

    (1)699条样本,共11列数据,第一列用语检索的id,后9列分别是与肿瘤

    相关的医学特征,最后一列表示肿瘤类型的数值。

    (2)包含16个缺失值,用”?”标出。

    2 案例分析

    1.获取数据
    2.基本数据处理
    2.1 缺失值处理
    2.2 确定特征值,目标值
    2.3 分割数据
    3.特征工程(标准化)
    4.机器学习(逻辑回归)
    5.模型评估
    

    3 代码实现

    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
    
    import ssl
    ssl._create_default_https_context = ssl._create_unverified_context
    
    # 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()
    
    # 2.基本数据处理
    # 2.1 缺失值处理
    data = data.replace(to_replace="?", value=np.NaN)
    data = data.dropna()
    # 2.2 确定特征值,目标值
    x = data.iloc[:, 1:10]
    x.head()
    y = data["Class"]
    y.head()
    # 2.3 分割数据
    x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=22)
    
    # 3.特征工程(标准化)
    transfer = StandardScaler()
    x_train = transfer.fit_transform(x_train)
    x_test = transfer.transform(x_test)
    
    # 4.机器学习(逻辑回归)
    estimator = LogisticRegression()
    estimator.fit(x_train, y_train)
    
    # 5.模型评估
    y_predict = estimator.predict(x_test)
    y_predict
    estimator.score(x_test, y_test)
    

    在很多分类场景当中我们不一定只关注预测的准确率!!!!!

    比如以这个癌症举例子!!!我们并不关注预测的准确率,而是关注在所有的样本当中,癌症患者有没有被全部预测(检测)出来。

  • 相关阅读:
    《数据挖掘导论》研读(1)
    《机器学习理论、方法及应用》研读(2)
    《机器学习理论、方法及应用》研读(1)
    Python3爬虫(3)_urllib.error
    Python3爬虫(2)_利用urllib.urlopen发送数据获得反馈信息
    debian 安装svn197
    Debian卸载软件197
    chmod 详解197
    debian 创建快捷方式197
    vim高亮配置197
  • 原文地址:https://www.cnblogs.com/deepend/p/14464560.html
Copyright © 2011-2022 走看看