# Path: splearn/base.py
# class SparkBaseEstimator(BaseEstimator):
#     pass
# 
# Path: splearn/cross_validation.py
# def _check_cv(cv, Z=None):
#     # This exists for internal use while indices is being deprecated.
#     if cv is None:
#         cv = 3
#     if isinstance(cv, numbers.Integral):
#         n_samples = Z.count()
#         try:
#             # scikit-learn version under 0.17
#             cv = KFold(n_samples, cv, indices=True)
#         except:
#             cv = KFold(n_samples, cv)
#     if not getattr(cv, "_indices", True):
#         raise ValueError("Sparse data and lists require indices-based cross"
#                          " validation generator, got: %r", cv)
#     return cv
# 
# def _fit_and_score(estimator, Z, scorer, train, test, verbose,
#                    parameters, fit_params, return_train_score=False,
#                    return_parameters=False, error_score='raise'):
# 
#     if verbose > 1:
#         if parameters is None:
#             msg = "no parameters to be set"
#         else:
#             msg = '%s' % (', '.join('%s=%s' % (k, v)
#                                     for k, v in list(parameters.items())))
#         print(("[CV] %s %s" % (msg, (64 - len(msg)) * '.')))
# 
#     fit_params = fit_params if fit_params is not None else {}
# 
#     if parameters is not None:
#         estimator.set_params(**parameters)
# 
#     start_time = time.time()
# 
#     Z_train = Z[train]
#     Z_test = Z[test]
# 
#     try:
#         estimator.fit(Z_train, **fit_params)
#     except Exception as e:
#         if error_score == 'raise':
#             raise
#         elif isinstance(error_score, numbers.Number):
#             test_score = error_score
#             if return_train_score:
#                 train_score = error_score
#             warnings.warn("Classifier fit failed. The score on this train-test"
#                           " partition for these parameters will be set to %f. "
#                           "Details: \n%r" % (error_score, e), FitFailedWarning)
#         else:
#             raise ValueError("error_score must be the string 'raise' or a"
#                              " numeric value. (Hint: if using 'raise', please"
#                              " make sure that it has been spelled correctly.)"
#                              )
#     else:
#         test_score = _score(estimator, Z_test, scorer)
#         if return_train_score:
#             train_score = _score(estimator, Z_train, scorer)
# 
#     scoring_time = time.time() - start_time
# 
#     if verbose > 2:
#         msg += ", score=%f" % test_score
#     if verbose > 1:
#         end_msg = "%s -%s" % (msg, logger.short_format_time(scoring_time))
#         print(("[CV] %s %s" % ((64 - len(end_msg)) * '.', end_msg)))
# 
#     ret = [train_score] if return_train_score else []
#     ret.extend([test_score, _num_samples(Z_test), scoring_time])
#     if return_parameters:
#         ret.append(parameters)
#     return ret


from collections import Sized
from sklearn.base import clone
from sklearn.externals.joblib import Parallel, delayed
from sklearn.grid_search import GridSearchCV, ParameterGrid, _CVScoreTuple
from sklearn.metrics.scorer import check_scoring
from splearn.base import SparkBaseEstimator
from splearn.cross_validation import _check_cv, _fit_and_score
import numpy as np
# -*- coding: utf-8 -*-





class SparkGridSearchCV(GridSearchCV, SparkBaseEstimator):

    def _fit(self, Z, parameter_iterable):
        """Actual fitting,  performing the search over parameters."""
        self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)

        cv = self.cv

# Path: splearn/base.py
# class SparkBaseEstimator(BaseEstimator):
#     pass
# 
# Path: splearn/cross_validation.py
# def _check_cv(cv, Z=None):
#     # This exists for internal use while indices is being deprecated.
#     if cv is None:
#         cv = 3
#     if isinstance(cv, numbers.Integral):
#         n_samples = Z.count()
#         try:
#             # scikit-learn version under 0.17
#             cv = KFold(n_samples, cv, indices=True)
#         except:
#             cv = KFold(n_samples, cv)
#     if not getattr(cv, "_indices", True):
#         raise ValueError("Sparse data and lists require indices-based cross"
#                          " validation generator, got: %r", cv)
#     return cv
# 
# def _fit_and_score(estimator, Z, scorer, train, test, verbose,
#                    parameters, fit_params, return_train_score=False,
#                    return_parameters=False, error_score='raise'):
# 
#     if verbose > 1:
#         if parameters is None:
#             msg = "no parameters to be set"
#         else:
#             msg = '%s' % (', '.join('%s=%s' % (k, v)
#                                     for k, v in list(parameters.items())))
#         print(("[CV] %s %s" % (msg, (64 - len(msg)) * '.')))
# 
#     fit_params = fit_params if fit_params is not None else {}
# 
#     if parameters is not None:
#         estimator.set_params(**parameters)
# 
#     start_time = time.time()
# 
#     Z_train = Z[train]
#     Z_test = Z[test]
# 
#     try:
#         estimator.fit(Z_train, **fit_params)
#     except Exception as e:
#         if error_score == 'raise':
#             raise
#         elif isinstance(error_score, numbers.Number):
#             test_score = error_score
#             if return_train_score:
#                 train_score = error_score
#             warnings.warn("Classifier fit failed. The score on this train-test"
#                           " partition for these parameters will be set to %f. "
#                           "Details: \n%r" % (error_score, e), FitFailedWarning)
#         else:
#             raise ValueError("error_score must be the string 'raise' or a"
#                              " numeric value. (Hint: if using 'raise', please"
#                              " make sure that it has been spelled correctly.)"
#                              )
#     else:
#         test_score = _score(estimator, Z_test, scorer)
#         if return_train_score:
#             train_score = _score(estimator, Z_train, scorer)
# 
#     scoring_time = time.time() - start_time
# 
#     if verbose > 2:
#         msg += ", score=%f" % test_score
#     if verbose > 1:
#         end_msg = "%s -%s" % (msg, logger.short_format_time(scoring_time))
#         print(("[CV] %s %s" % ((64 - len(end_msg)) * '.', end_msg)))
# 
#     ret = [train_score] if return_train_score else []
#     ret.extend([test_score, _num_samples(Z_test), scoring_time])
#     if return_parameters:
#         ret.append(parameters)
#     return ret


# Path: splearn/grid_search.py
from collections import Sized
from sklearn.base import clone
from sklearn.externals.joblib import Parallel, delayed
from sklearn.grid_search import GridSearchCV, ParameterGrid, _CVScoreTuple
from sklearn.metrics.scorer import check_scoring
from splearn.base import SparkBaseEstimator
from splearn.cross_validation import _check_cv, _fit_and_score
import numpy as np

# -*- coding: utf-8 -*-





class SparkGridSearchCV(GridSearchCV, SparkBaseEstimator):

    def _fit(self, Z, parameter_iterable):
        """Actual fitting,  performing the search over parameters."""
        self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)

        cv = self.cv

        cv = _check_cv(cv, Z)