当前位置: 首页>>代码示例>>Python>>正文


Python validation.check_array方法代码示例

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


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

示例1: _joint_log_likelihood

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def _joint_log_likelihood(self, X):
        """Calculate the posterior log probability of the samples X"""
        check_is_fitted(self, "classes_")

        X = check_array(X, accept_sparse='csr')
        X_bin = self._transform_data(X)

        n_classes, n_features = self.feature_log_prob_.shape
        n_samples, n_features_X = X_bin.shape

        if n_features_X != n_features:
            raise ValueError(
                "Expected input with %d features, got %d instead" %
                (n_features, n_features_X))

        # see chapter 4.1 of http://www.cs.columbia.edu/~mcollins/em.pdf
        # implementation as in Formula 4.
        jll = safe_sparse_dot(X_bin, self.feature_log_prob_.T)
        jll += self.class_log_prior_

        return jll 
开发者ID:J535D165,项目名称:recordlinkage,代码行数:23,代码来源:nb_sklearn.py

示例2: from_array

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def from_array(X, column_names=None):
    """A simple wrapper for H2OFrame.from_python. This takes a
    numpy array (or 2d array) and returns an H2OFrame with all 
    the default args.

    Parameters
    ----------

    X : ndarray
        The array to convert.

    column_names : list, tuple (default=None)
        the names to use for your columns

    Returns
    -------

    H2OFrame
    """
    X = check_array(X, force_all_finite=False)
    return from_pandas(pd.DataFrame.from_records(data=X, columns=column_names)) 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:23,代码来源:util.py

示例3: _diff_inv_matrix

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def _diff_inv_matrix(x, lag, differences, xi):
    n, m = x.shape
    y = np.zeros((n + lag * differences, m), dtype=DTYPE)

    if m >= 1:  # todo: R checks this. do we need to?
        # R: if(missing(xi)) xi <- matrix(0.0, lag*differences, m)
        if xi is None:
            xi = np.zeros((lag * differences, m), dtype=DTYPE)
        else:
            xi = check_array(
                xi, dtype=DTYPE, copy=False, force_all_finite=False,
                ensure_2d=True)
            if xi.shape != (lag * differences, m):
                raise IndexError('"xi" does not have the right shape')

        # TODO: can we vectorize?
        for i in range(m):
            y[:, i] = _diff_inv_vector(x[:, i], lag, differences, xi[:, i])

    return y 
开发者ID:alkaline-ml,项目名称:pmdarima,代码行数:22,代码来源:array.py

示例4: _seasonal_prediction_with_confidence

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def _seasonal_prediction_with_confidence(arima_res, start, end, exog, alpha,
                                         **kwargs):
    """Compute the prediction for a SARIMAX and get a conf interval

    Unfortunately, SARIMAX does not really provide a nice way to get the
    confidence intervals out of the box, so we have to perform the
    ``get_prediction`` code here and unpack the confidence intervals manually.

    Notes
    -----
    For internal use only.
    """
    results = arima_res.get_prediction(
        start=start,
        end=end,
        exog=exog,
        **kwargs)

    f = results.predicted_mean
    conf_int = results.conf_int(alpha=alpha)
    return check_endog(f, dtype=None, copy=False), \
        check_array(conf_int, copy=False, dtype=None) 
开发者ID:alkaline-ml,项目名称:pmdarima,代码行数:24,代码来源:arima.py

示例5: fit

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def fit(self, X, y_orig):

        def as_factory(r):
            return r if isinstance(r, AggregationRuleFactory) else DummyAggregationRuleFactory(r)

        self.aggregation_rules__ = [ as_factory(r) for r in self.aggregation_rules ]
        
        X = check_array(X)

        self.classes_, _ = np.unique(y_orig, return_inverse=True)
        self.m = X.shape[1]

        if np.nan in self.classes_:
            raise Exception("nan not supported for class values")

        self.build_with_ga(X, y_orig)

        return self 
开发者ID:sorend,项目名称:fylearn,代码行数:20,代码来源:fpcga.py

示例6: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def predict(self, X):
        """

        Predict outputs given examples.

        Parameters:
        -----------

        X : the examples to predict (array or matrix)

        Returns:
        --------

        y_pred : Predicted values for each row in matrix.

        """
        if self.protos_ is None:
            raise Exception("Prototypes not initialized. Perform a fit first.")

        X = check_array(X)

        # predict
        return _predict(self.protos_, self.aggregation, self.classes_, X) 
开发者ID:sorend,项目名称:fylearn,代码行数:25,代码来源:fpcga.py

示例7: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def predict(self, X):
        """

        Predict outputs given examples.

        Parameters:
        -----------

        X : the examples to predict (array or matrix)

        Returns:
        --------

        y_pred : Predicted values for each row in matrix.

        """
        if self.protos_ is None:
            raise Exception("Prototypes not initialized. Perform a fit first.")

        X = check_array(X)

        # predict
        return _predict_multi(self.protos_, self.aggregation, self.classes_, X, self.n_features) 
开发者ID:sorend,项目名称:fylearn,代码行数:25,代码来源:rafpc.py

