(一)监督学习模型之线性分类器
来源:互联网 发布:淘宝直通车的排名规则 编辑:程序博客网 时间:2024/05/16 07:01
一、解决问题
使用线性分类模型从事良/恶性肿瘤的预测任务
二、数据地址
http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data
三、代码实现
1、获得数据
import pandas as pdimport numpy as npcolumn_names = ['Sample code number', 'Clump Thickness', 'Uniformity of Call Size' 'Uniformity of Cell Shape', 'Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin', 'Normal Nucleoli', 'Mitoses', 'class']data = pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data', names = column_names)data.shape# drop nan# 去掉缺失值data = data.replace(to_replace='?', value=np.nan)data = data.dropna(how = 'any')data.shape
2、准备数据
from sklearn.cross_validation import train_test_splitX_train, X_test, y_train, y_test = train_test_split(data[column_names[1:9]], data[column_names[9]], test_size = 0.25, random_state = 33)y_train.value_counts()y_test.value_counts()
3、标准化数据
# 标准化数据,保证每个维度的特征数据方差为1,均值为0,# 让预测的结果不会被每个过大的特征值主导ss = StandardScaler()X_train = ss.fit_transform(X_train)X_test = ss.transform(X_test)
4、建立模型预测数据
lr = LogisticRegression()sgdc = SGDClassifier()lr.fit(X_train, y_train)lr_y_predict = lr.predict(X_test)sgdc.fit(X_train, y_train)sgdc_y_predict = sgdc.predict(X_test)
5、性能分析
from sklearn.metrics import classification_reportprint(lr.score(X_test, y_test))print(classification_report(y_test, lr_y_predict, target_names = ['Benign', 'Malignant']))print(classification_report(y_test, sgdc_y_predict, target_names = ['Benign', 'Malignant']))
**
四、代码地址
——
**
阅读全文
0 0
- (一)监督学习模型之线性分类器
- 监督学习之广义线性模型
- 监督学习初步---线性分类器
- 监督式学习 -- 分类决策树(一)
- 监督学习之广义线性模型——Andrew Ng机器学习笔记(三)
- 监督学习之线性回归(续)
- 监督学习之线性回归
- 监督学习之线性回归
- 【机器学习】python实践笔记 -- 经典监督学习模型之分类学习模型
- 机器学习模型的基本分类--有监督、无监督
- 线性分类器之感知器模型(Perceptron)
- 监督学习——线性回归(一)
- Python机器学习库SKLearn:监督学习之广义线性模型
- 机器学习之监督学习-分类
- Spark.MLlib之线性分类模型学习笔记
- 机器学习——线性模型之回归与分类
- MachineLearning-监督学习之线性回归
- 深度学习笔记(一)线性分类器(基础知识)
- 画弧
- Codeforces 852B Neural Network country
- Mutations|FreeCodeCamp
- 二位数组中的查找
- 关于微信小程序循环以及嵌套循环的总结
- (一)监督学习模型之线性分类器
- Codeforces 852 B Neural Network country [DP+乘法快速幂优化]
- php strpos注意的地方
- Spring Cloud中Hystrix的服务降级与异常处理
- MyCommandLineRunner 系统启动后运行的类
- JZOJ5377. 【NOIP2017提高A组模拟9.19】开拓 DP
- C#学习笔记_4.C#类型转换
- 头文件互相引用
- JAVA集合类汇总