<jupyter_start><jupyter_text>1s<jupyter_code>new_model = learn(22, 1000, 50)
new_model = learn(22, 1000, 100)
new_model = learn(22, 1000, 150)
new_model = learn(22, 1000, 200)
new_model = learn(22, 1000, 250)
new_model = learn(22, 1000, 300)
new_model = learn(22, 1000, 350)
new_model = learn(22, 1000, 400)
new_model = learn(22, 1000, 450)
new_model = learn(22, 1000, 500)
new_model = learn(22, 1000, 550)
new_model = learn(22, 1000, 600)
new_model = learn(22, 1000, 650)
new_model = learn(22, 1000, 700)<jupyter_output>Data is ready
100 100 finished
100 150 finished
100 200 finished
100 250 finished
150 100 finished
150 150 finished
150 200 finished
150 250 finished
200 100 finished
200 150 finished
200 200 finished
200 250 finished
250 100 finished
250 150 finished
250 200 finished
250 250 finished
best model hidden size: 150 250
0.5034815462200272
416.69663762651516<jupyter_text>1.5s<jupyter_code>new_model = learn(141, 1500, 50)
new_model = learn(141, 1500, 100)
new_model = learn(141, 1500, 150)
new_model = learn(141, 1500, 200)
new_model = learn(141, 1500, 250)
new_model = learn(141, 1500, 300)
new_model = learn(141, 1500, 350)
new_model = learn(141, 1500, 400)
new_model = learn(141, 1500, 450)
new_model = learn(141, 1500, 500)
new_model = learn(141, 1500, 550)
new_model = learn(141, 1500, 600)
new_model = learn(141, 1500, 650)
new_model = learn(141, 1500, 700)<jupyter_output>Data is ready
100 100 finished
100 150 finished
100 200 finished
100 250 finished
150 100 finished
150 150 finished
150 200 finished
150 250 finished
200 100 finished
200 150 finished
200 200 finished
200 250 finished
250 100 finished
250 150 finished
250 200 finished
250 250 finished
best model hidden size: 250 250
0.054362225233888076
369.20772052900645<jupyter_text>2s<jupyter_code>new_model = learn(902, 2000, 50)
new_model = learn(902, 2000, 100)
new_model = learn(902, 2000, 150)
new_model = learn(902, 2000, 200)
new_model = learn(902, 2000, 250)
new_model = learn(902, 2000, 300)
new_model = learn(902, 2000, 350)
new_model = learn(902, 2000, 400)
new_model = learn(902, 2000, 450)
new_model = learn(902, 2000, 500)
new_model = learn(902, 2000, 550)
new_model = learn(902, 2000, 600)
new_model = learn(902, 2000, 650)
new_model = learn(902, 2000, 700)
new_model = learn(902, 2000, 750)
new_model = learn(902, 2000, 800)
new_model = learn(902, 2000, 850)
new_model = learn(902, 2000, 900)
new_model = learn(902, 2000, 950)
new_model = learn(902, 2000, 1000)<jupyter_output>Data is ready
100 100 finished
100 150 finished
100 200 finished
100 250 finished
150 100 finished
150 150 finished
150 200 finished
150 250 finished
200 100 finished
200 150 finished
200 200 finished
200 250 finished
250 100 finished
250 150 finished
250 200 finished
250 250 finished
best model hidden size: 100 150
0.001190816533837356
3.022280058899337<jupyter_text>5s<jupyter_code>new_model = learn(19, 5000, 50)
new_model = learn(19, 5000, 100)
new_model = learn(19, 5000, 150)
new_model = learn(19, 5000, 200)
new_model = learn(19, 5000, 250)
new_model = learn(19, 5000, 300)
new_model = learn(19, 5000, 350)
new_model = learn(19, 5000, 400)
new_model = learn(19, 5000, 450)
new_model = learn(19, 5000, 500)
new_model = learn(19, 5000, 550)
new_model = learn(19, 5000, 600)
new_model = learn(19, 5000, 650)
new_model = learn(19, 5000, 700)
new_model = learn(19, 5000, 750)
new_model = learn(19, 5000, 800)
new_model = learn(19, 5000, 850)
new_model = learn(19, 5000, 900)
new_model = learn(19, 5000, 950)
new_model = learn(19, 5000, 1000)<jupyter_output>Data is ready
100 100 finished
100 150 finished
100 200 finished
100 250 finished
150 100 finished
150 150 finished
150 200 finished
150 250 finished
200 100 finished
200 150 finished
200 200 finished
200 250 finished
250 100 finished
250 150 finished
250 200 finished
250 250 finished
best model hidden size: 100 100
0.0026960382961240753
27.287717645861807<jupyter_text>15s<jupyter_code>new_model = learn(20, 15000, 50)
new_model = learn(20, 15000, 100)
new_model = learn(20, 15000, 150)
new_model = learn(20, 15000, 200)
new_model = learn(20, 15000, 250)
new_model = learn(20, 15000, 300)
new_model = learn(20, 15000, 350)
new_model = learn(20, 15000, 400)
new_model = learn(20, 15000, 450)
new_model = learn(20, 15000, 500)
new_model = learn(20, 15000, 550)
new_model = learn(20, 15000, 600)
new_model = learn(20, 15000, 650)
new_model = learn(20, 15000, 700)
new_model = learn(20, 15000, 750)
new_model = learn(20, 15000, 800)
new_model = learn(20, 15000, 850)
new_model = learn(20, 15000, 900)
new_model = learn(20, 15000, 950)
new_model = learn(20, 15000, 1000)
num = [str(i) for i in range(902)]
p1 = [read_csv('ics_data_preprocessed/06_Smart_Meter_45/P1/2000/' + n + '.csv', squeeze=True, parse_dates=['ts'], index_col='ts') for n in num]
    
