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')