Skip to content

Commit

Permalink
Fixes #139 Default n_jobs to 1
Browse files Browse the repository at this point in the history
* fix for windows use of joblib: n_jobs=1

* Revert test for GridSerch which must use n_jobs=-1
  • Loading branch information
kman0 authored and NicolasHug committed Apr 2, 2018
1 parent 56e534a commit efc0b44
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions surprise/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class will be removed in later versions.
used. For example, with ``n_jobs = -2`` all CPUs but one are\
used.
Default is ``-1``.
Default is ``1``.
pre_dispatch(int or string): Controls the number of jobs that get
dispatched during parallel execution. Reducing this number can be
useful to avoid an explosion of memory consumption when more jobs
Expand Down Expand Up @@ -195,7 +195,7 @@ class will be removed in later versions.
"""

def __init__(self, algo_class, param_grid, measures=['rmse', 'mae'],
n_jobs=-1, pre_dispatch='2*n_jobs', seed=None, verbose=1,
n_jobs=1, pre_dispatch='2*n_jobs', seed=None, verbose=1,
joblib_verbose=0):
self.best_params = CaseInsensitiveDefaultDict(list)
self.best_index = CaseInsensitiveDefaultDict(list)
Expand Down
10 changes: 5 additions & 5 deletions surprise/model_selection/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BaseSearchCV(with_metaclass(ABCMeta)):

@abstractmethod
def __init__(self, algo_class, measures=['rmse', 'mae'], cv=None,
refit=False, return_train_measures=False, n_jobs=-1,
refit=False, return_train_measures=False, n_jobs=1,
pre_dispatch='2*n_jobs', joblib_verbose=0):

self.algo_class = algo_class
Expand Down Expand Up @@ -253,7 +253,7 @@ class GridSearchCV(BaseSearchCV):
used. For example, with ``n_jobs = -2`` all CPUs but one are\
used.
Default is ``-1``.
Default is ``1``.
pre_dispatch(int or string): Controls the number of jobs that get
dispatched during parallel execution. Reducing this number can be
useful to avoid an explosion of memory consumption when more jobs
Expand Down Expand Up @@ -295,7 +295,7 @@ class GridSearchCV(BaseSearchCV):
<cv_results_example>`).
"""
def __init__(self, algo_class, param_grid, measures=['rmse', 'mae'],
cv=None, refit=False, return_train_measures=False, n_jobs=-1,
cv=None, refit=False, return_train_measures=False, n_jobs=1,
pre_dispatch='2*n_jobs', joblib_verbose=0):

super(GridSearchCV, self).__init__(
Expand Down Expand Up @@ -362,7 +362,7 @@ class RandomizedSearchCV(BaseSearchCV):
used. For example, with ``n_jobs = -2`` all CPUs but one are\
used.
Default is ``-1``.
Default is ``1``.
pre_dispatch(int or string): Controls the number of jobs that get
dispatched during parallel execution. Reducing this number can be
useful to avoid an explosion of memory consumption when more jobs
Expand Down Expand Up @@ -412,7 +412,7 @@ class RandomizedSearchCV(BaseSearchCV):
"""
def __init__(self, algo_class, param_distributions, n_iter=10,
measures=['rmse', 'mae'], cv=None, refit=False,
return_train_measures=False, n_jobs=-1,
return_train_measures=False, n_jobs=1,
pre_dispatch='2*n_jobs', random_state=None, joblib_verbose=0):

super(RandomizedSearchCV, self).__init__(
Expand Down
4 changes: 2 additions & 2 deletions surprise/model_selection/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def cross_validate(algo, data, measures=['rmse', 'mae'], cv=None,
return_train_measures=False, n_jobs=-1,
return_train_measures=False, n_jobs=1,
pre_dispatch='2*n_jobs', verbose=False):
'''
Run a cross validation procedure for a given algorithm, reporting accuracy
Expand Down Expand Up @@ -50,7 +50,7 @@ def cross_validate(algo, data, measures=['rmse', 'mae'], cv=None,
used. For example, with ``n_jobs = -2`` all CPUs but one are\
used.
Default is ``-1``.
Default is ``1``.
pre_dispatch(int or string): Controls the number of jobs that get
dispatched during parallel execution. Reducing this number can be
useful to avoid an explosion of memory consumption when more jobs
Expand Down
4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_gridsearchcv_same_splits():
param_grid = {'n_epochs': [5], 'lr_all': [.2, .2],
'reg_all': [.4, .4], 'n_factors': [5], 'random_state': [0]}
gs = GridSearchCV(SVD, param_grid, measures=['RMSE'], cv=kf,
n_jobs=-1)
n_jobs=1)
gs.fit(data)

rmse_scores = [m for m in gs.cv_results['mean_test_rmse']]
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_randomizedsearchcv_same_splits():
'reg_all': uniform(.4, 0), 'n_factors': [5],
'random_state': [0]}
rs = RandomizedSearchCV(SVD, param_distributions, measures=['RMSE'], cv=kf,
n_jobs=-1)
n_jobs=1)
rs.fit(data)

rmse_scores = [m for m in rs.cv_results['mean_test_rmse']]
Expand Down

0 comments on commit efc0b44

Please sign in to comment.