def model5(): from numpy import vstack from defs_neuro import prepare_data n_lag = 1 n_seq = 1 n_test = 7 n_epochs = 200 n_batch = 1 n_neurons = 4 scaler, train, test = prepare_data(series, n_test, n_lag, n_seq) scaler_1, train_1, test_1 = prepare_data(series, n_test, n_lag, n_seq) scaler_2, train_2, test_2 = prepare_data(values, n_test, n_lag, n_seq) train = vstack((train_1[:, 0], train_2[:, 0], train_1[:, 1])) train = train.T model = fit_lstm(train, n_lag + 1, n_seq, n_batch, n_epochs, n_neurons) model.reset_states() test = vstack((test_1[:, 0], test_2[:, 0], test_1[:, 1])) test = test.T forecasts = make_forecasts(model, n_batch, test, n_lag + 1, n_seq) forecasts = inverse_transform(series, forecasts, scaler, n_test) actual = [row[n_lag + 1:] for row in test] actual = inverse_transform(series, actual, scaler, n_test) evaluate_forecasts(actual, forecasts, n_lag, n_seq) plot_forecasts(series[(row_count - 12):(row_count)], forecasts, n_test)
def model4(): from defs_neuro import fit_lstm_CNN, make_forecasts_CNN n_lag = 1 n_test = 7 n_epochs = 200 n_batch = 1 n_neurons = 4 n_seq = 1 n_steps = 1 scaler, train, test = prepare_data(series, n_test, n_lag, n_seq) model = fit_lstm_CNN(train, n_lag, n_seq, n_steps, n_batch, n_epochs, n_neurons) model.reset_states() forecasts = make_forecasts_CNN(model, n_batch, test, n_lag, n_seq) forecasts = inverse_transform(series, forecasts, scaler, n_test) actual = [row[n_lag:] for row in test] actual = inverse_transform(series, actual, scaler, n_test) evaluate_forecasts(actual, forecasts, n_lag, n_seq) plot_forecasts(series[(row_count - 12):(row_count)], forecasts, n_test)
def model3(): # 3 модель прогнозирования "В лоб"(слой с обратным распространением) from defs_neuro import fit_lstm_bidir n_lag = 1 n_seq = 1 n_test = 7 n_epochs = 200 n_batch = 1 n_neurons = 3 scaler, train, test = prepare_data(series, n_test, n_lag, n_seq) model = fit_lstm_bidir(train, n_lag, n_seq, n_batch, n_epochs, n_neurons) model.reset_states() forecasts = make_forecasts(model, n_batch, test, n_lag, n_seq) forecasts = inverse_transform(series, forecasts, scaler, n_test - 1) actual = [row[n_lag:] for row in test] actual = inverse_transform(series, actual, scaler, n_test - 1) evaluate_forecasts(actual, forecasts, n_lag, n_seq) plot_forecasts(series[(row_count - 12):(row_count)], forecasts, n_test - 1)
def model2(): from defs_neuro import fit_lstm_stack n_lag = 1 n_seq = 1 n_test = 7 n_epochs = 200 n_batch = 1 n_neurons = 4 scaler, train, test = prepare_data(series, n_test, n_lag, n_seq) model = fit_lstm_stack(train, n_lag, n_seq, n_batch, n_epochs, n_neurons) model.reset_states() forecasts = make_forecasts(model, n_batch, test, n_lag, n_seq) forecasts = inverse_transform(series, forecasts, scaler, n_test) actual = [row[n_lag:] for row in test] actual = inverse_transform(series, actual, scaler, n_test) evaluate_forecasts(actual, forecasts, n_lag, n_seq) name = 'Модель 2' plot_forecasts(series[rc2:rc], forecasts, n_test, name)