运行
sgd = SGDRegressor()
sgd.fit(x_train, y_train)
print("r2 score of Linear regression is",r2_score(y_test,sgd.predict(x_test)))
时出现
DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True)
的报错
解决方法——
将代码改成
y_train = np.ravel(y_train)
# 创建并拟合模型
sgd = SGDRegressor()
sgd.fit(x_train, y_train)
# 评估模型
print("r2 score of Linear regression is",r2_score(y_test,sgd.predict(x_test)))
结果
解决
y_train = np.ravel(y_train)标签:r2,房价,train,score,报错,test,波士顿,sgd From: https://www.cnblogs.com/yansans/p/18182413
# 创建并拟合模型
sgd = SGDRegressor()
sgd.fit(x_train, y_train)
# 评估模型
print("r2 score of Linear regression is",r2_score(y_test,sgd.predict(x_test)))