我想实现梯度提升分类器到我的泰坦尼克号ML解决方案基于sklearn库。
我在Ubuntu 18.04上使用VS Code。
我试过了:
# Splitting the Training Data
from sklearn.model_selection import train_test_split
predictors = train.drop(['Survived', 'PassengerId'], axis=1)
target = train["Survived"]
x_train, x_val, y_train, y_val = train_test_split(predictors,
target, test_size = 0.22, random_state = 0)
# Gradient Boosting Classifier
from sklearn.ensemble import GradientBoostingClassifier
gbk = GradientBoostingClassifier()
gbk.fit(x_train, y_train)..which返回:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sj/anaconda3/lib/python3.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 1395, in fit
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], dtype=DTYPE)
File "/home/sj/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py", line 756, in check_X_y
estimator=estimator)
File "/home/sj/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py", line 527, in check_array
array = np.asarray(array, dtype=dtype, order=order)
File "/home/sj/anaconda3/lib/python3.7/site-packages/numpy/core/numeric.py", line 501, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: 'Baby'如果能帮上忙,我们将不胜感激。我是DS的新手。
发布于 2019-02-15 20:46:20
我认为你可以在你的训练数据中使用非数字值。你的分类器可以接受数字输入。这就是为什么它试图将一个字符串,这里是'Baby',转换成一个浮点数。由于不支持此操作,因此操作失败。
也许再看看你的数据。
https://stackoverflow.com/questions/54709600
复制相似问题