-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.py
71 lines (52 loc) · 2.03 KB
/
tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ------------------------------------------------------------------ #
# Imports
# ------------------------------------------------------------------ #
# Import other libraries
from IPython.display import display
import numpy as np
import pandas as pd
import pyarrow
import os
# Import files
from helpers import *
from cross_validation import *
from models import *
from dataloader import *
from dataprocess import processing
# ------------------------------------------------------------------ #
# ------------------------------------------------------------------ #
if __name__ == '__main__':
# Define the classifier
classifier = 'hydro'
# Load the data sets
data_set, classes = load_data_sets(classifier = classifier)
# Get a processing on the data sets
X, y = processing(data_set, classes, classifier)
# Get a train and test set for modelization
k_fold = 5
seed = 0
X_train, y_train, X_test, y_test = split_data(X, y, kfold = k_fold, seed = seed)
# Feature selection
method = 'lassoCV'
model_feat_selec = get_model_features_selection(X_train, y_train, method, k_fold, seed = seed)
# Select the good features
X_train_reduce = feature_transform(model_feat_selec, X_train, method)
X_test_reduce = feature_transform(model_feat_selec, X_test, method)
# Oversampling
X_train_reduce, y_train = smote_data_augmentation(X_train_reduce, y_train, seed = seed)
# Set the verbosity
verbose = 2
# MLR model
MLR, param = get_model_MLR(seed = seed)
cv_MLR = evaluate_model(MLR,
param,
X_train_reduce,
y_train,
X_test_reduce,
y_test,
verbosity = verbose)
# Save best model
path = 'Models/trained_model/'+str(classifier)+'_MLR.pkl'
save_model(path, cv_MLR)
# ------------------------------------------------------------------ #
# ------------------------------------------------------------------ #