p1 = [prepare_data(df, 1000) for df in p1]
p1 = sum(p1, [])
p1 = [df.values.tolist() for df in p1]
    
train, test = train_test_split(p1, test_size=0.2, random_state=42)
train_data_normalized = train
test_data_normalized = test
    
train_data, val_data = train_test_split(train_data_normalized, test_size=0.15, random_state=42)
train_data = torch.FloatTensor(train_data)
val_data = torch.FloatTensor(val_data)
test_data = torch.FloatTensor(test_data_normalized)
    
X_train = train_data[:, :-10]
y_train = train_data[:, -10:]
X_val = val_data[:, :-10]
y_val = val_data[:, -10:]
X_test = test_data[:, :-10]
y_test = test_data[:, -10:]
    
print("Data is ready")
    
loss_function = nn.MSELoss()
    
val_losses = []
    
best_hidden_layer_size = 50
    

losses = []
        
    
best_model = BPNN(1000 - 10, 100, 150)
model = BPNN(1000 - 10, 100, 150)
optimizer = torch.optim.Adam(model.parameters(), lr=0.2)
    
epochs = 1000
    
for i in range(epochs):
    model.train()
            
    optimizer.zero_grad()
            
    y_pred = model(X_train)
    single_loss = loss_function(y_pred, y_train)
    losses.append(single_loss)
            
    single_loss.backward()
    optimizer.step()
            
            
    model.eval()

    with torch.no_grad():
        y_pred = model(X_val)

        single_loss = loss_function(y_pred, y_val)

        if (len(val_losses) == 0) or (single_loss < min(val_losses)):

            best_model = model
                
        val_losses.append(single_loss)

    
print("best model hidden size:", best_hidden_layer_size)
    
predictions = []
best_model.eval()
with torch.no_grad():
    predictions = [best_model(seq) for (seq, labels) in zip(X_test, y_test)]
pred = [torch.cat((i, j)) for (i, j) in zip(X_test, predictions)]
actual_predictions = np.array([np.array(i) for i in pred])
mape = [np.mean(np.abs(actual_predictions[i] - test[i])/np.abs(test[i])) for i in range(len(test))]
print(sum(mape) / len(mape))
rmse = [np.mean((actual_predictions[i] - test[i])**2)**.5 for i in range(len(test))]
print(sum(rmse) / len(rmse))
# 2, 1000
# 100, 150
# new_model = learn(902, 2000, 1000)
predictions = []
best_model.eval()
with torch.no_grad():
    predictions = [best_model(seq) for (seq, labels) in zip(X_test, y_test)]
