# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:ysi]
#     language: python
#     name: conda-env-ysi-py
# ---

# +
import numpy as np
np.random.seed(0)
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
sns.set_context('talk', font_scale=1.5)
sns.set(color_codes=True)

import matplotlib.gridspec as gridspec

# %matplotlib inline

# +
from ysi_utils.models.setup_model import model

from ysi_utils.data import low
from ysi_utils.descriptors import dragon
from ysi_utils.validation import y_train as y
from ysi_utils.validation import y_test

X = dragon.loc[y.index]
X_test = dragon.loc[y_test.index]
# -

from sklearn.ensemble import BaggingRegressor
from sklearn.metrics import median_absolute_error

# *This next step takes a considerable amount of computing time, since the model is refit 25 times*

bagging_model = BaggingRegressor(base_estimator=model, random_state=0, verbose=False,
                                 max_samples=.9, bootstrap=False, n_estimators=25)
bagging_model.fit(X.values, y.YSI.values)

import keras

keras.__version__

# +
import sys
# This is required to prevent errors on pickling.
sys.setrecursionlimit(10000)

from sklearn.externals import joblib
joblib.dump(bagging_model, '../ysi_utils/models/bagging_model.pkl.large', compress=9)

StarcoderdataJupyterScriptsDedupFiltered