python机器学习及实战代码13-16,程序运行时出现提醒及修改

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    344
4    168
Name: Class, dtype: int64
2    100
4     71
Name: Class, dtype: int64
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        71

avg / total       0.99      0.99      0.99       171

Accuracy of SGD Classifier: 0.970760233918
             precision    recall  f1-score   support

     Benign       0.97      0.98      0.98       100
  Malignant       0.97      0.96      0.96        71

avg / total       0.97      0.97      0.97       171



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值