我想在基于 sklearn 庫的 Titanic ML 解決方案中實(shí)現(xiàn)梯度提升分類器。我在 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貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
我認(rèn)為您的火車數(shù)據(jù)中可能存在非數(shù)值。您的分類器可以接受數(shù)字輸入。這就是它嘗試將字符串轉(zhuǎn)換'Baby'
為浮點(diǎn)數(shù)的原因。由于不支持此操作,因此失敗。
也許再看看你的數(shù)據(jù)。
- 1 回答
- 0 關(guān)注
- 429 瀏覽
添加回答
舉報(bào)
0/150
提交
取消