ValueError:使用刻度时使用序列设置数组元素

时间:2018-11-30 08:01:53

标签: python scikit-learn data-science

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-48-9a56f92ca2dd> in <module>()
      1 from sklearn.preprocessing import scale
----> 2 X_transform = scale(X_transform)

/opt/conda/lib/python3.6/site-packages/sklearn/preprocessing/data.py in scale(X, axis, with_mean, with_std, copy)
    143     X = check_array(X, accept_sparse='csc', copy=copy, ensure_2d=False,
    144                     warn_on_dtype=True, estimator='the scale function',
--> 145                     dtype=FLOAT_DTYPES, force_all_finite='allow-nan')
    146     if sparse.issparse(X):
    147         if with_mean:

/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
    525             try:
    526                 warnings.simplefilter('error', ComplexWarning)
--> 527                 array = np.asarray(array, dtype=dtype, order=order)
    528             except ComplexWarning:
    529                 raise ValueError("Complex data not supported\n"

/opt/conda/lib/python3.6/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
    499 
    500     """
--> 501     return array(a, dtype, copy=False, order=order)
    502 
    503 

ValueError: setting an array element with a sequence.

这是我的代码X_transform是大小为16000*300的数组

from sklearn.preprocessing import scale
X_transform = scale(X_transform)

我要去哪里错了?它包含浮点类型的值。

这是我的X_transform enter image description here

1 个答案:

答案 0 :(得分:1)

X_transform不是浮点数的数组。正确地将其转换为数组(2D数组,而不是1D数组的1D数组),然后它将按预期工作。