本文整理汇总了Python中sklearn.externals.six.iteritems函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems函数的具体用法?Python iteritems怎么用?Python iteritems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteritems函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_up_funcs
def _set_up_funcs(funcs, metas_ordered, Ks, dim, X_ns=None, Y_ns=None):
# replace functions with partials of args
def replace_func(func, info):
needs_alpha = getattr(func, 'needs_alpha', False)
new = None
args = (Ks, dim)
if needs_alpha:
args = (info.alphas,) + args
if hasattr(func, 'chooser_fn'):
args += (X_ns, Y_ns)
if (getattr(func, 'needs_all_ks', False) and
getattr(func.chooser_fn, 'returns_ks', False)):
new, K = func.chooser_fn(*args)
new.K_needed = K
else:
new = func.chooser_fn(*args)
else:
new = partial(func, *args)
for attr in dir(func):
if not (attr.startswith('__') or attr.startswith('func_')):
setattr(new, attr, getattr(func, attr))
return new
rep_funcs = dict(
(replace_func(f, info), info) for f, info in iteritems(funcs))
rep_metas_ordered = OrderedDict(
(replace_func(f, info), info) for f, info in iteritems(metas_ordered))
return rep_funcs, rep_metas_ordered
示例2: _clone_h2o_obj
def _clone_h2o_obj(estimator, ignore=False, **kwargs):
# do initial clone
est = clone(estimator)
# set kwargs:
if kwargs:
for k, v in six.iteritems(kwargs):
setattr(est, k, v)
# check on h2o estimator
if isinstance(estimator, H2OPipeline):
# the last step from the original estimator
e = estimator.steps[-1][1]
if isinstance(e, H2OEstimator):
last_step = est.steps[-1][1]
# so it's the last step
for k, v in six.iteritems(e._parms):
k, v = _kv_str(k, v)
# if (not k in PARM_IGNORE) and (not v is None):
# e._parms[k] = v
last_step._parms[k] = v
# otherwise it's an BaseH2OFunctionWrapper
return est
示例3: get_params
def get_params(self, deep=True):
if not deep:
return super(Pipeline, self).get_params(deep=False)
else:
out = self.named_steps.copy()
for name, step in six.iteritems(self.named_steps):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例4: get_params
def get_params(self, deep=True):
if not deep:
return super(MajorityVoteClassifier, self).get_params(deep=False)
else:
out = self.named_classifiers.copy()
for name, step in six.iteritems(self.named_classifiers):
for key, value in six.iteritems(self.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例5: get_params
def get_params(self, deep=True):
if not deep:
return super(EnsembleClassifier, self).get_params(deep=False)
else:
out = self.named_clfs.copy()
for name, step in six.iteritems(self.named_clfs):
for k, v in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, k)] = v
return out
示例6: get_params
def get_params(self, deep=True):
"""Return estimator parameter names for GridSearch support."""
if not deep:
return super(EnsembleVoteClassifier, self).get_params(deep=False)
else:
out = self.named_clfs.copy()
for name, step in six.iteritems(self.named_clfs):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例7: get_params
def get_params(self, deep=True):
""" Get classifier parameter names for GridSearch"""
if not deep:
return super(SLS_Classifier, self).get_params(deep=False)
else:
out = self.named_classifiers.copy()
for name, step in six.iteritems(self.named_classifiers):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例8: get_params
def get_params(self, deep=True):
"""Return estimator parameter names for GridSearch support"""
if not deep:
return super(HybridFeatureVotingClassifier, self).get_params(deep=False)
else:
out = super(HybridFeatureVotingClassifier, self).get_params(deep=False)
out.update(self.named_estimators.copy())
for name, step in six.iteritems(self.named_estimators):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例9: get_params
def get_params(self, deep=False):
"""Return estimator parameter names for GridSearch support"""
if not deep:
return super(StackingRegressor, self).get_params(deep=False)
else:
# TODO: this will not work, need to implement `named_estimators`
raise NotImplementedError("`deep` attribute not yet supported.")
out = super(StackingRegressor, self).get_params(deep=False)
out.update(self.named_estimators.copy())
for name, step in six.iteritems(self.named_estimators):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例10: get_params
def get_params(self, deep=True):
"""Return estimator parameter names for GridSearch support."""
if not deep:
return super(StackingCVClassifier, self).get_params(deep=False)
else:
out = self.named_classifiers.copy()
for name, step in six.iteritems(self.named_classifiers):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
out.update(self.named_meta_classifier.copy())
for name, step in six.iteritems(self.named_meta_classifier):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value
return out
示例11: test_type_of_target
def test_type_of_target():
for group, group_examples in iteritems(EXAMPLES):
for example in group_examples:
assert_equal(type_of_target(example), group,
msg=('type_of_target(%r) should be %r, got %r'
% (example, group, type_of_target(example))))
for example in NON_ARRAY_LIKE_EXAMPLES:
msg_regex = 'Expected array-like \(array or non-string sequence\).*'
assert_raises_regex(ValueError, msg_regex, type_of_target, example)
for example in MULTILABEL_SEQUENCES:
msg = ('You appear to be using a legacy multi-label data '
'representation. Sequence of sequences are no longer supported;'
' use a binary array or sparse matrix instead.')
assert_raises_regex(ValueError, msg, type_of_target, example)
try:
from pandas import SparseSeries
except ImportError:
raise SkipTest("Pandas not found")
y = SparseSeries([1, 0, 0, 1, 0])
msg = "y cannot be class 'SparseSeries'."
assert_raises_regex(ValueError, msg, type_of_target, y)
示例12: fit
def fit(self, X, y=None):
"""Learn a list of feature name -> indices mappings.
Parameters
----------
X : Mapping or iterable over Mappings
Dict(s) or Mapping(s) from feature names (arbitrary Python
objects) to feature values (strings or convertible to dtype).
y : (ignored)
Returns
-------
self
"""
# collect all the possible feature names
feature_names = set()
for x in X:
for f, v in six.iteritems(x):
if isinstance(v, six.string_types):
f_v = "%s%s%s" % (f, self.separator, v)
if f_v not in self._onehot_dict:
self._onehot_dict[f_v] = [f, v]
f = f_v
feature_names.add(f)
# sort the feature names to define the mapping
feature_names = sorted(feature_names)
self.vocabulary_ = dict((f, i) for i, f in enumerate(feature_names))
self.feature_names_ = feature_names
return self
示例13: _remove_highandlow
def _remove_highandlow(self, cscmatrix, feature_to_pos, high, low):
"""Remove too rare or too common features.
Prune features that are non zero in more samples than high or less
documents than low.
This does not prune samples with zero features.
"""
kept_indices = []
removed_indices = set()
for colptr in xrange(len(cscmatrix.indptr) - 1):
len_slice = cscmatrix.indptr[colptr + 1] - cscmatrix.indptr[colptr]
if len_slice <= high and len_slice >= low:
kept_indices.append(colptr)
else:
removed_indices.add(colptr)
s_kept_indices = set(kept_indices)
new_mapping = dict((v, i) for i, v in enumerate(kept_indices))
feature_to_pos = dict((k, new_mapping[v])
for k, v in six.iteritems(feature_to_pos)
if v in s_kept_indices)
return cscmatrix[:, kept_indices], feature_to_pos, removed_indices
示例14: mypp
def mypp(params, offset=0, printer=repr):
# Do a multi-line justified repr:
options = np.get_printoptions()
np.set_printoptions(precision=5, threshold=64, edgeitems=2)
params_list = list()
this_line_length = offset
line_sep = ',\n' + (1 + offset // 2) * ' '
for i, (k, v) in enumerate(sorted(six.iteritems(params))):
if type(v) is float:
# use str for representing floating point numbers
# this way we get consistent representation across
# architectures and versions.
this_repr = '%s=%s' % (k, str(v))
else:
# use repr of the rest
this_repr = '%s=%s' % (k, printer(v))
if len(this_repr) > 500000000:
this_repr = this_repr[:300] + '...' + this_repr[-100:]
if i > 0:
if (this_line_length + len(this_repr) >= 75 or '\n' in this_repr):
params_list.append(line_sep)
this_line_length = len(line_sep)
else:
params_list.append(', ')
this_line_length += 2
params_list.append(this_repr)
this_line_length += len(this_repr)
np.set_printoptions(**options)
lines = ''.join(params_list)
# Strip trailing space to avoid nightmare in doctests
lines = '\n'.join(l.rstrip(' ') for l in lines.split('\n'))
return lines
示例15: _new_base_estimator
def _new_base_estimator(est, clonable_kwargs):
"""When the grid searches are pickled, the estimator
has to be dropped out. When we load it back in, we have
to reinstate a new one, since the fit is predicated on
being able to clone a base estimator, we've got to have
an estimator to clone and fit.
Parameters
----------
est : str
The type of model to build
Returns
-------
estimator : H2OEstimator
The cloned base estimator
"""
est_map = {
'dl': H2ODeepLearningEstimator,
'gbm': H2OGradientBoostingEstimator,
'glm': H2OGeneralizedLinearEstimator,
# 'glrm': H2OGeneralizedLowRankEstimator,
# 'km' : H2OKMeansEstimator,
'nb': H2ONaiveBayesEstimator,
'rf': H2ORandomForestEstimator
}
estimator = est_map[est]() # initialize the new ones
for k, v in six.iteritems(clonable_kwargs):
k, v = _kv_str(k, v)
estimator._parms[k] = v
return estimator