Skip to content

Commit 3bdc405

Browse files
Merge pull request #8 from ottenbreit-data-science/examples
Examples
2 parents d68b438 + 7eed65c commit 3bdc405

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

examples/train_aplr_cross_validation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pandas as pd
2-
import pickle
2+
import joblib
33
from sklearn.model_selection import GridSearchCV, train_test_split
44
from sklearn.datasets import load_diabetes
55
from aplr import APLRRegressor
@@ -35,7 +35,7 @@
3535
print("Done training")
3636

3737
#Saving model
38-
pickle.dump(best_model,open("best_model.zip","wb"))
38+
joblib.dump(best_model,"best_model.gz")
3939

4040
#Cross validation results when doing grid search
4141
cv_results = pd.DataFrame(grid_search_cv.cv_results_).sort_values(by="rank_test_score")
@@ -44,11 +44,11 @@
4444
validation_error_per_boosting_step = best_model.get_validation_error_steps()
4545

4646
#Terms in the best model
47-
terms=pd.DataFrame({"Predictor":best_model.get_term_names(),"Coefficient":best_model.get_term_coefficients()})
47+
terms=pd.DataFrame({"term":best_model.get_term_names(),"coefficient":best_model.get_term_coefficients()})
4848

49-
#Coefficients for intercept and the first predictor per boosting step
49+
#Coefficients for intercept and the first term per boosting step
5050
intercept_coefficient_per_boosting_step = best_model.get_intercept_steps()
51-
first_predictor_coefficient_per_boosting_step = best_model.get_term_coefficient_steps(term_index=0)
51+
first_term_coefficient_per_boosting_step = best_model.get_term_coefficient_steps(term_index=0)
5252

5353
#Estimated feature importance was estimated on the validation set when the best model was trained
5454
estimated_feature_importance = pd.DataFrame({"predictor":predictors,"importance":best_model.get_feature_importance()})

examples/train_aplr_validation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pandas as pd
22
import numpy as np
3-
import pickle
3+
import joblib
44
from sklearn.model_selection import ParameterGrid, train_test_split
55
from sklearn.datasets import load_diabetes
66
from aplr import APLRRegressor
@@ -45,7 +45,7 @@
4545
print("Done training")
4646

4747
#Saving model
48-
pickle.dump(best_model,open("best_model.zip","wb"))
48+
joblib.dump(best_model,"best_model.gz")
4949

5050
#Validation results when doing grid search
5151
validation_results = validation_results.sort_values(by="validation_error")
@@ -54,11 +54,11 @@
5454
validation_error_per_boosting_step = best_model.get_validation_error_steps()
5555

5656
#Terms in the best model
57-
terms=pd.DataFrame({"Predictor":best_model.get_term_names(),"Coefficient":best_model.get_term_coefficients()})
57+
terms=pd.DataFrame({"term":best_model.get_term_names(),"coefficient":best_model.get_term_coefficients()})
5858

59-
#Coefficients for intercept and the first predictor per boosting step
59+
#Coefficients for intercept and the first term per boosting step
6060
intercept_coefficient_per_boosting_step = best_model.get_intercept_steps()
61-
first_predictor_coefficient_per_boosting_step = best_model.get_term_coefficient_steps(term_index=0)
61+
first_term_coefficient_per_boosting_step = best_model.get_term_coefficient_steps(term_index=0)
6262

6363
#Estimated feature importance was estimated on the validation set when the best model was trained
6464
estimated_feature_importance = pd.DataFrame({"predictor":predictors,"importance":best_model.get_feature_importance()})

0 commit comments

Comments
 (0)