本文整理汇总了Python中sklearn.externals.six.iteritems函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems函数的具体用法?Python iteritems怎么用?Python iteritems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteritems函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:cimor,项目名称:skl-groups,代码行数:32,代码来源:knn.py
示例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
开发者ID:tgsmith61591,项目名称:skutil,代码行数:26,代码来源:grid_search.py
示例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
开发者ID:jcrudy,项目名称:higgs,代码行数:9,代码来源:pipeline.py
示例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
开发者ID:ilikesongdandan,项目名称:Introduction-to-Programming-Using-Python,代码行数:9,代码来源:learn_easy_vote.py
示例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
开发者ID:ijustloveses,项目名称:armory,代码行数:9,代码来源:ensemble_classifier.py
示例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
开发者ID:beingzy,项目名称:mlxtend,代码行数:10,代码来源:ensemble_vote.py
示例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
开发者ID:nlinc1905,项目名称:Ensemble-Models-Majority-Vote-FWLS,代码行数:10,代码来源:sls_logistic_reg_classifier.py
示例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
开发者ID:daniaki,项目名称:ppi_wrangler,代码行数:11,代码来源:learning.py
示例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
开发者ID:josh-howes,项目名称:sklearn-stacking,代码行数:14,代码来源:stacking_regressor.py
示例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
开发者ID:chrinide,项目名称:mlxtend,代码行数:15,代码来源:stacking_cv_classification.py
示例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)
开发者ID:NelleV,项目名称:scikit-learn,代码行数:25,代码来源:test_multiclass.py
示例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
开发者ID:doxav,项目名称:skll,代码行数:31,代码来源:DictVectorizer.py
示例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
开发者ID:bochaton,项目名称:scikit-learn,代码行数:25,代码来源:text.py
示例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
开发者ID:dalupus,项目名称:python-faudmutils,代码行数:33,代码来源:resultsFormater.py
示例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
开发者ID:tgsmith61591,项目名称:skutil,代码行数:35,代码来源:grid_search.py
示例16: get_feature_names
def get_feature_names(self):
"""Array mapping from feature integer indices to feature name"""
if not hasattr(self, 'vocabulary_') or len(self.vocabulary_) == 0:
raise ValueError("Vocabulary wasn't fitted or is empty!")
return [t for t, i in sorted(six.iteritems(self.vocabulary_),
key=itemgetter(1))]
开发者ID:2011200799,项目名称:scikit-learn,代码行数:7,代码来源:text.py
示例17: transform
def transform(self, X):
"""Transform a test matrix given the already-fit transformer.
Parameters
----------
X : Pandas ``DataFrame``
The Pandas frame to transform. The operation will
be applied to a copy of the input data, and the result
will be returned.
Returns
-------
X : Pandas ``DataFrame``
The operation is applied to a copy of ``X``,
and the result set is returned.
"""
check_is_fitted(self, 'sq_nms_')
# check on state of X and cols
X, _ = validate_is_pd(X, self.cols)
sq_nms_ = self.sq_nms_
# scale by norms
for nm, the_norm in six.iteritems(sq_nms_):
X[nm] /= the_norm
return X if self.as_df else X.as_matrix()
开发者ID:tgsmith61591,项目名称:skutil,代码行数:30,代码来源:transform.py
示例18: test_paired_distances
def test_paired_distances():
""" Test the pairwise_distance helper function. """
rng = np.random.RandomState(0)
# Euclidean distance should be equivalent to calling the function.
X = rng.random_sample((5, 4))
# Euclidean distance, with Y != X.
Y = rng.random_sample((5, 4))
for metric, func in iteritems(PAIRED_DISTANCES):
S = paired_distances(X, Y, metric=metric)
S2 = func(X, Y)
assert_array_almost_equal(S, S2)
if metric in PAIRWISE_DISTANCE_FUNCTIONS:
# Check the the pairwise_distances implementation
# gives the same value
distances = PAIRWISE_DISTANCE_FUNCTIONS[metric](X, Y)
distances = np.diag(distances)
assert_array_almost_equal(distances, S)
# Check the callable implementation
S = paired_distances(X, Y, metric='manhattan')
S2 = paired_distances(X, Y,
metric=lambda x, y: np.abs(x -y).sum(axis=0))
assert_array_almost_equal(S, S2)
# Test that a value error is raised when the lengths of X and Y should not
# differ
Y = rng.random_sample((3, 4))
assert_raises(ValueError, paired_distances, X, Y)
开发者ID:Arezou1,项目名称:scikit-learn,代码行数:28,代码来源:test_pairwise.py
示例19: set_params
def set_params(self, **params):
if not params:
# Simple optimisation to gain speed (inspect is slow)
return self
# gmm_0
gmm_0_param_dict = {}
gmm_1_param_dict = {}
valid_params = self.get_params(deep=True)
for key, value in six.iteritems(params):
split = key.split('__',1)
if len(split) > 1:
# combined key name
prefix, name = split
if prefix.find('gmm_0') >= 0:
gmm_0_param_dict[name] = value
elif prefix.find('gmm_1') >= 0:
gmm_1_param_dict[name] = value
else:
raise ValueError('Invalid parameter %s ' 'for estimator %s'
% (key, self.__class__.__name__))
else:
# simple objects case
if not key in valid_params:
raise ValueError('Invalid parameter %s ' 'for estimator %s'
% (key, self.__class__.__name__))
setattr(self, key, value)
self.gmm_0.set_params(params=gmm_0_param_dict)
self.gmm_1.set_params(params=gmm_0_param_dict)
## self.gmm_1.set_params(gmm_1_param_dict)
return self
开发者ID:gt-ros-pkg,项目名称:hrl-assistive,代码行数:34,代码来源:learning_gmm.py
示例20: transform
def transform(self, raw_documents):
"""Extract token counts out of raw text documents using the vocabulary
fitted with fit or the one provided in the constructor.
Parameters
----------
raw_documents : iterable
An iterable which yields either str, unicode or file objects.
Returns
-------
vectors : sparse matrix, [n_samples, n_features]
"""
if not hasattr(self, 'vocabulary_') or len(self.vocabulary_) == 0:
raise ValueError("Vocabulary wasn't fitted or is empty!")
# raw_documents can be an iterable so we don't know its size in
# advance
# result of document conversion to term count arrays
i_indices = _make_int_array()
j_indices = _make_int_array()
values = _make_int_array()
analyze = self.build_analyzer()
for n_doc, doc in enumerate(raw_documents):
term_counts = Counter(analyze(doc))
for term, count in six.iteritems(term_counts):
if term in self.vocabulary_:
i_indices.append(n_doc)
j_indices.append(self.vocabulary_[term])
values.append(count)
n_doc += 1
return self._term_counts_to_matrix(n_doc, i_indices, j_indices, values)
开发者ID:JakeMick,项目名称:scikit-learn,代码行数:35,代码来源:text.py
注:本文中的sklearn.externals.six.iteritems函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论