• chapter02“良/恶性乳腺癌肿瘤预测”的问题


    最近比较闲,是时候把自己以前看的资料整理一下了。

    LogisticRegression:由于在训练过程中考虑了所有的样本对参数的影响,因此不一定获得最佳的分类器,对比下一篇 svm只用支持向量来帮助决策最优线性分类模型。
    
    
    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    from sklearn.linear_model import LogisticRegression



    df_train = pd.read_csv('./Breast-Cancer/breast-cancer-train.csv')
    df_test = pd.read_csv('./Breast-Cancer/breast-cancer-test.csv')

    lr = LogisticRegression()
    lr.fit(df_train[['Clump Thickness', 'Cell Size']], df_train['Type'])
    print 'Testing accuracy (all training samples):', lr.score(df_test[['Clump Thickness', 'Cell Size']], df_test['Type'])

    #使用训练样本学习直线的系数和截距
    intercept = lr.intercept_
    coef = lr.coef_[0, :]
    lx = np.arange(0, 12)
    #a*x + b*y = 0
    ly = (-intercept - lx * coef[0]) / coef[1]
    plt.plot(lx, ly, c='yellow')


    df_test_negative = df_test.loc[df_test['Type'] == 0][['Clump Thickness', 'Cell Size']]
    df_test_positive = df_test.loc[df_test['Type'] == 1][['Clump Thickness', 'Cell Size']]
    plt.scatter(df_test_negative['Clump Thickness'], df_test_negative['Cell Size'], marker='o', s=200, c='red')
    plt.scatter(df_test_positive['Clump Thickness'], df_test_positive['Cell Size'], marker='x', s=150, c='black')

    plt.xlabel('Clump Thickness')
    plt.ylabel('Cell Size')

    plt.show()

    结果如下图:

  • 相关阅读:
    agc015D A or...or B Problem
    agc016E Poor Turkeys
    CTSC2016时空旅行
    假期的宿舍[ZJOI2009]
    上白泽慧音(luogu P1726
    小K的农场(luogu P1993
    Cashier Employment(poj1275
    Intervals(poj1201
    序列分割[Apio2014]
    特别行动队[APIO2010]
  • 原文地址:https://www.cnblogs.com/TMatrix52/p/7652485.html
Copyright © 2020-2023  润新知