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


Python fixes.MaskedArray方法代码示例

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


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

示例1: test_masked_array_obj_dtype_pickleable

# 需要导入模块: from sklearn.utils import fixes [as 别名]
# 或者: from sklearn.utils.fixes import MaskedArray [as 别名]
def test_masked_array_obj_dtype_pickleable():
    marr = MaskedArray([1, None, 'a'], dtype=object)

    for mask in (True, False, [0, 1, 0]):
        marr.mask = mask
        marr_pickled = pickle.loads(pickle.dumps(marr))
        assert_array_equal(marr.data, marr_pickled.data)
        assert_array_equal(marr.mask, marr_pickled.mask) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:10,代码来源:test_fixes.py

示例2: _process_outputs

# 需要导入模块: from sklearn.utils import fixes [as 别名]
# 或者: from sklearn.utils.fixes import MaskedArray [as 别名]
def _process_outputs(self, out, n_splits):
        """return results dict and best dict for given outputs"""

        # if one choose to see train score, "out" will contain train score info
        if self.return_train_score:
            (train_scores, test_scores, test_sample_counts,
             fit_time, score_time, parameters) = zip(*out)
        else:
            (test_scores, test_sample_counts,
             fit_time, score_time, parameters) = zip(*out)

        candidate_params = parameters[::n_splits]
        n_candidates = len(candidate_params)

        results = dict()

        # Computed the (weighted) mean and std for test scores alone
        # NOTE test_sample counts (weights) remain the same for all candidates
        test_sample_counts = np.array(test_sample_counts[:n_splits],
                                      dtype=np.int)

        results = self._store_results(
            results, n_splits, n_candidates, 'test_score',
            test_scores, splits=True, rank=True,
            weights=test_sample_counts if self.iid else None)
        if self.return_train_score:
            results = self._store_results(
                results, n_splits, n_candidates,
                'train_score', train_scores, splits=True)
        results = self._store_results(
            results, n_splits, n_candidates, 'fit_time', fit_time)
        results = self._store_results(
            results, n_splits, n_candidates, 'score_time', score_time)

        best_index = np.flatnonzero(results["rank_test_score"] == 1)[0]

        # Use one MaskedArray and mask all the places where the param is not
        # applicable for that candidate. Use defaultdict as each candidate may
        # not contain all the params
        param_results = defaultdict(partial(MaskedArray,
                                            np.empty(n_candidates,),
                                            mask=True,
                                            dtype=object))
        for cand_i, params in enumerate(candidate_params):
            for name, value in params.items():
                # An all masked empty array gets created for the key
                # `"param_%s" % name` at the first occurence of `name`.
                # Setting the value at an index also unmasks that index
                param_results["param_%s" % name][cand_i] = value

        results.update(param_results)

        # Store a list of param dicts at the key 'params'
        results['params'] = candidate_params

        return results, best_index 
开发者ID:civisanalytics,项目名称:civisml-extensions,代码行数:58,代码来源:hyperband.py

示例3: _format_results

# 需要导入模块: from sklearn.utils import fixes [as 别名]
# 或者: from sklearn.utils.fixes import MaskedArray [as 别名]
def _format_results(candidate_params, scorers, n_splits, out):
        n_candidates = len(candidate_params)

        (test_score_dicts,) = zip(*out)

        test_scores = aggregate_score_dicts(test_score_dicts)

        results = {}

        def _store(key_name, array, splits=False, rank=False):
            """A small helper to store the scores/times to the cv_results_"""
            array = np.array(array, dtype=np.float64).reshape(n_candidates,
                                                              n_splits)
            if splits:
                for split_i in range(n_splits):
                    # Uses closure to alter the results
                    results["split%d_%s"
                            % (split_i, key_name)] = array[:, split_i]

            array_means = np.mean(array, axis=1)
            results['mean_%s' % key_name] = array_means
            array_stds = np.std(array, axis=1)
            results['std_%s' % key_name] = array_stds

            if rank:
                results["rank_%s" % key_name] = np.asarray(
                    rankdata(-array_means, method='min'), dtype=np.int32)

        # Use one MaskedArray and mask all the places where the param is not
        # applicable for that candidate. Use defaultdict as each candidate may
        # not contain all the params
        param_results = defaultdict(partial(MaskedArray,
                                            np.empty(n_candidates, ),
                                            mask=True,
                                            dtype=object))
        for cand_i, params in enumerate(candidate_params):
            for name, value in params.items():
                # An all masked empty array gets created for the key
                # `"param_%s" % name` at the first occurrence of `name`.
                # Setting the value at an index also unmasks that index
                param_results["param_%s" % name][cand_i] = value

        results.update(param_results)
        # Store a list of param dicts at the key 'params'
        results['params'] = candidate_params

        for scorer_name in scorers.keys():
            _store('test_%s' % scorer_name, test_scores[scorer_name],
                   splits=True, rank=True)

        return results 
开发者ID:bsc-wdc,项目名称:dislib,代码行数:53,代码来源:_search.py


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