您的位置:首页 > 编程语言 > Python开发

python基础语法——2 综合基础案例之乳腺癌肿瘤预测代码

2019-07-26 09:51 344 查看
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')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: