为什么在使用python在LSTM中训练模型之前执行scaler.fit转换时错误显示“'列表'对象没有属性'值'”

这里我有一个包含四个输入的数据集。因此,在这里我想使用LSTM模型预测一个输出。因此对于y值,我每隔一小时使用附加值创建一个值。

 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

此后,我对Y值进行了scaler.fit转换。然后它给了我这个错误。

这是我的代码:

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,y)
    306         # Reset internal state before fitting
    307         self._reset()
--> 308         return self.partial_fit(X,y)
    309 
    310     def partial_fit(self,y=None):

~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in partial_fit(self,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,

有人可以帮我解决这个问题吗?

ssq1987312 回答:为什么在使用python在LSTM中训练模型之前执行scaler.fit转换时错误显示“'列表'对象没有属性'值'”

我找到了答案。谢谢您的答复。

我的代码是:

y = [int(x) for x in y]
本文链接:https://www.f2er.com/3146494.html

大家都在问