ValueError: bad input shape (37533, 3) Gradient Boosting Error in fit() method
ValueError: bad input shape (37533, 3) Gradient Boosting Error in fit() method
我正在使用机器学习分类技术随机森林和梯度提升:
下面是运行良好的随机森林代码:
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, min_samples_leaf=10,
random_state=1)
model.fit(x_train, y_train)
print(model.score)
#Accuracy of prediction
y_pred = model.predict(x_test)
#Mean Standard Error
mean_squared_error(y_pred, y_test)
model.score(x_test, y_test)
Out[423]: 0.80038542832276516
现在第二个分类器Gradient Boosting报错:
from sklearn.ensemble import GradientBoostingClassifier #For Classification
clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
max_depth=1)
clf.fit(x_train, y_train)
这是它给出以下错误的地方:
clf.fit(x_train, y_train)
Traceback (most recent call last):
File "<ipython-input-425-9249b506d83f>", line 1, in <module>
clf.fit(x_train, y_train)
File "C:\Anaconda3\lib\site-packages\sklearn\ensemble\gradient_boosting.py",
line 973, in fit
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], dtype=DTYPE)
File "C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 526,
in check_X_y
y = column_or_1d(y, warn=True)
File "C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 562,
in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (37533, 3)
数据如下:
print(x_train)
No Yes
32912 1.0 0.0
35665 1.0 0.0
32436 1.0 0.0
25885 1.0 0.0
24896 1.0 0.0
51734 1.0 0.0
4235 1.0 0.0
51171 1.0 0.0
33221 0.0 1.0
print(y_train)
Fatal Incident Non-Fatal
32912 0.0 0.0 1.0
35665 0.0 0.0 1.0
32436 0.0 0.0 1.0
你能说出Gradient Boosting fit() 函数的问题是什么,它给出了错误:
ValueError:错误的输入形状 (37533, 3)
尝试不对标签进行二值化...
我正在使用机器学习分类技术随机森林和梯度提升:
下面是运行良好的随机森林代码:
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, min_samples_leaf=10,
random_state=1)
model.fit(x_train, y_train)
print(model.score)
#Accuracy of prediction
y_pred = model.predict(x_test)
#Mean Standard Error
mean_squared_error(y_pred, y_test)
model.score(x_test, y_test)
Out[423]: 0.80038542832276516
现在第二个分类器Gradient Boosting报错:
from sklearn.ensemble import GradientBoostingClassifier #For Classification
clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
max_depth=1)
clf.fit(x_train, y_train)
这是它给出以下错误的地方:
clf.fit(x_train, y_train)
Traceback (most recent call last):
File "<ipython-input-425-9249b506d83f>", line 1, in <module>
clf.fit(x_train, y_train)
File "C:\Anaconda3\lib\site-packages\sklearn\ensemble\gradient_boosting.py",
line 973, in fit
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], dtype=DTYPE)
File "C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 526,
in check_X_y
y = column_or_1d(y, warn=True)
File "C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 562,
in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (37533, 3)
数据如下:
print(x_train)
No Yes
32912 1.0 0.0
35665 1.0 0.0
32436 1.0 0.0
25885 1.0 0.0
24896 1.0 0.0
51734 1.0 0.0
4235 1.0 0.0
51171 1.0 0.0
33221 0.0 1.0
print(y_train)
Fatal Incident Non-Fatal
32912 0.0 0.0 1.0
35665 0.0 0.0 1.0
32436 0.0 0.0 1.0
你能说出Gradient Boosting fit() 函数的问题是什么,它给出了错误: ValueError:错误的输入形状 (37533, 3)
尝试不对标签进行二值化...