import pandas # 训练集 train = pandas.read_csv("c://train.csv") # 测试集 test = pandas.read_csv("c://test.csv") # 选取‘Clump Thickness’与‘Cell Size'作为特征,构建测试集中的正负分类样本 test_negative = test.loc[test['Type'] == 0][['Clump Thickness', 'Cell Size']] test_positive = test.loc[test['Type'] == 1][['Clump Thickness', 'Cell Size']] import matplotlib.pyplot as plt # 绘制良性肿瘤样本点,标记为红色 plt.scatter(test_negative['Clump Thickness'], test_negative['Cell Size'], marker='o', s=200, c='red') # 绘制恶性肿瘤样本点,标记为黑色 plt.scatter(test_positive['Clump Thickness'], test_positive['Cell Size'], marker='x', s=150, c='black') # 绘制x,y轴 plt.xlabel('Clump Thickness') plt.ylabel('Cell Size') import numpy as np # 利用numpy中random函数随机采样直线的截距和系数 intercept = np.random.random([1]) coef = np.random.random([2]) lx = np.arange(0, 12) ly = (-intercept-lx*coef[0])/coef[1] # 绘制一条随机直线 plt.plot(lx, ly, c='yellow')
python基础语法——2 综合基础案例之乳腺癌肿瘤预测代码
最新推荐文章于 2024-07-12 08:45:00 发布