This is the first part of the tutorial, focusing on MERCS as a simple classifier.
import numpy as np
import os
import sys
from sklearn.metrics import (mean_absolute_error,
mean_squared_error,
mean_squared_log_error)
import pandas as pd
sys.path.insert(0, '..') # We add the parent dir to the path
from src.mercs.core import MERCS
from src.mercs.utils import *
import src.datasets as datasets
First, we import the nursery dataset.
train, test = datasets.load_slump()
This is a fully numerical dataset
train.head()
test.head()
model = MERCS()
ind_parameters = {'ind_type': 'RF',
'ind_n_estimators': 10,
'ind_max_depth': 4}
sel_parameters = {'sel_type': 'Base',
'sel_its': 4,
'sel_param': 1}
model.fit(train, **ind_parameters, **sel_parameters)
code = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
target_boolean = np.array(code) == 1
y_true = test[test.columns.values[target_boolean]].values
y_true
pred_parameters = {'pred_type': 'IT',
'pred_param': 0.1,
'pred_its': 4}
y_pred = model.predict(test,
**pred_parameters,
qry_code=code)
y_pred
y_true = test[test.columns.values[np.array(code)==1]].values
obs_1 = mean_absolute_error(y_true, y_pred)
obs_2 = mean_squared_error(y_true, y_pred)
obs_3 = mean_squared_log_error(y_true, y_pred)
obs = [obs_1, obs_2, obs_3]
for o in obs:
assert isinstance(o, (int, float))
assert 0 <= o
obs_3