GradientBoostingClassifier 实现

我想在基于 sklearn 库的 Titanic ML 解决方案中实现梯度提升分类器。


我在 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)

..返回:


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 很陌生。


拉丁的传说
浏览 388回答 1
1回答

PIPIONE

我认为您的火车数据中可能存在非数值。您的分类器可以接受数字输入。这就是它尝试将字符串转换'Baby'为浮点数的原因。由于不支持此操作,因此失败。也许再看看你的数据。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go