• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python validation.check_is_fitted函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sklearn.utils.validation.check_is_fitted函数的典型用法代码示例。如果您正苦于以下问题:Python check_is_fitted函数的具体用法?Python check_is_fitted怎么用?Python check_is_fitted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_is_fitted函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: predict

    def predict(self, ys, paradigm, use_beta=True):
        """
        """
        check_is_fitted(self, "hrf_")
        names, onsets, durations, modulation = check_paradigm(paradigm)
        frame_times = np.arange(0, onsets.max() + self.time_offset, self.t_r)
        f_hrf = interp1d(self.hx_, self.hrf_)

        dm = make_design_matrix_hrf(frame_times, paradigm,
                                    hrf_length=self.hrf_length,
                                    t_r=self.t_r, time_offset=self.time_offset,
                                    drift_model=self.drift_model,
                                    period_cut=self.period_cut,
                                    drift_order=self.drift_order,
                                    f_hrf=f_hrf)
        # Least squares estimation
        if use_beta:
            beta_values = self.beta
        else:
            beta_values = np.linalg.pinv(dm.values).dot(ys)
        #print dm.shape
        #print beta_values.shape
        ys_fit = dm.values[:, :len(beta_values)].dot(beta_values)
        #ys -= drifts.dot(np.linalg.pinv(drifts).dot(ys))

        ress = ys - ys_fit

        return ys_fit, dm, beta_values, ress
开发者ID:eickenberg,项目名称:super-duper-octo-disco,代码行数:28,代码来源:gp.py


示例2: _check_vocabulary

    def _check_vocabulary(self):
        """Check if vocabulary is empty or missing (not fit-ed)"""
        msg = "%(name)s - Vocabulary wasn't fitted."
        check_is_fitted(self, 'vocabulary_', msg=msg),

        if len(self.vocabulary_) == 0:
            raise ValueError("Vocabulary is empty")
开发者ID:NPSDC,项目名称:Online-News-Clustering-SMAI-PROJECT-,代码行数:7,代码来源:featureExtraction.py


示例3: transform

    def transform(self, X):
        """Transform a dataframe given the fit imputer.

        Parameters
        ----------

        X : Pandas ``DataFrame``, shape=(n_samples, n_features)
            The Pandas frame to transform.

        Returns
        -------

        X : pd.DataFrame or np.ndarray
            The imputed matrix
        """

        check_is_fitted(self, 'fills_')
        # check on state of X and cols
        X, _ = validate_is_pd(X, self.cols)
        cols = self.cols if self.cols is not None else X.columns.values

        # get the fills
        modes = self.fills_

        # if it's a single int, easy:
        if isinstance(modes, int):
            X[cols] = X[cols].fillna(modes)
        else:
            # it's a dict
            for nm in cols:
                X[nm] = X[nm].fillna(modes[nm])

        return X if self.as_df else X.as_matrix()
开发者ID:tgsmith61591,项目名称:skutil,代码行数:33,代码来源:impute.py


示例4: predict

    def predict(self, X):
        """Predict if a particular sample is an outlier or not.
        Calling xgboost `predict` function.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        outlier_labels : numpy array of shape (n_samples,)
            For each observation, tells whether or not
            it should be considered as an outlier according to the
            fitted model. 0 stands for inliers and 1 for outliers.
        """

        check_is_fitted(self, ['clf_', 'decision_scores_',
                               'labels_', '_scalar'])

        X = check_array(X)

        # construct the new feature space
        X_add = self._generate_new_features(X)
        X_new = np.concatenate((X, X_add), axis=1)

        pred_scores = self.clf_.predict(X_new)
        return pred_scores.ravel()
开发者ID:flaviassantos,项目名称:pyod,代码行数:28,代码来源:xgbod.py


