import pandas as pd
import math
import numpy as np
from datetime import datetime
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
import yfinance as yf
amzn = yf.Ticker("AMZN")
end_date = datetime.now().strftime('%Y-%m-%d')
amzn_hist = amzn.history(start='2017-01-01',end=end_date)
amzn_close = amzn_hist['Close']
amzn_values = amzn_close.values
amzn_values = amzn_values.reshape(-1,1)
trainingScaler = MinMaxScaler(feature_range=(0,1))
amzn_values_scaled = trainingScaler.fit_transform(amzn_values)
raining_split = math.floor(len(amzn_values_scaled) * 0.85) #1267+
training_amzn = amzn_values_scaled[0:training_split]
training_ind_amzn = []
training_dep_amzn = []
for i in range(50, len(training_amzn)):
training_ind_amzn.append(training_amzn[i-50:i][0])
training_dep_amzn.append(training_amzn[i][0])
training_ind_amzn, training_dep_amzn = np.array(training_ind_amzn), np.array(training_dep_amzn)
training_ind_amzn = np.reshape(training_ind_amzn, (training_ind_amzn.shape[0], training_ind_amzn.shape[1], 1))
amzn_model = keras.Sequential()
amzn_model.add(layers.LSTM(100, return_sequences=True, input_shape=(training_ind_amzn.shape[1], 1)))
amzn_model.add(layers.Dropout(0.2))
amzn_model.add(layers.LSTM(100, return_sequences=True))
amzn_model.add(layers.Dropout(0.2))
amzn_model.add(layers.LSTM(100))
amzn_model.add(layers.Dropout(0.2))
amzn_model.add(layers.Dense(25))
amzn_model.add(layers.Dense(1))
amzn_model.compile(optimizer='adam',loss='mean_squared_error')
amzn_model.fit(training_ind_amzn, training_dep_amzn, epochs = 60, batch_size = 32)
testing_input_amzn = amzn_values[training_split:]
testing_input_amzn = trainingScaler.fit_transform(testing_input_amzn)
testing_amzn = []
for i in range(50, len(testing_input_amzn) + 50):
testing_amzn.append(testing_input_amzn[i-50:i][0])
testing_amzn = np.array(testing_amzn)
testing_amzn = np.reshape(testing_amzn, (testing_amzn.shape[0], testing_amzn.shape[1], 1))
predict_amzn = amzn_model.predict(testing_amzn)
predict_amzn = trainingScaler.inverse_transform(predict_amzn)
plt.plot(amzn_values[training_split:], color = 'blue', label = 'AMZN Stock Price')
plt.plot(predict_amzn, color = 'red', label = 'Predicted AMZN Stock Price')
plt.title('Amazon (AMZN)')
plt.xlabel('Number of Days since April 26, 2022')
plt.ylabel('AMZN Stock Price')
plt.legend()
plt.show()
Возьми за основу посмотри, что на что влияет и подстрой под свои данные. я разбил высоты на диапазоны, так как не очень представляю как иначе получить случайную переменную.ОТВЕТ MLE. либо работай с дискретной переменной либо с нормальной, но не смешевай одно с другим это полная глупость.
mu = 2
std = 1
from scipy.stats import norm
X = norm(mu,std)
result = X.rvs(5)
print(result)
Это вообще что такое?