Skip to content

Commit

Permalink
Conventions of PEP8 solved
Browse files Browse the repository at this point in the history
and added the Rescaled SGDRegressor
  • Loading branch information
nineil committed Jun 10, 2014
1 parent b014a9c commit 6da4c0c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions skll/learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,16 @@
from sklearn.preprocessing import StandardScaler
from sklearn.svm.base import BaseLibLinear
from sklearn.utils import shuffle as sk_shuffle

# sklearn models: these are used indirectly, so ignore linting messages
from sklearn.ensemble import (GradientBoostingClassifier,
GradientBoostingRegressor, RandomForestClassifier,
RandomForestRegressor)
from sklearn.linear_model import (ElasticNet, Lasso, LinearRegression,
LogisticRegression, Ridge)
LogisticRegression, Ridge, SGDClassifier,
SGDRegressor)
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm import LinearSVC, SVC, SVR
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor

from sklearn.linear_model import SGDClassifier
from sklearn.linear_model import SGDRegressor

from skll.data import ExamplesTuple
from skll.metrics import _CORRELATION_METRICS, use_score_func
from skll.version import VERSION
Expand All @@ -75,11 +71,18 @@
'GradientBoostingRegressor': [{'max_depth': [1, 3, 5]}],
'Ridge': [{'alpha': [0.01, 0.1, 1.0, 10.0, 100.0]}],
'Lasso': [{'alpha': [0.01, 0.1, 1.0, 10.0, 100.0]}],
'ElasticNet': [{'alpha': [0.01, 0.1, 1.0, 10.0, 100.0]}],
'ElasticNet': [{'alpha': [0.01, 0.1, 1.0, 10.0,
100.0]}],
'SVR': [{'C': [0.01, 0.1, 1.0, 10.0, 100.0]}],
'LinearRegression': [{}],
'SGDClassifier':[{'alpha': [0.000001, 0.00001, 0.0001, 0.001, 0.01], 'penalty': ['l1', 'l2', 'elasticnet']}], # boundary default
'SGDRegressor':[{'alpha': [0.000001, 0.00001, 0.0001, 0.001, 0.01], 'penalty': ['l1', 'l2', 'elasticnet']}]} # boundary default
'SGDClassifier': [{'alpha': [0.000001, 0.00001, 0.0001,
0.001, 0.01],
'penalty': ['l1', 'l2',
'elasticnet']}],
'SGDRegressor': [{'alpha': [0.000001, 0.00001, 0.0001,
0.001, 0.01],
'penalty': ['l1', 'l2',
'elasticnet']}]}

_REGRESSION_MODELS = frozenset(['DecisionTreeRegressor', 'ElasticNet',
'GradientBoostingRegressor', 'Lasso',
Expand Down Expand Up @@ -309,6 +312,7 @@ def init(self, constrain=True, rescale=True, **kwargs):
# Return modified class
return cls


# Rescaled regressors
@rescaled
class RescaledDecisionTreeRegressor(DecisionTreeRegressor):
Expand Down Expand Up @@ -350,6 +354,11 @@ class RescaledSVR(SVR):
pass


@rescaled
class RescaledSGDRegressor(SGDRegressor):
pass


class Learner(object):
"""
A simpler learner interface around many scikit-learn classification
Expand Down Expand Up @@ -435,14 +444,13 @@ def __init__(self, model_type, probability=False, feature_scaling='none',
elif self._model_type == 'SVR':
self._model_kwargs['cache_size'] = 1000
self._model_kwargs['kernel'] = 'linear'


if self._model_type in {'RandomForestClassifier', 'LinearSVC',
'LogisticRegression', 'DecisionTreeClassifier',
'GradientBoostingClassifier',
'GradientBoostingRegressor',
'DecisionTreeRegressor',
'RandomForestRegressor', 'SGDClassifier', 'SGDRegressor'}:
'RandomForestRegressor', 'SGDClassifier',
'SGDRegressor'}:
self._model_kwargs['random_state'] = 123456789

if model_kwargs:
Expand Down Expand Up @@ -532,7 +540,7 @@ def model_params(self):
for feat, idx in iteritems(self.feat_vectorizer.vocabulary_):
if coef[idx]:
res[feat] = correction * coef[idx]
#res[feat] = coef[idx]
# res[feat] = coef[idx]
elif isinstance(self._model, BaseLibLinear):
label_list = self.label_list

Expand Down Expand Up @@ -686,7 +694,6 @@ def _train_setup(self, examples):
with_mean=False,
with_std=False)


def train(self, examples, param_grid=None, grid_search_folds=5,
grid_search=True, grid_objective='f1_score_micro',
grid_jobs=None, shuffle=True):
Expand Down

0 comments on commit 6da4c0c

Please sign in to comment.