示例5: score

    def score(self, X, y=None):
        """Return the average log-likelihood of all samples.
        This calls sklearn.decomposition.PCA's score method
        on the specified columns [1].

        Parameters
        ----------

        X: Pandas ``DataFrame``, shape=(n_samples, n_features)
            The data to score.

        y: None
            Passthrough for pipeline/gridsearch


        Returns
        -------

        ll: float
            Average log-likelihood of the samples under the fit
            PCA model (`self.pca_`)


        References
        ----------

        .. [1] Bishop, C.  "Pattern Recognition and Machine Learning"
               12.2.1 p. 574 http://www.miketipping.com/papers/met-mppca.pdf
        """
        check_is_fitted(self, 'pca_')
        X, _ = validate_is_pd(X, self.cols)
        cols = X.columns if not self.cols else self.cols

        ll = self.pca_.score(X[cols].as_matrix(), _as_numpy(y))
        return ll
开发者ID:tgsmith61591,项目名称:skutil,代码行数:35,代码来源:decompose.py


示例6: _predict_rank

    def _predict_rank(self, X, normalized=False):
        """Predict the outlyingness rank of a sample by a fitted model. The
        method is for outlier detector score combination.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples.

        normalized : bool, optional (default=False)
            If set to True, all ranks are normalized to [0,1].

        Returns
        -------
        ranks : array, shape (n_samples,)
            Outlying rank of a sample according to the training data.

        """

        check_is_fitted(self, ['decision_scores_'])

        test_scores = self.decision_function(X)
        train_scores = self.decision_scores_

        sorted_train_scores = np.sort(train_scores)
        ranks = np.searchsorted(sorted_train_scores, test_scores)

        if normalized:
            # return normalized ranks
            ranks = ranks / ranks.max()
        return ranks
开发者ID:flaviassantos,项目名称:pyod,代码行数:31,代码来源:base.py


示例7: transform

    def transform(self, X):
        """Transform a test matrix given the already-fit transformer.

        Parameters
        ----------

        X : Pandas ``DataFrame``
            The Pandas frame to transform. The operation will
            be applied to a copy of the input data, and the result
            will be returned.


        Returns
        -------

        X : Pandas ``DataFrame``
            The operation is applied to a copy of ``X``,
            and the result set is returned.
        """
        check_is_fitted(self, 'lambda_')
        # check on state of X and cols
        X, cols = validate_is_pd(X, self.cols, assert_all_finite=True)  # creates a copy -- we need all to be finite
        cols = _cols_if_none(X, self.cols)

        lambdas_ = self.lambda_

        # do transformations
        for nm in cols:
            X[nm] = _yj_transform_y(X[nm], lambdas_[nm])

        return X if self.as_df else X.as_matrix()
开发者ID:tgsmith61591,项目名称:skutil,代码行数:31,代码来源:transform.py


示例8: decision_function

 def decision_function(self,X):
     ''' 
     Computes distance to separating hyperplane between classes. The larger 
     is the absolute value of the decision function further data point is 
     from the decision boundary.
     
     Parameters
     ----------
     X: array-like of size (n_samples_test,n_features)
        Matrix of explanatory variables
       
     Returns
     -------
     decision: numpy array of size (n_samples_test,)
        Distance to decision boundary
     '''
     check_is_fitted(self, 'coef_') 
     X = check_array(X, accept_sparse=None, dtype = np.float64)
     n_features = self.relevant_vectors_[0].shape[1]
     if X.shape[1] != n_features:
         raise ValueError("X has %d features per sample; expecting %d"
                          % (X.shape[1], n_features))
     kernel = lambda rvs : get_kernel(X,rvs,self.gamma, self.degree, 
                                      self.coef0, self.kernel, self.kernel_params)
     decision = []
     for rv,cf,act,b in zip(self.relevant_vectors_,self.coef_,self.active_,
                            self.intercept_):
         # if there are no relevant vectors => use intercept only
         if rv.shape[0] == 0:
             decision.append( np.ones(X.shape[0])*b )
         else:
             decision.append(self._decision_function_active(kernel(rv),cf,act,b))
     decision = np.asarray(decision).squeeze().T
     return decision
