本文整理匯總了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)
示例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
示例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