pred = [torch.cat((i, j)) for (i, j) in zip(X_test, predictions)]
actual_predictions = np.array([np.array(i) for i in pred])
mape = [np.mean(np.abs(actual_predictions[i] - test[i])/np.abs(test[i])) for i in range(len(test))]
print(sum(mape) / len(mape))
rmse = [np.mean((actual_predictions[i] - test[i])**2)**.5 for i in range(len(test))]
print(sum(rmse) / len(rmse))
n = 2
plt.plot(test_data[n].numpy())
plt.plot(actual_predictions[n])
num = [str(i) for i in range(20)]
p1 = [read_csv('ics_data_preprocessed/06_Smart_Meter_45/P1/15000/' + n + '.csv', squeeze=True, parse_dates=['ts'], index_col='ts') for n in num]
    
p1 = [prepare_data(df, 200) for df in p1]
p1 = sum(p1, [])
p1 = [df.values.tolist() for df in p1]
    
train, test = train_test_split(p1, test_size=0.2, random_state=42)
train_data_normalized = train
test_data_normalized = test
    
train_data, val_data = train_test_split(train_data_normalized, test_size=0.15, random_state=42)
train_data = torch.FloatTensor(train_data)
val_data = torch.FloatTensor(val_data)
test_data = torch.FloatTensor(test_data_normalized)
    
X_train = train_data[:, :-10]
y_train = train_data[:, -10:]
X_val = val_data[:, :-10]
y_val = val_data[:, -10:]
X_test = test_data[:, :-10]
y_test = test_data[:, -10:]
    
print("Data is ready")
    
loss_function = nn.MSELoss()
    
val_losses = []
    
best_hidden_layer_size = 50
    

losses = []
        
    
best_model = BPNN(200 - 10, 100, 150)
model = BPNN(200 - 10, 100, 150)
optimizer = torch.optim.Adam(model.parameters(), lr=0.2)
    
epochs = 1000
    
for i in range(epochs):
    model.train()
            
    optimizer.zero_grad()
            
    y_pred = model(X_train)
    single_loss = loss_function(y_pred, y_train)
    losses.append(single_loss)
            
    single_loss.backward()
    optimizer.step()
            
            
    model.eval()

    with torch.no_grad():
        y_pred = model(X_val)

        single_loss = loss_function(y_pred, y_val)

        if (len(val_losses) == 0) or (single_loss < min(val_losses)):

            best_model = model
                
        val_losses.append(single_loss)

    
print("best model hidden size:", best_hidden_layer_size)
    
predictions = []
best_model.eval()
with torch.no_grad():
    predictions = [best_model(seq) for (seq, labels) in zip(X_test, y_test)]
pred = [torch.cat((i, j)) for (i, j) in zip(X_test, predictions)]
actual_predictions = np.array([np.array(i) for i in pred])
mape = [np.mean(np.abs(actual_predictions[i] - test[i])/np.abs(test[i])) for i in range(len(test))]
print(sum(mape) / len(mape))
rmse = [np.mean((actual_predictions[i] - test[i])**2)**.5 for i in range(len(test))]
print(sum(rmse) / len(rmse))
# new_model = learn(20, 15000, 200)
# 100, 100
predictions = []
best_model.eval()
with torch.no_grad():
    predictions = [best_model(seq) for (seq, labels) in zip(X_test, y_test)]
pred = [torch.cat((i, j)) for (i, j) in zip(X_test, predictions)]
actual_predictions = np.array([np.array(i) for i in pred])
mape = [np.mean(np.abs(actual_predictions[i] - test[i])/np.abs(test[i])) for i in range(len(test))]
print(sum(mape) / len(mape))
rmse = [np.mean((actual_predictions[i] - test[i])**2)**.5 for i in range(len(test))]
print(sum(rmse) / len(rmse))
n = 1
plt.plot(test_data[n].numpy())
plt.plot(actual_predictions[n])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1352596716905059, 'fraction_numerical': 0.15378707881347797, 'mean_word_length': 4.443051201671891, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '626539', 'license': 'MIT', 'n_tokens_mistral': 5226, 'n_tokens_neox': 3918, 'n_words': 1042, 'path': 'BPNN2layers.ipynb', 'repo_name': 'HannaYakusevych/Time_series_forecasting', 'size': '10417'}