python机器学习及实战代码13-16,程序运行时出现提醒及修改
2017-09-10 10:38
555 查看
import pandas as pd import numpy as np column_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) data = data.replace(to_replace='?', value=np.nan) data = data.dropna(how='any') print(data.shape) from sklearn.model_selection import train_test_split x_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 StandardScaler from sklearn.linear_model import LogisticRegression from sklearn.linear_model import SGDClassifier 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_report print('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.意思大概是说在0.19中,SGDClassifier随机梯度下降分类器在sklearn.linear_model.stochastic_gradient.SGDClassifier模块中,而不是直接在模块sklearn.linear_model中,只需找到相应的模块导入代码from sklearn.linear_model import SGDClassifier将其修改为from sklearn.linear_model import stochastic_gradient,并且程序中相应的代码也要做修改,将sgdc= SGDClassifier()改为sgdc = stochastic_gradient.SGDClassifier()运行结果如下:2 3444 168Name: Class, dtype: int642 1004 71Name: Class, dtype: int64Accuracy of LR Classifier: 0.988304093567precision recall f1-score supportBenign 0.99 0.99 0.99 100Malignant 0.99 0.99 0.99 71avg / total 0.99 0.99 0.99 171Accuracy of SGD Classifier: 0.970760233918precision recall f1-score supportBenign 0.97 0.98 0.98 100Malignant 0.97 0.96 0.96 71avg / total 0.97 0.97 0.97 171
相关文章推荐
- 针对python机器学习与实战代码在python3上运行出现的错误分析和warning的修改代码34—38
- python机器学习与实战中运行代码出现警告的处理
- TensorFlow学习笔记7——Win7下Spyder运行python代码出现UnicodeEncodeError问题的解决
- java代码修改了之后运行仍然是原程序
- Python中3+版本运行2+版本程序出现TypeError: a bytes-like object is required, not 'str'之读取PDF中的图片
- ubuntu下运行Python程序出现ImportError: No module named skimage
- 使用Gevent程序正常运行出现这个异常KeyError(155880780,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored解决办法
- python机器学习-预测分析核心算法3-2代码在python3下运行遇到的一些问题
- 解决WIN7下Sublime运行python代码出现的UnicodeEncodeError错误
- 修改桌面堆栈大小,解决运行大量程序时出现”Out of Memory”(内存不足)错误信息的问题
- python机器学习4—2代码详解及修改
- python 程序运行时出现DLL load error
- 机器学习实战--第三版代码修改
- VS2010调试“正试图在 OS 加载程序锁内执行托管代码”和运行出现R6034问题解决
- python机器学习4-4代码及运行结果
- 【小白自学笔记】【机器学习实战】【Python代码逐行理解】CH02
- 机器学习中代码出现tensorflow.python.framework.errors_impl.InternalError,from device: CUDA_ERROR_OUT_OF_MEMORY
- python实战教程1 定时提醒程序的制作(2)
- python运行时修改代码的方法——monkey patch
- 机器学习-决策树,部分代码已修改简化,部分已修改为python3.5