示例8: fit

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def fit(self, X, y):
        X = check_array(X)

        self.classes_, _ = np.unique(y, return_inverse=True)

        # construct distance measure
        self.distance_ = self.df(X)

        # build models
        models = np.zeros((len(self.classes_), X.shape[1]))
        for c_idx, c_value in enumerate(self.classes_):
            models[c_idx, :] = self.build_for_class(X[y == c_value])

        self.models_ = models

        return self 
开发者ID:sorend,项目名称:fylearn,代码行数:18,代码来源:garules.py

示例9: fit

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def fit(self, X, y):

        X = check_array(X)

        self.classes_, y = np.unique(y, return_inverse=True)

        if "?" in tuple(self.classes_):
            raise ValueError("nan not supported for class values")

        # build membership functions for each feature for each class
        self.protos_ = [
            build_memberships(X, y == idx, self.membership_factory)
            for idx, class_value in enumerate(self.classes_)
        ]

        # build aggregation
        self.aggregation_ = self.aggregation_factory(self.protos_, X, y, self.classes_)

        return self 
开发者ID:sorend,项目名称:fylearn,代码行数:21,代码来源:nfpc.py

示例10: fit

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def fit(self, X, y):

        X = check_array(X)

        self.classes_, y = np.unique(y, return_inverse=True)

        if np.nan in self.classes_:
            raise Exception("nan not supported for class values")

        self.trees_ = {}

        # build membership functions
        P = []
        for feature_idx, feature in enumerate(X.T):
            P.extend(self.fuzzifier(feature_idx, feature))

        # build the pattern tree for each class
        for class_idx, class_value in enumerate(self.classes_):
            class_vector = np.zeros(len(y))
            class_vector[y == class_idx] = 1.0
            root = self.build_for_class(X, y, class_vector, list(P))
            self.trees_[class_idx] = root

        return self 
开发者ID:sorend,项目名称:fylearn,代码行数:26,代码来源:fpt.py

示例11: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def predict(self, X):
        """Predict class for X.

        Parameters
        ----------
        X : Array-like of shape [n_samples, n_features]
            The input to classify.

        Returns
        -------
        y : array of shape = [n_samples]
            The predicted classes.
        """

        X = check_array(X)

        if self.trees_ is None:
            raise Exception("Pattern trees not initialized. Perform a fit first.")

        y_classes = np.zeros((X.shape[0], len(self.classes_)))
        for i, c in enumerate(self.classes_):
            y_classes[:, i] = self.trees_[i](X)

        # predict the maximum value
        return self.classes_.take(np.argmax(y_classes, -1)) 
开发者ID:sorend,项目名称:fylearn,代码行数:27,代码来源:fpt.py

示例12: decision_function

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
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_'])
        X = check_array(X)

        # Computer mahalanobis distance of the samples
        return self.detector_.mahalanobis(X) 
开发者ID:yzhao062,项目名称:pyod,代码行数:25,代码来源:mcd.py

示例13: transform

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def transform(self, X):
        check_is_fitted(self, ['statistics_', 'estimators_', 'gamma_'])
        X = check_array(X, copy=True, dtype=np.float64, force_all_finite=False)
        if X.shape[1] != self.statistics_.shape[1]:
            raise ValueError("X has %d features per sample, expected %d"
                             % (X.shape[1], self.statistics_.shape[1]))

        X_nan = np.isnan(X)
        imputed = self.initial_imputer.transform(X)

        if len(self.estimators_) > 1:
            for i, estimator_ in enumerate(self.estimators_):
                X_s = np.delete(imputed, i, 1)
                y_nan = X_nan[:, i]

                X_unk = X_s[y_nan]
                if len(X_unk) > 0:
                    X[y_nan, i] = estimator_.predict(X_unk)

        else:
            estimator_ = self.estimators_[0]
            X[X_nan] = estimator_.inverse_transform(estimator_.transform(imputed))[X_nan]

        return X 
开发者ID:log0ymxm,项目名称:predictive_imputer,代码行数:26,代码来源:predictive_imputer.py

示例14: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def predict(self, X):
        """Applies learned event segmentation to new testing dataset

        Alternative function for segmenting a new dataset after using
        fit() to learn a sequence of events, to comply with the sklearn
        Classifier interface

        Parameters
        ----------
        X: timepoint by voxel ndarray
            fMRI data to segment based on previously-learned event patterns

        Returns
        -------
        Event label for each timepoint
        """
        check_is_fitted(self, ["event_pat_", "event_var_"])
        X = check_array(X)
        segments, test_ll = self.find_events(X)
        return np.argmax(segments, axis=1) 
开发者ID:brainiak,项目名称:brainiak,代码行数:22,代码来源:event.py

示例15: fit

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import check_array [as 别名]
def fit(self, X, y=None):
        """Compute the lower and upper quantile cutoffs, columns to transform, and nonnegative columns.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data array to transform. Must be numeric, non-sparse, and two-dimensional.

        Returns
        -------
        self : LogExtremeValueTransformer
        """
        super().fit(X)
        X = check_array(X)
        self.nonnegative_cols_ = [j for j in range(self.n_input_features_) if np.all(X[:, j] >= 0)]
        return self 
开发者ID:aws,项目名称:sagemaker-scikit-learn-extension,代码行数:18,代码来源:base.py


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