<jupyter_start><jupyter_text>RMSE dla modeli<jupyter_code>import pandas as pd
import numpy as np
import os
from Arima import Arima
from boosting import XGBoost
from copy import deepcopy
def rmse(y, y_hat):
    return np.sqrt(np.sum((y - y_hat)**2) / len(y))
df = pd.read_csv('final_data.csv')
countries = df["Country"].unique()
continents = [df[df["Country"] == i]["Continent"].iloc[0] for i in countries]
new_df = pd.DataFrame({'Continent': continents, 'Country': countries})
def country_loss(model, country, years, *args):
    data = df[df["Country"] == country]["AverageTemperature"].to_numpy()
    training, test = data[:years*12], data[:-years*12]
    model_ = model(training, *args)
    model_.train()
    predictions = model_.predict(len(test))
    return rmse(test, predictions)

os.chdir(r"C:\\Users\\Mark Kostriew\\time_series_prediction")
def loss_to_files(model, model_name, *args): 
    os.chdir(os.path.dirname(os.path.realpath(__name__)))
    os.chdir(r"loss/test/country")
    df_ = deepcopy(new_df)
    vec = np.zeros(len(df_['country']))
    for i in range(len(countries)):
        vec[i] = country_loss(model, countries[i], 10, *args)
    df_['Loss'] = vec
    df_.to_csv(f'{model_name}.csv', index=False)  
loss_to_files(XGBoost, "XGBoost", 24)
os.chdir(r"C:\\Users\\Mark Kostriew\\time_series_prediction")
loss_to_files(Arima, "Arima")
continents_ = df["Continent"].unique()
continents_
def continent_loss(model_name):
    df = pd.read_csv(rf"loss/test/country/{model_name}.csv")
    new_df = pd.DataFrame({'Continent': continents_})
    func = lambda x: df[df["continent"] == x]['loss'].mean()
    new_df['Loss'] = new_df['Continent'].apply(func)
    new_df.to_csv(rf"loss/test/continent/{model_name}.csv", index=False)
continent_loss("XGBoost")
continent_loss("Arima")
a = pd.read_csv(r"loss/test/country/Arima.csv")
a.columns = ['Continent', 'Country', 'Loss']
a.to_csv(r'loss/test/country/Arima.csv', index=False)
b = pd.read_csv(r"loss/test/country/XGBoost.csv") 
b.columns = ['Continent', 'Country', 'Loss']
b.to_csv(r'loss/test/country/XGBoost.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17783018867924527, 'fraction_numerical': 0.0047169811320754715, 'mean_word_length': 5.506134969325154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '507149', 'license': 'MIT', 'n_tokens_mistral': 818, 'n_tokens_neox': 800, 'n_words': 137, 'path': 'rmse.ipynb', 'repo_name': 'Manik2000/time_series_prediction', 'size': '2120'}