當前位置: 首頁>>代碼示例>>Python>>正文


Python base.ClusterMixin方法代碼示例

本文整理匯總了Python中sklearn.base.ClusterMixin方法的典型用法代碼示例。如果您正苦於以下問題:Python base.ClusterMixin方法的具體用法?Python base.ClusterMixin怎麽用?Python base.ClusterMixin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.base的用法示例。


在下文中一共展示了base.ClusterMixin方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _generate_bases_test

# 需要導入模塊: from sklearn import base [as 別名]
# 或者: from sklearn.base import ClusterMixin [as 別名]
def _generate_bases_test(est, pd_est):
    def test(self):
        self.assertTrue(isinstance(pd_est, FrameMixin), pd_est)
        self.assertFalse(isinstance(est, FrameMixin))
        self.assertTrue(isinstance(pd_est, base.BaseEstimator))
        try:
            mixins = [
                base.ClassifierMixin,
                base.ClusterMixin,
                base.BiclusterMixin,
                base.TransformerMixin,
                base.DensityMixin,
                base.MetaEstimatorMixin,
                base.ClassifierMixin,
                base.RegressorMixin]
        except:
            if _sklearn_ver > 17:
                raise
            mixins = [
                base.ClassifierMixin,
                base.ClusterMixin,
                base.BiclusterMixin,
                base.TransformerMixin,
                base.MetaEstimatorMixin,
                base.ClassifierMixin,
                base.RegressorMixin]
        for mixin in mixins:
            self.assertEqual(
                isinstance(pd_est, mixin),
                isinstance(est, mixin),
                mixin)

    return test 
開發者ID:atavory,項目名稱:ibex,代碼行數:35,代碼來源:_test.py

示例2: run_silhouette_cv_estimator

# 需要導入模塊: from sklearn import base [as 別名]
# 或者: from sklearn.base import ClusterMixin [as 別名]
def run_silhouette_cv_estimator(estimator, x, n_folds=10):
    """
    隻針對kmean的cv驗證,使用silhouette_score對聚類後的結果labels_
    進行度量使用silhouette_score,kmean的cv驗證隻是簡單的通過np.random.choice
    進行隨機篩選x數據進行聚類的silhouette_score度量,並不涉及訓練集測試集
    :param estimator: keman或者支持estimator.labels_, 隻通過if not isinstance(estimator, ClusterMixin)進行過濾
    :param x: x特征矩陣
    :param n_folds: int,透傳KFold參數,切割訓練集測試集參數,默認10
    :return: eg: array([ 0.693 ,  0.652 ,  0.6845,  0.6696,  0.6732,  0.6874,  0.668 ,
                         0.6743,  0.6748,  0.671 ])
    """

    if not isinstance(estimator, ClusterMixin):
        print('estimator must be ClusterMixin')
        return

    silhouette_list = list()
    # eg: n_folds = 10, len(x) = 150 -> 150 * 0.9 = 135
    choice_cnt = int(len(x) * ((n_folds - 1) / n_folds))
    choice_source = np.arange(0, x.shape[0])

    # 所有執行fit的操作使用clone一個新的
    estimator = clone(estimator)
    for _ in np.arange(0, n_folds):
        # 隻是簡單的通過np.random.choice進行隨機篩選x數據
        choice_index = np.random.choice(choice_source, choice_cnt)
        x_choice = x[choice_index]
        estimator.fit(x_choice)
        # 進行聚類的silhouette_score度量
        silhouette_score = metrics.silhouette_score(x_choice, estimator.labels_, metric='euclidean')
        silhouette_list.append(silhouette_score)
    return silhouette_list 
開發者ID:bbfamily,項目名稱:abu,代碼行數:34,代碼來源:ABuMLExecute.py

示例3: _check_parameters

# 需要導入模塊: from sklearn import base [as 別名]
# 或者: from sklearn.base import ClusterMixin [as 別名]
def _check_parameters(self):
        """Check if the parameters passed as argument are correct.

        Raises
        ------
        ValueError
            If the hyper-parameters are incorrect.
        """
        if self.metric_diversity not in ['DF', 'Q', 'ratio']:
            raise ValueError(
                'Diversity metric must be one of the following values:'
                ' "DF", "Q" or "Ratio"')

        try:
            getattr(metrics, self.metric_performance)
        except AttributeError:
            raise ValueError(
                "Parameter metric_performance must be a sklearn metrics")

        if self.N_ <= 0 or self.J_ <= 0:
            raise ValueError("The values of N_ and J_ should be higher than 0"
                             "N_ = {}, J_= {} ".format(self.N_, self.J_))
        if self.N_ < self.J_:
            raise ValueError(
                "The value of N_ should be greater or equals than J_"
                "N_ = {}, J_= {} ".format(self.N_, self.J_))

        if self.clustering is not None:
            if not isinstance(self.clustering, ClusterMixin):
                raise ValueError(
                    "Parameter clustering must be a sklearn"
                    " cluster estimator.") 
開發者ID:scikit-learn-contrib,項目名稱:DESlib,代碼行數:34,代碼來源:des_clustering.py

示例4: yield_all_checks

# 需要導入模塊: from sklearn import base [as 別名]
# 或者: from sklearn.base import ClusterMixin [as 別名]
def yield_all_checks(name, estimator):
    tags = estimator._get_tags()
    if "2darray" not in tags["X_types"]:
        warnings.warn("Can't test estimator {} which requires input "
                      " of type {}".format(name, tags["X_types"]),
                      SkipTestWarning)
        return
    if tags["_skip_test"]:
        warnings.warn("Explicit SKIP via _skip_test tag for estimator "
                      "{}.".format(name),
                      SkipTestWarning)
        return

    yield from _yield_checks(name, estimator)
    if is_classifier(estimator):
        yield from _yield_classifier_checks(name, estimator)
    if is_regressor(estimator):
        yield from _yield_regressor_checks(name, estimator)
    if hasattr(estimator, 'transform'):
        if not tags["allow_variable_length"]:
            # Transformer tests ensure that shapes are the same at fit and
            # transform time, hence we need to skip them for estimators that
            # allow variable-length inputs
            yield from _yield_transformer_checks(name, estimator)
    if isinstance(estimator, ClusterMixin):
        yield from _yield_clustering_checks(name, estimator)
    if is_outlier_detector(estimator):
        yield from _yield_outliers_checks(name, estimator)
    # We are not strict on presence/absence of the 3rd dimension
    # yield check_fit2d_predict1d

    if not tags["non_deterministic"]:
        yield check_methods_subset_invariance

    yield check_fit2d_1sample
    yield check_fit2d_1feature
    yield check_fit1d
    yield check_get_params_invariance
    yield check_set_params
    yield check_dict_unchanged
    yield check_dont_overwrite_parameters
    yield check_fit_idempotent

    if (is_classifier(estimator) or
            is_regressor(estimator) or
            isinstance(estimator, ClusterMixin)):
        if tags["allow_variable_length"]:
            yield check_different_length_fit_predict_transform 
開發者ID:tslearn-team,項目名稱:tslearn,代碼行數:50,代碼來源:sklearn_patches.py


注:本文中的sklearn.base.ClusterMixin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。