Python sklearn.base 模块-is_classifier() 实例源码

Python sklearn.base 模块,is_classifier() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用sklearn.base.is_classifier()

项目:palladio    作者:slipguru    | 项目源码 | 文件源码
def _grid_search(self, train_X, train_y):
        if callable(self.inner_cv):
            # inner_cv = self.inner_cv(train_X,train_y)
            inner_cv = self.inner_cv.split(train_X, train_y)
        else:
            # inner_cv = _check_cv(self.inner_cv,train_X,train_y,
            #                      classifier=is_classifier(self.estimator))
            inner_cv = _check_cv(self.inner_cv, train_y,
                                 classifier=is_classifier(
                                    self.estimator)).split(train_X, train_y)

        master = MPIGridSearchCVMaster(self.param_grid, inner_cv,
                                       self.estimator, self.scorer_,
                                       self.fit_params)
        return master.run(train_X, train_y)
项目:palladio    作者:slipguru    | 项目源码 | 文件源码
def fit(self, X, y):
        """Fit the model to the training data."""
        X, y = check_X_y(X, y, force_all_finite=False,
                         multi_output=self.multi_output)
        _check_param_grid(self.param_grid)

        # cv = _check_cv(self.cv,X,y,classifier=is_classifier(self.estimator))
        cv = _check_cv(self.cv, classifier=is_classifier(self.estimator))

        self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)

        if comm_rank == 0:
            self._fit_master(X, cv)
        else:
            self._fit_slave()

        return self
项目:mriqc    作者:poldracklab    | 项目源码 | 文件源码
def cross_val_score(estimator, y=None, groups=None, scoring=None, cv=None,
                    n_jobs=1, verbose=0, fit_params=None,
                    pre_dispatch='2*n_jobs'):
    """
    Evaluate a score by cross-validation
    """
    if not isinstance(scoring, (list, tuple)):
        scoring = [scoring]

    X, groups = indexable(X, groups)

    cv = check_cv(cv, classifier=is_classifier(estimator))
    splits = list(cv.split(X, groups))
    scorer = [check_scoring(estimator, scoring=s) for s in scoring]
    # We clone the estimator to make sure that all the folds are
    # independent,and that it is pickle-able.
    parallel = Parallel(n_jobs=n_jobs, verbose=verbose,
                        pre_dispatch=pre_dispatch)
    scores = parallel(delayed(_fit_and_score)(clone(estimator), scorer,
                                              train, test, verbose, None,
                                              fit_params)
                      for train, test in splits)

    group_order = []
    if hasattr(cv, 'groups'):
        group_order = [np.array(cv.groups)[test].tolist()[0] for _, test in splits]
    return np.squeeze(np.array(scores)), group_order
项目:mriqc    作者:poldracklab    | 项目源码 | 文件源码
def permutation_test_score(estimator,
                           n_permutations=100, n_jobs=1, random_state=0,
                           verbose=0, scoring=None):
    """
    Evaluate the significance of a cross-validated score with permutations,
    as in test 1 of [Ojala2010]_.

    A modification of original sklearn's permutation test score function
    to evaluate p-value outside this function,so that the score can be
    reused from outside.


    .. [Ojala2010] Ojala and Garriga. Permutation Tests for Studying Classifier
                   Performance.  The Journal of Machine Learning Research (2010)
                   vol. 11

    """
    X, classifier=is_classifier(estimator))
    scorer = check_scoring(estimator, scoring=scoring)
    random_state = check_random_state(random_state)

    # We clone the estimator to make sure that all the folds are
    # independent,and that it is pickle-able.
    permutation_scores = Parallel(n_jobs=n_jobs, verbose=verbose)(
        delayed(_permutation_test_score)(
            clone(estimator), _shuffle(y, groups, random_state),
            groups, cv, scorer)
        for _ in range(n_permutations))
    permutation_scores = np.array(permutation_scores)
    return permutation_scores
项目:decoding_challenge_cortana_2016_3rd    作者:kingjr    | 项目源码 | 文件源码
def _set_cv(cv, clf=None, X=None, y=None):
    from sklearn.base import is_classifier

    # Set the default cross-validation depending on whether clf is classifier
    # or regressor.
    if check_version('sklearn', '0.18'):
        from sklearn.model_selection import (check_cv, StratifiedKFold, KFold)
        if isinstance(cv, (int, np.int)):
            XFold = StratifiedKFold if is_classifier(clf) else KFold
            cv = XFold(n_folds=cv)
        cv = check_cv(cv=cv, y=y, classifier=is_classifier(clf))
    else:
        from sklearn.cross_validation import (check_cv, np.int)):
            if is_classifier(clf):
                cv = StratifiedKFold(y=y, n_folds=cv)
            else:
                cv = KFold(n=len(y), n_folds=cv)
        cv = check_cv(cv=cv, X=X, classifier=is_classifier(clf))

    # Extract train and test set to retrieve them at predict time
    if hasattr(cv, 'split'):
        cv_splits = [(train, test) for train, test in
                     cv.split(X=np.zeros_like(y), y=y)]
    else:
        # XXX support sklearn.cross_validation cv
        cv_splits = [(train, test in cv]

    if not np.all([len(train) for train, _ in cv_splits]):
        raise ValueError('Some folds do not have any train epochs.')

    return cv, cv_splits
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def test_is_classifier():
    svc = SVC()
    assert_true(is_classifier(svc))
    assert_true(is_classifier(GridSearchCV(svc, {'C': [0.1, 1]})))
    assert_true(is_classifier(Pipeline([('svc', svc)])))
    assert_true(is_classifier(Pipeline([('svc_cv',
                              GridSearchCV(svc, 1]}))])))
