网上代码:https://data-flair.training/blogs/stock-price-prediction-machine-learning-project-in-python/中:
- scaler=MinMaxScaler(feature_range=(0,1))
- final_dataset=new_dataset.values
- train_data=final_dataset[0:987,:]
- valid_data=final_dataset[987:,:]
- new_dataset.index=new_dataset.Date
- new_dataset.drop("Date",axis=1,inplace=True)
- scaler=MinMaxScaler(feature_range=(0,1))
- scaled_data=scaler.fit_transform(final_dataset)
- x_train_data,y_train_data=[],[]
- for i in range(60,len(train_data)):
- x_train_data.append(scaled_data[i-60:i,0])
- y_train_data.append(scaled_data[i,0])
- x_train_data,y_train_data=np.array(x_train_data),np.array(y_train_data)
- x_train_data=np.reshape(x_train_data,(x_train_data.shape[0],x_train_data.shape[1],1))
红线所在行改为:scaled_data=scaler.fit_transform(new_dataset)
原因:蓝行代码final_dataset=new_dataset.values中将final_dataset赋值为时间戳格式,导致报错