python机器学习及实践 书中的错误(持续更新)

1. 美国波士顿房价预测标准化处理报错: Reshape your data either using array.reshape(-1, 1) 

from sklearn.preprocessing import StandardScaler
ss_X = StandardScaler()
ss_y = StandardScaler()
X_train = ss_X.fit_transform(X_train)
X_test = ss_X.transform(X_test)
y_train = ss_y.fit_transform(y_train.reshape(-1,1))
y_test = ss_y.transform(y_test.reshape(-1,1))

如上图所示, 在y_train和y_test后面加上reshape(-1,1)就好.

 

2. 数据分割报错

from sklearn.cross_validation import train_test_split

改成

from sklearn.model_selection import train_test_split

 

3. ValueError: cannot reshape array of size 1 into shape (14,2) (书P86) 

X = np.array(list(zip(x1,x2))).reshape(len(x1), 2)

参考:https://blog.csdn.net/m0_37586991/article/details/80195248

 

4. 108页

print ('Optimal number of features %d' %percentiles[opt])
改成
print ('Optimal number of features %d' %np.array(percentiles)[opt])

5. 124页

from sklearn.grid_search import GridSearchCV

改成 

from sklearn.model_selection import GridSearchCV

6. 132页,显示如下错误

打开Anaconda的 Spyder,在右下角的Ipython里输入

>>> import nltk
>>> nltk.download('punkt')
  
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值