python机器学习与实战中运行代码出现警告的处理
来源:互联网 发布:c语言函数大全 chm 编辑:程序博客网 时间:2024/06/08 07:09
import pandas as pdimport numpy as npcolumn_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('http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data', names=column_names)#print(data)data = data.replace(to_replace='?', value=np.nan)#print(data)data = data.dropna(how='any')#print(data)data.shapefrom sklearn.model_selection import train_test_splitx_train, x_test, y_train, y_test = train_test_split(data[column_names[1:10]], data[column_names[10]], test_size=0.25, random_state=33)print(y_train.value_counts())print(y_test.value_counts())from sklearn.preprocessing import StandardScalerfrom sklearn.linear_model import LogisticRegressionfrom sklearn.linear_model import SGDClassifierss = StandardScaler()x_train = ss.fit_transform(x_train)x_test = ss.transform(x_test)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)from sklearn.metrics import classification_reportprint('Accuracy of LR Classifier:', lr.score(x_test, y_test))print(classification_report(y_test, lr_y_predict, target_names=['Benign', 'Malignant']))print('Accuracy of SGD Classifier:', sgdc.score(x_test, y_test))print(classification_report(y_test, sgdc_y_predict, target_names=['Benign', 'Malignant']))
运行上面程序会出现一下警告:
Warning (from warnings module): File "D:\Python362\lib\site-packages\sklearn\linear_model\stochastic_gradient.py", line 84 "and default tol will be 1e-3." % type(self), FutureWarning)FutureWarning: max_iter and tol parameters have been added in <class 'sklearn.linear_model.stochastic_gradient.SGDClassifier'> in 0.19. If both are left unset, they default to max_iter=5 and tol=None. If tol is not None, max_iter defaults to max_iter=1000. From 0.21, default max_iter will be 1000, and default tol will be 1e-3.翻看了官方文档是版本升级的问题:
max_iter : int, optional The maximum number of passes over the training data (aka epochs). It only impacts the behavior in the ``fit`` method, and not the `partial_fit`. Defaults to 5. Defaults to 1000 from 0.21, or if tol is not None. .. versionadded:: 0.19
在0.19的版本中,SDGClassifier默认的迭代次数是5,0.21版本默认的迭代次数是1000,要想不出现warnings只需手动设定SDGClassifier的迭代次数,代码如下:
sgdc = SGDClassifier(max_iter=5)运行修改后的代码最终结果如下:
Accuracy of LR Classifier: 0.988304093567 precision recall f1-score support Benign 0.99 0.99 0.99 100 Malignant 0.99 0.99 0.99 71avg / total 0.99 0.99 0.99 171Accuracy of SGD Classifier: 0.982456140351 precision recall f1-score support Benign 0.99 0.98 0.98 100 Malignant 0.97 0.99 0.98 71avg / total 0.98 0.98 0.98 171
阅读全文
0 0
- python机器学习与实战中运行代码出现警告的处理
- 针对python机器学习与实战代码在python3上运行出现的错误分析和warning的修改代码34—38
- python机器学习及实战代码13-16,程序运行时出现提醒及修改
- python与机器学习实战
- Python机器学习实战与kaggle实战
- apriori算法的代码,python实现,参考《机器学习实战》
- 机器学习实战:KNN 代码注释(python)
- 机器学习实战:python算法代码汇总
- 机器学习实战-决策树ID3-python代码
- 机器学习实战-AdaBoost-python代码
- 机器学习实战中遇到的python问题
- strip---机器学习实战与Python
- Python机器学习实践与Kaggle实战
- Python与机器学习之实战(一)
- Python与机器学习之实战(二)
- 机器学习python处理文本数据 代码
- 机器学习实战 Ch8回归 代码运行总结
- 2017新Python机器深度学习自然语言处理视频教程文本挖掘算法实战 Python机器学习算法升级版 机器学习与数据挖掘(视频+课件+源码)
- 内联函数
- 使用@Retryable来进行重处理
- nfs挂载
- 双路快排
- golang中并发sync和channel
- python机器学习与实战中运行代码出现警告的处理
- 【Linux】文本处理、关键字截取
- 数字证书应用综合揭秘(包括证书生成、加密、解密、签名、验签)
- Linux:SSH免密码登录
- ConcurrentLinkedQueue源码分析
- RF+Appium 测试demo:搜索课程
- android L Palette 实现原理
- 分库分表的几种常见玩法及如何解决跨库查询等问题
- thinkphp nginx配置文件