开发者ID:AmazaspShumik,项目名称:sklearn-bayes,代码行数:34,代码来源:fast_rvm.py


示例9: decision_function

    def decision_function(self, X):
        """Predict raw anomaly score of X using the fitted detector.

        The anomaly score of an input sample is computed based on different
        detector algorithms. For consistency, outliers are assigned with
        larger anomaly scores.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The training input samples. Sparse matrices are accepted only
            if they are supported by the base estimator.

        Returns
        -------
        anomaly_scores : numpy array of shape (n_samples,)
            The anomaly score of the input samples.
        """

        check_is_fitted(self, ['decision_scores_', 'threshold_', 'labels_'])

        # Invert outlier scores. Outliers comes with higher outlier scores
        # noinspection PyProtectedMember
        if _sklearn_version_20():
            return invert_order(self.detector_._score_samples(X))
        else:
            return invert_order(self.detector_._decision_function(X))
开发者ID:flaviassantos,项目名称:pyod,代码行数:27,代码来源:lof.py


示例10: predict

    def predict(self, X):
        """ Predict class labels for X.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape = [n_samples, n_features]
            Training vectors, where n_samples is the number of samples and
            n_features is the number of features.

        Returns
        ----------
        maj : array-like, shape = [n_samples]
            Predicted class labels.
        """

        check_is_fitted(self, 'estimators_')
        if self.voting == 'soft':
            maj = np.argmax(self.predict_proba(X), axis=1)

        else:  # 'hard' voting
            predictions = self._predict(X)
            maj = np.apply_along_axis(lambda x:
                                      np.argmax(np.bincount(x,
                                                weights=self.weights)),
                                      axis=1,
                                      arr=predictions.astype('int'))

        maj = self.le_.inverse_transform(maj)

        return maj
开发者ID:daniaki,项目名称:ppi_wrangler,代码行数:30,代码来源:learning.py


示例11: sample

    def sample(self, X, y):
        """Resample the dataset.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape (n_samples, n_features)
            Matrix containing the data which have to be sampled.

        y : array-like, shape (n_samples,)
            Corresponding label for each sample in X.

        Returns
        -------
        X_resampled : {ndarray, sparse matrix}, shape \
(n_samples_new, n_features)
            The array containing the resampled data.

        y_resampled : ndarray, shape (n_samples_new)
            The corresponding label of `X_resampled`

        """

        # Check the consistency of X and y
        X, y = check_X_y(X, y, accept_sparse=['csr', 'csc'])

        check_is_fitted(self, 'ratio_')
        self._check_X_y(X, y)

        return self._sample(X, y)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:29,代码来源:base.py


示例12: decision_function

    def decision_function(self, X):
        """Compute the decision function of ``X``.

        Parameters
        ----------
        X : array-like of shape = [n_samples, n_features]
            The input samples.

        Returns
        -------
        score : array, shape = [n_samples, k]
            The decision function of the input samples. The order of
            outputs is the same of that of the `classes_` attribute.
            Binary classification is a special cases with ``k == 1``,
            otherwise ``k==n_classes``. For binary classification,
            values closer to -1 or 1 mean more like the first or second
            class in ``classes_``, respectively.
        """
        check_is_fitted(self, "n_classes_")
        X = np.asarray(X)

        pred = None

        for estimator in self.estimators_:
            # The weights are all 1. for LogitBoost
            current_pred = estimator.predict(X)

            if pred is None:
                pred = current_pred
            else:
                pred += current_pred

        return pred
开发者ID:hbldh,项目名称:skboost,代码行数:33,代码来源:logitboost.py


