Skip to content

Commit

Permalink
Unify quotation marks 🔨
Browse files Browse the repository at this point in the history
  • Loading branch information
feger committed Oct 15, 2019
1 parent d29b255 commit acb8646
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 deletions.
4 changes: 2 additions & 2 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''This module runs a 5-Fold CV for all the algorithms (default parameters) on
"""This module runs a 5-Fold CV for all the algorithms (default parameters) on
the movielens datasets, and reports average RMSE, MAE, and total computation
time. It is used for making tables in the README.md file'''
time. It is used for making tables in the README.md file"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)
Expand Down
4 changes: 2 additions & 2 deletions examples/top_n_recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def get_top_n(predictions, n=10):
'''Return the top-N recommendation for each user from a set of predictions.
"""Return the top-N recommendation for each user from a set of predictions.
Args:
predictions(list of Prediction objects): The list of predictions, as
Expand All @@ -25,7 +25,7 @@ def get_top_n(predictions, n=10):
Returns:
A dict where keys are user (raw) ids and values are lists of tuples:
[(raw item id, rating estimation), ...] of size n.
'''
"""

# First map the predictions to each user.
top_n = defaultdict(list)
Expand Down
4 changes: 2 additions & 2 deletions surprise/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
def main():

class MyParser(argparse.ArgumentParser):
'''A parser which prints the help message when an error occurs. Taken from
http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu.''' # noqa
"""A parser which prints the help message when an error occurs. Taken from
http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu.""" # noqa

def error(self, message):
sys.stderr.write('error: %s\n' % message)
Expand Down
8 changes: 4 additions & 4 deletions surprise/builtin_datasets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''This module contains built-in datasets that can be automatically
downloaded.'''
"""This module contains built-in datasets that can be automatically
downloaded."""

from __future__ import (absolute_import, division, print_function,
unicode_literals)
Expand All @@ -12,10 +12,10 @@


def get_dataset_dir():
'''Return folder where downloaded datasets and other data are stored.
"""Return folder where downloaded datasets and other data are stored.
Default folder is ~/.surprise_data/, but it can also be set by the
environment variable ``SURPRISE_DATA_FOLDER``.
'''
"""

folder = os.environ.get('SURPRISE_DATA_FOLDER', os.path.expanduser('~') +
'/.surprise_data/')
Expand Down
50 changes: 25 additions & 25 deletions surprise/model_selection/split.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
The :mod:`model_selection.split<surprise.model_selection.split>` module
contains various cross-validation iterators. Design and tools are inspired from
the mighty scikit learn.
Expand All @@ -22,7 +22,7 @@
train_test_split
'''
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)
Expand All @@ -40,7 +40,7 @@


def get_cv(cv):
'''Return a 'validated' CV iterator.'''
"""Return a 'validated' CV iterator."""

if cv is None:
return KFold(n_splits=5)
Expand All @@ -54,7 +54,7 @@ def get_cv(cv):


class KFold():
'''A basic cross-validation iterator.
"""A basic cross-validation iterator.
Each fold is used once as a testset while the k - 1 remaining folds are
used for training.
Expand All @@ -73,7 +73,7 @@ class KFold():
shuffle(bool): Whether to shuffle the ratings in the ``data`` parameter
of the ``split()`` method. Shuffling is not done in-place. Default
is ``True``.
'''
"""

def __init__(self, n_splits=5, random_state=None, shuffle=True):

Expand All @@ -82,15 +82,15 @@ def __init__(self, n_splits=5, random_state=None, shuffle=True):
self.random_state = random_state

def split(self, data):
'''Generator function to iterate over trainsets and testsets.
"""Generator function to iterate over trainsets and testsets.
Args:
data(:obj:`Dataset<surprise.dataset.Dataset>`): The data containing
ratings that will be devided into trainsets and testsets.
Yields:
tuple of (trainset, testset)
'''
"""

