为什么执行时显示“'list'对象没有属性'values'”时出错定标器.fit使用python在LSTM中训练模型之前进行转换

2024-04-29 16:02:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这里有一个包含四个输入的数据集。所以这里我想用LSTM模型预测一个输出。所以对于y值,我每一小时使用append value创建一个值。你知道吗

 X = 1
 n_out = 1

 x,y=list(),list()
 start =0


for _ in range(len(df)):
in_end = start+X
out_end= in_end + n_out
if out_end < len(df):
    x_input = df[start:in_end]
    x.append(x_input)
    y.append(df[in_end:out_end,0])
start +=1

在这里,附加值y的值显示如下。你知道吗

2018-06-08 06:15:00          141.0
2018-06-08 07:15:00          0
2018-06-08 08:15:00          0
2018-06-08 09:15:00          0
2018-06-08 10:15:00          0
2018-06-08 11:15:00          0
2018-06-08 12:15:00          0
2018-06-08 13:15:00          0
2018-06-08 14:15:00          0
2018-06-08 15:15:00          0
2018-06-08 16:15:00          0
2018-06-08 17:15:00          0
2018-06-08 18:15:00          0
2018-06-08 19:15:00          0
2018-06-08 20:15:00          0
2018-06-08 21:15:00          0
2018-06-08 22:15:00          0

在这之后我做到了定标器.fit转换为Y值。然后它给了我这个错误。你知道吗

这是我的密码:

y = y.values.astype(int)
scaler_y = preprocessing.MinMaxScaler(feature_range =(0, 1))
y = np.array(y).reshape([-1, 1])
y = scaler_y.fit_transform(y)

错误:

第一个错误:

ttributeError Traceback (most recent call last) <ipython-input-240-6ac9211db656> in <module>() ----> 1 y = y.values.astype(int) AttributeError: 'list' object has no attribute 'values'
ValueError                                Traceback (most recent call last)
<ipython-input-184-ad4efba4dd31> in <module>()
      1 scaler_y = preprocessing.MinMaxScaler(feature_range =(0, 1))
      2 y = np.array(y).reshape([-1, 1])
----> 3 y = scaler_y.fit_transform(y)

~\Anaconda3\lib\site-packages\sklearn\base.py in fit_transform(self, X, y, **fit_params)
    515         if y is None:
    516             # fit method of arity 1 (unsupervised transformation)
--> 517             return self.fit(X, **fit_params).transform(X)
    518         else:
    519             # fit method of arity 2 (supervised transformation)

~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in fit(self, X, y)
    306         # Reset internal state before fitting
    307         self._reset()
--> 308         return self.partial_fit(X, y)
    309 
    310     def partial_fit(self, X, y=None):

~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in partial_fit(self, X, y)
    332 
    333         X = check_array(X, copy=self.copy, warn_on_dtype=True,
--> 334                         estimator=self, dtype=FLOAT_DTYPES)
    335 
    336         data_min = np.min(X, axis=0)

~\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: "{'level': [141.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 

有人能帮我解决这个问题吗?你知道吗


Tags: inselfdfinputnptransformoutarray