Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the base and average recommenders #19

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions ai/recommender/average_recommender.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Recommender system for Penn AI.

"""
import pandas as pd
from .base import BaseRecommender
Expand All @@ -14,16 +13,15 @@ class AverageRecommender(BaseRecommender):
Parameters
----------
ml_type: str, 'classifier' or 'regressor'
recommending classifiers or regressors. used to determine ML options.
Recommending classifiers or regressors. Used to determine ML options.

metric: str
the metric by which to assess performance in the data.
default: accuracy for classifiers, mse for regressors.
metric: str (default: accuracy for classifiers, mse for regressors)
The metric by which to assess performance on the datasets.

"""

def __init__(self, ml_type='classifier', metric=None):
"""initialize recommendation system."""
"""Initialize recommendation system."""
if ml_type not in ['classifier', 'regressor']:
raise ValueError('ml_type must be "classifier" or "regressor"')

Expand Down Expand Up @@ -51,6 +49,7 @@ def update(self, results_data):
Parameters
----------
results_data: DataFrame with columns corresponding to:
'dataset'
'algorithm'
'parameters'
self.metric
Expand Down Expand Up @@ -78,12 +77,14 @@ def update(self, results_data):
self._update_scores(new_scores, new_weights)

def recommend(self, dataset_id=None, n_recs=1):
"""return a model and parameter values expected to do best on the dataset.
"""Return a model and parameter values expected to do best on dataset.

Parameters
----------
n_recs (default: 1): optionally, return a list of length n_recs
in order of estimators and parameters expected to do best.
dataset_id: string
ID of the dataset for which the recommender is generating recommendations.
n_recs: int (default: 1), optional
Return a list of length n_recs in order of estimators and parameters expected to do best.
"""

# return ML+P for best average y
Expand Down Expand Up @@ -118,7 +119,7 @@ def recommend(self, dataset_id=None, n_recs=1):
return ml_rec, p_rec, rec_score

def _update_scores(self, new_scores, new_weights):
"""update scores based on new_scores"""
"""Update scores based on new_scores."""
new_ind = new_scores.index.values
if len(self.scores.index) == 0:
self.scores = new_scores
Expand Down
18 changes: 9 additions & 9 deletions ai/recommender/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ class BaseRecommender:
Parameters
----------
ml_type: str, 'classifier' or 'regressor'
recommending classifiers or regressors. used to determine ML options.
Recommending classifiers or regressors. Used to determine ML options.

metric: str
the metric by which to assess performance in the data.
default: accuracy for classifiers, mse for regressors.
metric: str (default: accuracy for classifiers, mse for regressors)
The metric by which to assess performance on the datasets.

"""

def __init__(self, ml_type='classifier', metric=None):
"""initialize recommendation system."""
"""Initialize recommendation system."""
raise RuntimeError('Do not instantiate the BaseRecommender class directly.')

def update(self, results_data):
Expand All @@ -36,12 +35,13 @@ def update(self, results_data):
raise NotImplementedError

def recommend(self, dataset_id=None, n_recs=1):
"""return a model and parameter values expected to do best on
dataset.
"""Return a model and parameter values expected to do best on dataset.

Parameters
----------
n_recs (default: 1): optionally, return a list of length n_recs
in order of estimators and parameters expected to do best.
dataset_id: string
ID of the dataset for which the recommender is generating recommendations.
n_recs: int (default: 1), optional
Return a list of length n_recs in order of estimators and parameters expected to do best.
"""
raise NotImplementedError