1
---------------------------------------------------------------------------
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 在此处输入图像描述

4

1 回答 1

1

X_transform不是一个 numpy 浮点数组。将其正确转换为数组(二维数组,而不是一维数组的一维数组),然后它将按预期工作。

于 2018-11-30T09:37:42.627 回答