<jupyter_start><jupyter_text>Import dataThe model fitting was done in colab using notebook 5.0. Unfortunatelly, the model saving methods `.save()` class method, and pickle, didn't produce the same predicted probabilities using the loaded models as compared to the ones predictied using the in-memory models. The loaded models predicted probabilities had were all the same value.As a result, I decided to do the fit and predict in colab, and then save the predictions. In this notebook, we load these predictions.  y_pred<jupyter_code>models_proba_path = ROOT_DIR / 'data/raw' / 'models_proba_with_nans.csv'

if models_proba_path.is_file():
    models_proba = pd.read_csv(models_proba_path)
else:
    print('Check if the model proba file exists. If not, run notebook 5.0-rp-fit-predict-save-proba-colab on Colab')
models_proba.sample(10)
# The sum of all probabilities for each sample should be 1
models_proba.loc[:, 'Sandstone':'Basement'].sum(axis=1).describe()
models_proba.head()<jupyter_output><empty_output><jupyter_text>y_true<jupyter_code>csv_open_test_path = ROOT_DIR / 'data/external/open_test_y_true.csv'

csv_open_test = pd.read_csv(csv_open_test_path, ',')
csv_open_test.head()
y_true = csv_open_test['FORCE_2020_LITHOFACIES_LITHOLOGY'].map(KEYS_TO_ORDINAL)<jupyter_output><empty_output><jupyter_text>Probabilities mean over models<jupyter_code># Container to hold added probabilities across models
models_probas_cumsum = sum((model_proba.loc[:, 'Sandstone':'Basement'].reset_index(drop=True)
                            for model_name, model_proba
                            in models_proba.groupby('MODEL')))
models_probas_cumsum.head()
models_len = len(models_proba['MODEL'].unique())
models_probas_mean = models_probas_cumsum / models_len
models_probas_mean.head()<jupyter_output><empty_output><jupyter_text>Lithology with highest cumsum probability per sample<jupyter_code># Turn column names from lith to ordinal
models_probas_mean.columns = [LITHOLOGY_TO_ORDINAL[col] for col in models_probas_mean.columns]
y_pred = models_probas_mean.idxmax(axis=1)<jupyter_output><empty_output><jupyter_text>Score<jupyter_code>open_test_score = score(y_true, y_pred)
print(f'Olawale modified open test score is: {open_test_score:.4f}')<jupyter_output>Olawale modified open test score is: -0.5442
{'fraction_non_alphanumeric': 0.09260869565217392, 'fraction_numerical': 0.00826086956521739, 'mean_word_length': 6.3514376996805115, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '245381', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 802, 'n_tokens_neox': 771, 'n_words': 182, 'path': 'notebooks/5.1-rp-fit-predict-proba-score.ipynb', 'repo_name': 'RafaelPinto/force_2020_lith', 'size': '2300'}