if self.n_splits > len(data.raw_ratings) or self.n_splits < 2:
raise ValueError('Incorrect value for n_splits={0}. '
Expand Down Expand Up @@ -125,7 +125,7 @@ def get_n_folds(self):


class RepeatedKFold():
'''
"""
Repeated :class:`KFold` cross validator.
Repeats :class:`KFold` n times with different randomization in each
Expand All @@ -146,7 +146,7 @@ class RepeatedKFold():
shuffle(bool): Whether to shuffle the ratings in the ``data`` parameter
of the ``split()`` method. Shuffling is not done in-place. Default
is ``True``.
'''
"""

def __init__(self, n_splits=5, n_repeats=10, random_state=None):

Expand All @@ -155,15 +155,15 @@ def __init__(self, n_splits=5, n_repeats=10, random_state=None):
self.n_splits = n_splits

def split(self, data):
'''Generator function to iterate over trainsets and testsets.
"""Generator function to iterate over trainsets and testsets.
Args:
data(:obj:`Dataset<surprise.dataset.Dataset>`): The data containing
ratings that will be devided into trainsets and testsets.
Yields:
tuple of (trainset, testset)
'''
"""

rng = get_rng(self.random_state)

Expand All @@ -178,7 +178,7 @@ def get_n_folds(self):


class ShuffleSplit():
'''A basic cross-validation iterator with random trainsets and testsets.
"""A basic cross-validation iterator with random trainsets and testsets.
Contrary to other cross-validation strategies, random splits do not
guarantee that all folds will be different, although this is still very
Expand Down Expand Up @@ -210,7 +210,7 @@ class ShuffleSplit():
this to `False` defeats the purpose of this iterator, but it's
useful for the implementation of :func:`train_test_split`. Default
is ``True``.
'''
"""

def __init__(self, n_splits=5, test_size=.2, train_size=None,
random_state=None, shuffle=True):
Expand Down Expand Up @@ -262,15 +262,15 @@ def validate_train_test_sizes(self, test_size, train_size, n_ratings):
return int(train_size), int(test_size)

def split(self, data):
'''Generator function to iterate over trainsets and testsets.
"""Generator function to iterate over trainsets and testsets.
Args:
data(:obj:`Dataset<surprise.dataset.Dataset>`): The data containing
ratings that will be devided into trainsets and testsets.
Yields:
tuple of (trainset, testset)
'''
"""

test_size, train_size = self.validate_train_test_sizes(
self.test_size, self.train_size, len(data.raw_ratings))
Expand Down Expand Up @@ -300,7 +300,7 @@ def get_n_folds(self):

def train_test_split(data, test_size=.2, train_size=None, random_state=None,
shuffle=True):
'''Split a dataset into trainset and testset.
"""Split a dataset into trainset and testset.
See an example in the :ref:`User Guide <train_test_split_example>`.
Expand Down Expand Up @@ -328,14 +328,14 @@ def train_test_split(data, test_size=.2, train_size=None, random_state=None,
only used if ``shuffle`` is ``True``. Default is ``None``.
shuffle(bool): Whether to shuffle the ratings in the ``data``
parameter. Shuffling is not done in-place. Default is ``True``.
'''
"""
ss = ShuffleSplit(n_splits=1, test_size=test_size, train_size=train_size,
random_state=random_state, shuffle=shuffle)
return next(ss.split(data))


class LeaveOneOut():
'''Cross-validation iterator where each user has exactly one rating in the
"""Cross-validation iterator where each user has exactly one rating in the
testset.
Contrary to other cross-validation strategies, ``LeaveOneOut`` does not
Expand All @@ -359,7 +359,7 @@ class LeaveOneOut():
testset). Other users are discarded. Default is ``0``, so some
users (having only one rating) may be in the testset and not in the
trainset.
'''
"""

def __init__(self, n_splits=5, random_state=None, min_n_ratings=0):

Expand All @@ -368,15 +368,15 @@ def __init__(self, n_splits=5, random_state=None, min_n_ratings=0):
self.min_n_ratings = min_n_ratings

def split(self, data):
'''Generator function to iterate over trainsets and testsets.
"""Generator function to iterate over trainsets and testsets.
Args:
data(:obj:`Dataset<surprise.dataset.Dataset>`): The data containing
ratings that will be devided into trainsets and testsets.
Yields:
tuple of (trainset, testset)
'''
"""

# map ratings to the users ids
user_ratings = defaultdict(list)
Expand Down Expand Up @@ -410,23 +410,23 @@ def get_n_folds(self):


class PredefinedKFold():
'''A cross-validation iterator to when a dataset has been loaded with the
"""A cross-validation iterator to when a dataset has been loaded with the
:meth:`load_from_folds <surprise.dataset.Dataset.load_from_folds>`
method.
See an example in the :ref:`User Guide <load_from_folds_example>`.
'''
"""

def split(self, data):
'''Generator function to iterate over trainsets and testsets.
"""Generator function to iterate over trainsets and testsets.
Args:
data(:obj:`Dataset<surprise.dataset.Dataset>`): The data containing
ratings that will be devided into trainsets and testsets.
Yields:
tuple of (trainset, testset)
'''
"""

self.n_splits = len(data.folds_files)
for train_file, test_file in data.folds_files:
Expand Down
16 changes: 9 additions & 7 deletions surprise/model_selection/validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'''The validation module contains the cross_validate function, inspired from
the mighty scikit learn.'''
"""
The validation module contains the cross_validate function, inspired from
the mighty scikit learn.
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)
Expand All @@ -17,7 +19,7 @@
def cross_validate(algo, data, measures=['rmse', 'mae'], cv=None,
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
measures and computation times.
Expand Down Expand Up @@ -89,7 +91,7 @@ def cross_validate(algo, data, measures=['rmse', 'mae'], cv=None,
- ``'test_time'``: numpy array with the testing time in seconds for
each split.
'''
"""

measures = [m.lower() for m in measures]

Expand Down Expand Up @@ -130,7 +132,7 @@ def cross_validate(algo, data, measures=['rmse', 'mae'], cv=None,

def fit_and_score(algo, trainset, testset, measures,
return_train_measures=False):
'''Helper method that trains an algorithm and compute accuracy measures on
"""Helper method that trains an algorithm and compute accuracy measures on
a testset. Also report train and test times.
Args:
Expand Down Expand Up @@ -158,7 +160,7 @@ def fit_and_score(algo, trainset, testset, measures,
- The fit time in seconds.
- The testing time in seconds.
'''
"""

start_fit = time.time()
algo.fit(trainset)
Expand All @@ -183,7 +185,7 @@ def fit_and_score(algo, trainset, testset, measures,

def print_summary(algo, measures, test_measures, train_measures, fit_times,
test_times, n_splits):
'''Helper for printing the result of cross_validate.'''
"""Helper for printing the result of cross_validate."""

print('Evaluating {0} of algorithm {1} on {2} split(s).'.format(
', '.join((m.upper() for m in measures)),
Expand Down
4 changes: 2 additions & 2 deletions surprise/prediction_algorithms/algo_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ def predict(self, uid, iid, r_ui=None, clip=True, verbose=False):
return pred

def default_prediction(self):
'''Used when the ``PredictionImpossible`` exception is raised during a
"""Used when the ``PredictionImpossible`` exception is raised during a
call to :meth:`predict()
<surprise.prediction_algorithms.algo_base.AlgoBase.predict>`. By
default, return the global mean of all ratings (can be overridden in
child classes).
Returns:
(float): The mean of all ratings in the trainset.
'''
"""

return self.trainset.global_mean

Expand Down
1 change: 1 addition & 0 deletions surprise/prediction_algorithms/baseline_only.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
This class implements the baseline estimation.
"""

from __future__ import (absolute_import, division, print_function,
Expand Down
6 changes: 3 additions & 3 deletions surprise/reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''This module contains the Reader class.'''
"""This module contains the Reader class."""

from __future__ import (absolute_import, division, print_function,
unicode_literals)
Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(self, name=None, line_format='user item rating', sep=None,
entities]

def parse_line(self, line):
'''Parse a line.
"""Parse a line.
Ratings are translated so that they are all strictly positive.
Expand All @@ -84,7 +84,7 @@ def parse_line(self, line):
Returns:
tuple: User id, item id, rating and timestamp. The timestamp is set
to ``None`` if it does no exist.
'''
"""

line = line.split(self.sep)
try:
Expand Down
2 changes: 1 addition & 1 deletion surprise/trainset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''This module contains the Trainset class.'''
"""This module contains the Trainset class."""


from __future__ import (absolute_import, division, print_function,
Expand Down
Loading

0 comments on commit acb8646

Please sign in to comment.