plt.plot(future_predictions, label='Future Predictions') plt.title(f'{ticker}Future Stock Price Prediction') plt.xlabel('Time') plt.ylabel('Price (USD)') plt.legend() plt.show()
Densefrom sklearn.preprocessing import MinMaxScaler if __name__=="__main__": # 读取股票价格数据 data = pd.read_csv('stock_data.csv') prices = data['Close'].values # 数据预处理:归一化
# 调用库importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltfromtensorflowimportkerasfromtensorflow.kerasimportlayersfromsklearn.preprocessingimportMinMaxScalerfromkerasimportregularizers### 数据处理部分 ### 读入数据google_stock=pd.read_excel('道琼斯综合.xls',encoding='GBK')google_stock.tail()# 查看部...
plt.plot(original, color = 'red', label = 'Real Stock Price') plt.plot(pred, color = 'blue', label = 'Predicted Stock Price') plt.title('Stock Price Prediction') plt.xlabel('Time') plt.ylabel('Google Stock Price') plt.legend() plt.show() 1. 2. 3. 4. 5. 6. 7. 看样子还...
aapl_stock_data.isnull().sum() # 填充缺失值(如果有) aapl_stock_data.fillna(method='ffill', inplace=True) 在股票市场数据中,各种特征可能都有影响。通常,“开盘价”、“最高价”、“最低价”、“收盘价”和“成交量”被使用。对于我们的模型,我们将使用“收盘价”,但你可以尝试使用其他特征,如“开...
print("保存模型:",saver.save(sess,'stock.model')) step+=1 train_lstm() #预测模型 def prediction(): pred,_=lstm(1) #预测时只输入[1,time_step,input_size]的测试数据 saver=tf.train.Saver(tf.global_variables()) with tf.Session() as sess: ...
'time': stock['time'] } 4.2 预测部分代码 import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, LSTM ...
A stock time series is unfortunately not a function that can be mapped. It can best described more as a random walk, which makes the whole prediction thing considerably harder. But what about the LSTM identifying any underlying hidden trends? Well, let’s take a look. ...
plt.title('Stock Price Prediction') plt.xlabel('Time') plt.ylabel('Google Stock Price') plt.legend() plt.show() 看样子还不错,到目前为止,我们训练了模型并用测试值检查了该模型。现在让我们预测一些未来值。 从主df 数据集中获取我们在开始时加载的最后 30 个值[为什么是 30?因为这是我们想要的过去...
plt.plot(real_stock_price, color='red', label='Real MaoTai Stock Price') plt.plot(predicted_stock_price, color='blue', label='Predicted MaoTai Stock Price') plt.title('MaoTai Stock Price Prediction') plt.xlabel('Time') plt.ylabel('MaoTai Stock Price') plt.legend() plt.show() ### ...