示例13: decision_function

    def decision_function(self, X):
        """Predict raw anomaly score of X using the fitted detector.

        The anomaly score of an input sample is computed based on different
        detector algorithms. For consistency, outliers are assigned with
        larger anomaly scores.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The training input samples. Sparse matrices are accepted only
            if they are supported by the base estimator.

        Returns
        -------
        anomaly_scores : numpy array of shape (n_samples,)
            The anomaly score of the input samples.
        """
        check_is_fitted(self, ['model_', 'history_'])
        X = check_array(X)

        if self.preprocessing:
            X_norm = self.scaler_.transform(X)
        else:
            X_norm = np.copy(X)

        # Predict on X and return the reconstruction errors
        pred_scores = self.model_.predict(X_norm)
        return pairwise_distances_no_broadcast(X_norm, pred_scores)
开发者ID:flaviassantos,项目名称:pyod,代码行数:29,代码来源:auto_encoder.py


示例14: predict_proba

    def predict_proba(self, X):
        """Predict probability for each possible outcome.

        Compute the probability estimates for each single sample in X
        and each possible outcome seen during training (categorical
        distribution).

        Parameters
        ----------
        X : array_like, shape = [n_samples, n_features]

        Returns
        -------
        probabilities : array, shape = [n_samples, n_classes]
            Normalized probability distributions across
            class labels
        """
        check_is_fitted(self, 'X_')

        X_2d = check_array(X, accept_sparse = ['csc', 'csr', 'coo', 'dok',
                        'bsr', 'lil', 'dia'])
        weight_matrices = self._get_kernel(self.X_, X_2d)
        if self.kernel == 'knn':
            probabilities = []
            for weight_matrix in weight_matrices:
                ine = np.sum(self.label_distributions_[weight_matrix], axis=0)
                probabilities.append(ine)
            probabilities = np.array(probabilities)
        else:
            weight_matrices = weight_matrices.T
            probabilities = np.dot(weight_matrices, self.label_distributions_)
        normalizer = np.atleast_2d(np.sum(probabilities, axis=1)).T
        probabilities /= normalizer
        return probabilities
开发者ID:musically-ut,项目名称:semi_supervised,代码行数:34,代码来源:label_propagation.py


示例15: _kernel_decision_function

 def _kernel_decision_function(self,X):
     ''' Computes kernel and decision function based on kernel'''
     check_is_fitted(self,'coef_')
     X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
     K = get_kernel( X, self.relevant_vectors_, self.gamma, self.degree, 
                     self.coef0, self.kernel, self.kernel_params)
     return K , np.dot(K,self.coef_[self.active_]) + self.intercept_
开发者ID:AmazaspShumik,项目名称:sklearn-bayes,代码行数:7,代码来源:fast_rvm.py


示例16: score

    def score(self, frame):
        """Predict and score on a new frame. Note that this method
        will not store performance metrics in the report that ``report_score``
        generates.

        Parameters
        ----------

        frame : H2OFrame, shape=(n_samples, n_features)
            The test frame on which to predict and score performance.

        Returns
        -------

        scor : float
            The score on the testing frame
        """
        check_is_fitted(self, 'best_estimator_')
        e, l, p = self.extra_names_['expo'], self.extra_names_['loss'], self.extra_names_['prem']

        kwargs = {
            'expo': frame[e],
            'loss': frame[l],
            'prem': frame[p] if p is not None else None
        }

        y_truth = frame[self.target_feature]
        pred = self.best_estimator_.predict(frame)['predict']
        scor = self.scoring_class_.score_no_store(y_truth, pred, **kwargs)

        return scor
开发者ID:tgsmith61591,项目名称:skutil,代码行数:31,代码来源:grid_search.py


