Skip to content

Commit

Permalink
adds package versions and optional model name to saved pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
ClimbsRocks committed Jan 20, 2018
1 parent 34606e6 commit 0c218ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion auto_ml/predictor.py
Expand Up @@ -189,7 +189,7 @@ def _construct_pipeline(self, model_name='LogisticRegression', trained_pipeline=
final_model = utils_models.get_model_from_name(model_name, training_params=params)
pipeline_list.append(('final_model', utils_model_training.FinalModelATC(model=final_model, type_of_estimator=self.type_of_estimator, ml_for_analytics=self.ml_for_analytics, name=self.name, _scorer=self._scorer, feature_learning=feature_learning, uncertainty_model=self.need_to_train_uncertainty_model, training_prediction_intervals=training_prediction_intervals, column_descriptions=self.column_descriptions, training_features=training_features, keep_cat_features=keep_cat_features, is_hp_search=is_hp_search, X_test=self.X_test, y_test=self.y_test)))

constructed_pipeline = utils.ExtendedPipeline(pipeline_list, keep_cat_features=keep_cat_features)
constructed_pipeline = utils.ExtendedPipeline(pipeline_list, keep_cat_features=keep_cat_features, name=self.name)
return constructed_pipeline


Expand Down
34 changes: 24 additions & 10 deletions auto_ml/utils.py
Expand Up @@ -2,6 +2,7 @@
import datetime
import numbers
import os
import pkg_resources

import numpy as np
import pandas as pd
Expand All @@ -13,6 +14,8 @@
from sklearn.utils.metaestimators import if_delegate_has_method
from sklearn.utils import column_or_1d

from _version import __version__ as auto_ml_version


def is_linear_model(model_names):
linear_models = set(['RANSACRegressor', 'LinearRegression', 'Ridge', 'Lasso', 'ElasticNet', 'LassoLars', 'OrthogonalMatchingPursuit', 'BayesianRidge', 'ARDRegression', 'SGDRegressor', 'PassiveAggressiveRegressor', 'LogisticRegression', 'RidgeClassifier', 'SGDClassifier', 'Perceptron', 'PassiveAggressiveClassifier'])
Expand Down Expand Up @@ -225,15 +228,6 @@ def __init__(self):
super(self.__class__, self).__init__()

def transform(self, y):
"""Transform labels to normalized encoding.
Parameters
----------
y : array-like of shape [n_samples]
Target values.
Returns
-------
y : array-like of shape [n_samples]
"""
y = column_or_1d(y, warn=True)

classes = np.unique(y)
Expand All @@ -242,11 +236,31 @@ def transform(self, y):
self.classes_ = np.hstack((self.classes_, diff))
return np.searchsorted(self.classes_, y)[0]


def get_versions():

libraries_to_check = ['dill', 'h5py', 'keras', 'lightgbm', 'numpy', 'pandas', 'pathos', 'python', 'scikit-learn', 'scipy', 'sklearn-deap2', 'tabulate', 'tensorflow', 'xgboost']

versions = {
'auto_ml': auto_ml_version
}

for lib in libraries_to_check:
try:
versions[lib] = pkg_resources.get_distribution(lib).version
except:
pass

return versions


class ExtendedPipeline(Pipeline):

def __init__(self, steps, keep_cat_features=False):
def __init__(self, steps, keep_cat_features=False, name=None):
super(self.__class__, self).__init__(steps)
self.keep_cat_features = keep_cat_features
self.__versions__ = get_versions()
self.name = name


@if_delegate_has_method(delegate='_final_estimator')
Expand Down

0 comments on commit 0c218ce

Please sign in to comment.