Python sklearn.utils.fixes.MaskedArray() Examples
The following are 4
code examples of sklearn.utils.fixes.MaskedArray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sklearn.utils.fixes
, or try the search function
.
Example #1
Source File: test_fixes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
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)
Example #2
Source File: test_fixes.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #3
Source File: hyperband.py From civisml-extensions with BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example #4
Source File: _search.py From dislib with Apache License 2.0 | 4 votes |
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