<jupyter_start><jupyter_text>Calculate the confidence interval of the error by using t-distribution.<jupyter_code>import numpy as np
import pandas as pd

import datetime
date = datetime.datetime.now().strftime('%Y%m%d')<jupyter_output><empty_output><jupyter_text>Case study<jupyter_code>from joblib import load
from  nwp_cali import PrepareData

measurement = 'CaCO3%'
model = load('models/{}_nmf+svr_model_20210823.joblib'.format(measurement[:-1].lower()))
prepare = PrepareData(measurement=measurement)
data_df = prepare.select_casestudy(case_cores = ['PS75-056-1'])
X, y = prepare.produce_Xy(data_df)

y_df = data_df[['core', 'mid_depth_mm']].copy()
y_df[measurement] = y
y_df['{}_pred'.format(measurement)] = np.exp(model.predict(X))

measurement = 'TOC%'
model = load('models/{}_nmf+svr_model_20210823.joblib'.format(measurement[:-1].lower()))
prepare = PrepareData(measurement=measurement)
data_df = prepare.select_casestudy(case_cores = ['PS75-056-1'])
X, y = prepare.produce_Xy(data_df)

y_df[measurement] = y
y_df['{}_pred'.format(measurement)] = np.exp(model.predict(X))

y_df.info()
from sklearn.metrics import mean_squared_error

for measurement in ['CaCO3%', 'TOC%']:
    print(
        'RMSE', 
        measurement, 
        mean_squared_error(
            y_df[measurement], 
            y_df['{}_pred'.format(measurement)],
            squared=False)
    )
from scipy import stats

confidence = 0.95

for measurement in ['CaCO3%', 'TOC%']:
    err = (y_df['{}_pred'.format(measurement)] - y_df[measurement]).values
    mean, sigma = np.mean(err), np.std(err)
    conf_int = stats.t.interval(confidence, df=len(err)-1, loc=mean, scale=sigma)
    print(measurement, conf_int)

np.var(y_df['TOC%_pred'])<jupyter_output><empty_output><jupyter_text>Test set<jupyter_code>y_df = pd.read_csv('results/y_dev_preds_20210823.csv', index_col=0)
y_df.info()
from sklearn.metrics import mean_squared_error

for measurement in ['CaCO3%', 'TOC%']:
    print(
        'RMSE',
        measurement, 
        mean_squared_error(
            y_df[measurement].dropna(), 
            y_df['{}_pred'.format(measurement)].dropna(),
            squared=False)
    )
from scipy import stats

confidence = 0.95

for measurement in ['CaCO3%', 'TOC%']:

    err = (y_df['{}_pred'.format(measurement)].dropna() - y_df[measurement].dropna()).values
    mean, sigma = np.mean(err), np.std(err)
    conf_int = stats.t.interval(confidence, df=len(err)-1, loc=mean, scale=sigma)
    print(measurement, conf_int)

np.var(y_df['TOC%_pred'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.156078431372549, 'fraction_numerical': 0.0203921568627451, 'mean_word_length': 4.85091743119266, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '179526', 'license': 'MIT', 'n_tokens_mistral': 1001, 'n_tokens_neox': 941, 'n_words': 153, 'path': 'build_models_10.ipynb', 'repo_name': 'dispink/CaCO3_NWP', 'size': '2550'}