项目:CerebralCortex-2.0-legacy    作者:MD2Korg    | 项目源码 | 文件源码
def fit(self, y):
        """Actual fitting,performing the search over parameters."""

        parameter_iterable = ParameterGrid(self.param_grid)

        estimator = self.estimator
        cv = self.cv

        n_samples = _num_samples(X)
        X, y = indexable(X, y)

        if y is not None:
            if len(y) != n_samples:
                raise ValueError('Target variable (y) has a different number '
                                 'of samples (%i) than data (X: %i samples)'
                                 % (len(y), n_samples))
        cv = check_cv(cv, classifier=is_classifier(estimator))

        if self.verbose > 0:
            if isinstance(parameter_iterable, Sized):
                n_candidates = len(parameter_iterable)
                print("Fitting {0} folds for each of {1} candidates,totalling"
                      " {2} fits".format(len(cv), n_candidates,
                                         n_candidates * len(cv)))

        base_estimator = clone(self.estimator)

        pre_dispatch = self.pre_dispatch

        out = Parallel(
            n_jobs=self.n_jobs, verbose=self.verbose,
            pre_dispatch=pre_dispatch
        )(delayed(cv_fit_and_score)(clone(base_estimator), self.scoring,
                                      parameters, cv=cv)
            for parameters in parameter_iterable)

        best = sorted(out, key=lambda x: x[0])[-1]
        self.best_params_ = best[1]
        self.best_score_ = best[0]

        if self.refit:
            # fit the best estimator using the entire dataset
            # clone first to work around broken estimators
            best_estimator = clone(base_estimator).set_params(
                **best[1])
            if y is not None:
                best_estimator.fit(X, **self.fit_params)
            else:
                best_estimator.fit(X, **self.fit_params)
            self.best_estimator_ = best_estimator

        return self
项目:CerebralCortex-2.0-legacy    作者:MD2Korg    | 项目源码 | 文件源码
def fit(self,performing the search over parameters."""

        parameter_iterable = ParameterSampler(self.param_distributions,
                                              self.n_iter,
                                              random_state=self.random_state)
        estimator = self.estimator
        cv = self.cv

        n_samples = _num_samples(X)
        X,
            pre_dispatch=pre_dispatch
        )(
            delayed(cv_fit_and_score)(clone(base_estimator), reverse=True)[0]
        self.best_params_ = best[1]
        self.best_score_ = best[0]

        if self.refit:
            # fit the best estimator using the entire dataset
            # clone first to work around broken estimators
            best_estimator = clone(base_estimator).set_params(
                **best[1])
            if y is not None:
                best_estimator.fit(X, **self.fit_params)
            self.best_estimator_ = best_estimator

        return self

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Python ftplib 模块,error_proto() 实例源码 我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用ftplib.error_proto()。
Python ftplib 模块,Error() 实例源码 我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用ftplib.Error()。
Python ftplib 模块,error_reply() 实例源码 我们从Python开源项目中,提取了以下36个代码示例,用于说明如何使用ftplib.error_reply()。
Python ftplib 模块,error_temp() 实例源码 我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用ftplib.error_temp()。
Python ftplib 模块,FTP_TLS 实例源码 我们从Python开源项目中,提取了以下42个代码示例,用于说明如何使用ftplib.FTP_TLS。
Python ftplib 模块,FTP_PORT 实例源码 我们从Python开源项目中,提取了以下42个代码示例,用于说明如何使用ftplib.FTP_PORT。
Python ftplib 模块,all_errors() 实例源码 我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ftplib.all_errors()。
Python ftplib 模块,error_perm() 实例源码 我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用ftplib.error_perm()。
Python ftplib 模块,FTP 实例源码 我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ftplib.FTP。
Python sklearn.base 模块,is_classifier() 实例源码 我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用sklearn.base.is_classifier()。
Python sklearn.base 模块,ClusterMixin() 实例源码 我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用sklearn.base.ClusterMixin()。
Python sklearn.base 模块,RegressorMixin() 实例源码 我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用sklearn.base.RegressorMixin()。
Python sklearn.base 模块,clone() 实例源码 我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sklearn.base.clone()。
Python sklearn.base 模块,ClassifierMixin() 实例源码 我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用sklearn.base.ClassifierMixin()。
Python sklearn.base 模块,TransformerMixin() 实例源码 我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用sklearn.base.TransformerMixin()。
Python sklearn.base 模块,BaseEstimator() 实例源码 我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用sklearn.base.BaseEstimator()。
Python colorama.Fore 模块,LIGHTCYAN_EX 实例源码 我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用colorama.Fore.LIGHTCYAN_EX。
Python colorama.Fore 模块,LIGHTMAGENTA_EX 实例源码 我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用colorama.Fore.LIGHTMAGENTA_EX。
Python colorama.Fore 模块,LIGHTBLUE_EX 实例源码 我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用colorama.Fore.LIGHTBLUE_EX。
Python colorama.Fore 模块,LIGHTWHITE_EX 实例源码 我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用colorama.Fore.LIGHTWHITE_EX。