示例17: transform

    def transform(self, X, y=None, copy=None):
        """Perform standardization by centering and scaling

        Parameters
        ----------
        X : array-like with shape [n_samples, n_features]
            The data used to scale along the features axis.
        """
        check_is_fitted(self, 'std_')

        copy = copy if copy is not None else self.copy
        X = check_array(X, copy=copy, accept_sparse="csc", ensure_2d=False)
        if warn_if_not_float(X, estimator=self):
            X = X.astype(np.float)
        if sparse.issparse(X):
            if self.center_sparse:
                for i in range(X.shape[1]):
                    X.data[X.indptr[i]:X.indptr[i + 1]] -= self.mean_[i]

            elif self.with_mean:
                raise ValueError(
                    "Cannot center sparse matrices: pass `with_mean=False` "
                    "instead. See docstring for motivation and alternatives.")

            else:
                pass

            if self.std_ is not None:
                inplace_column_scale(X, 1 / self.std_)
        else:
            if self.with_mean:
                X -= self.mean_
            if self.with_std:
                X /= self.std_
        return X
开发者ID:Ayaro,项目名称:auto-sklearn,代码行数:35,代码来源:StandardScaler.py


示例18: inverse_transform

    def inverse_transform(self, X, copy=None):
        """Scale back the data to the original representation

        Parameters
        ----------
        X : array-like with shape [n_samples, n_features]
            The data used to scale along the features axis.
        """
        check_is_fitted(self, 'std_')

        copy = copy if copy is not None else self.copy
        if sparse.issparse(X):
            if self.with_mean:
                raise ValueError(
                    "Cannot uncenter sparse matrices: pass `with_mean=False` "
                    "instead See docstring for motivation and alternatives.")
            if not sparse.isspmatrix_csr(X):
                X = X.tocsr()
                copy = False
            if copy:
                X = X.copy()
            if self.std_ is not None:
                inplace_column_scale(X, self.std_)
        else:
            X = np.asarray(X)
            if copy:
                X = X.copy()
            if self.with_std:
                X *= self.std_
            if self.with_mean:
                X += self.mean_
        return X
开发者ID:Ayaro,项目名称:auto-sklearn,代码行数:32,代码来源:StandardScaler.py


示例19: transform

    def transform(self, X):
        """ A reference implementation of a transform function.

        Parameters
        ----------
        X : array-like of shape = [n_samples, n_features]
            The input samples.

        Returns
        -------
        X_transformed : array of int of shape = [n_samples, n_features]
            The array containing the element-wise square roots of the values
            in `X`
        """
        # Check is fit had been called
        check_is_fitted(self, ['input_shape_'])

        # Input validation
        X = check_array(X)

        # Check that the input is of the same shape as the one passed
        # during fit.
        if X.shape != self.input_shape_:
            raise ValueError('Shape of input is different from what was seen'
                             'in `fit`')
        return np.sqrt(X)
开发者ID:I2Cvb,项目名称:simblefaron,代码行数:26,代码来源:simblefaron.py


示例20: pairwise_kernel

    def pairwise_kernel(self, X, Y):
        """Function to use with :func:`sklearn.metrics.pairwise.pairwise_kernels`

        Parameters
        ----------
        X : array, shape = [n_features]

        Y : array, shape = [n_features]

        Returns
        -------
        similarity : float
            Similarities are normalized to be within [0, 1]
        """
        check_is_fitted(self, 'X_fit_')
        if X.shape[0] != Y.shape[0]:
            raise ValueError('X and Y have different number of features')

        val = pairwise_continuous_ordinal_kernel(X[self._numeric_columns], Y[self._numeric_columns],
                                                 self._numeric_ranges)
        if len(self._nominal_columns) > 0:
            val += pairwise_nominal_kernel(X[self._nominal_columns].astype(numpy.int8),
                                           Y[self._nominal_columns].astype(numpy.int8))

        val /= X.shape[0]

        return val
开发者ID:tum-camp,项目名称:survival-support-vector-machine,代码行数:27,代码来源:clinical.py



注:本文中的sklearn.utils.validation.check_is_fitted函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python validation.check_random_state函数代码示例发布时间:2022-05-27
下一篇:
Python validation.check_consistent_length函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap