我想在基于 sklearn 库的 Titanic ML 解决方案中实现梯度提升分类器。我在 Ubuntu 18.04 上使用 VS Code。我试过了:# Splitting the Training Datafrom sklearn.model_selection import train_test_splitpredictors = 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 Classifierfrom sklearn.ensemble import GradientBoostingClassifiergbk = GradientBoostingClassifier()gbk.fit(x_train, y_train)..返回: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 很陌生。
1 回答
PIPIONE
TA贡献1829条经验 获得超9个赞
我认为您的火车数据中可能存在非数值。您的分类器可以接受数字输入。这就是它尝试将字符串转换'Baby'
为浮点数的原因。由于不支持此操作,因此失败。
也许再看看你的数据。
- 1 回答
- 0 关注
- 387 浏览
添加回答
举报
0/150
提交
取消