【问题标题】:Logistic Regression get Value error could not convert string to float: '?'逻辑回归获取值错误无法将字符串转换为浮点数:“?”
【发布时间】:2018-11-19 16:28:12
【问题描述】:

我对这些东西很陌生。这是我正在上的一门课程; 我需要拟合逻辑回归分类器

我进入

from sklearn.linear_model import LogisticRegression
C=1.0
classifier = LogisticRegression(C=C, penalty='l1')

classifier.fit(x, y)

并得到一个值错误

ValueError                                Traceback (most recent call last) <ipython-input-33-9d4de811daf9> in <module>()
----> 1 classifier.fit(x, y)

~\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py in fit(self,  X, y, sample_weight)    1214     1215         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype,
-> 1216                          order="C")    1217         check_classification_targets(y)    1218         self.classes_ = np.unique(y)

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y,  accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd,  multi_output, ensure_min_samples, ensure_min_features, y_numeric,  warn_on_dtype, estimator)
    571     X = check_array(X, accept_sparse, dtype, order, copy,  force_all_finite,
    572                     ensure_2d, allow_nd, ensure_min_samples,
--> 573                     ensure_min_features, warn_on_dtype, estimator)
    574     if multi_output:
    575         y = check_array(y, 'csr', force_all_finite=True,  ensure_2d=False,

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in  check_array(array, accept_sparse, dtype, order, copy, force_all_finite,  ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype,  estimator)
    431                                       force_all_finite)
    432     else:
--> 433         array = np.array(array, dtype=dtype, order=order, copy=copy)
    434 
    435         if ensure_2d:

ValueError: could not convert string to float: '?'

请帮忙

【问题讨论】:

标签: python numpy scikit-learn regression


【解决方案1】:

训练输入 x 和输出 y 必须是 np.float64 类型。 如果要使用字符串,则需要在拟合之前对其进行编码。

查看这篇文章:

Link

【讨论】:

    猜你喜欢
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 2020-10-16
    • 2019-08-31
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    相关资源
    最近更新 更多