本文整理汇总了Python中sklearn.pipeline._name_estimators函数的典型用法代码示例。如果您正苦于以下问题:Python _name_estimators函数的具体用法?Python _name_estimators怎么用?Python _name_estimators使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_name_estimators函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: fit
def fit(self, X, y):
"""Learn weight coefficients from training data for each classifier.
Parameters
----------
X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and
n_features is the number of features.
y : array-like, shape = [n_samples]
Target values.
Returns
-------
self : object
"""
if isinstance(y, np.ndarray) and len(y.shape) > 1 and y.shape[1] > 1:
raise NotImplementedError('Multilabel and multi-output'
' classification is not supported.')
if self.voting not in ('soft', 'hard'):
raise ValueError("Voting must be 'soft' or 'hard'; got (voting=%r)"
% self.voting)
if self.weights and len(self.weights) != len(self.clfs):
raise ValueError('Number of classifiers and weights must be equal'
'; got %d weights, %d clfs'
% (len(self.weights), len(self.clfs)))
self.le_ = LabelEncoder()
self.le_.fit(y)
self.classes_ = self.le_.classes_
self.clfs_ = [clone(clf) for clf in self.clfs]
if self.verbose > 0:
print("Fitting %d classifiers..." % (len(self.clfs)))
for clf in self.clfs_:
if self.verbose > 0:
i = self.clfs_.index(clf) + 1
print("Fitting clf%d: %s (%d/%d)" %
(i, _name_estimators((clf,))[0][0], i, len(self.clfs_)))
if self.verbose > 2:
if hasattr(clf, 'verbose'):
clf.set_params(verbose=self.verbose - 2)
if self.verbose > 1:
print(_name_estimators((clf,))[0][1])
clf.fit(X, self.le_.transform(y))
return self
开发者ID:beingzy,项目名称:mlxtend,代码行数:54,代码来源:ensemble_vote.py
示例2: __init__
def __init__(self, classifiers, vote='classlabel',
weights=None):
self.classifiers = classifiers
self.named_classifiers = {key: value for key, value in
_name_estimators(classifiers)}
self.vote = vote
self.weights = weights
开发者ID:prakharchoudhary,项目名称:fun_with_python,代码行数:7,代码来源:majority_voting.py
示例3: __init__
def __init__(self, clfs, voting='hard', weights=None, verbose=0):
self.clfs = clfs
self.named_clfs = {key: value for key, value in _name_estimators(clfs)}
self.voting = voting
self.weights = weights
self.verbose = verbose
开发者ID:beingzy,项目名称:mlxtend,代码行数:7,代码来源:ensemble_vote.py
示例4: __init__
def __init__(self, clfs, voting='hard', weights=None):
"""
voting: if 'hard', uses predicted class labels for majority rule voting
if 'soft', predicts the class label based on the argmax of the sums of the predicted probalities
"""
self.clfs = clfs
self.named_clfs = {key:value for key, value in _name_estimators(clfs)}
self.voting = voting
self.weights = weights
开发者ID:ijustloveses,项目名称:kaggle_learning,代码行数:9,代码来源:weighted_blend_model.py
示例5: __init__
def __init__(self, clfs, voting, weights=None, threshold=None):
self.clfs = clfs
self.named_clfs = {key:value for key,value in _name_estimators(clfs)}
self.voting=voting
if voting is 'weighted':
self.combiner=WeightedVote(weights=weights, threshold=threshold)
elif voting is 'majority':
self.combiner=MajorityVote()
else:
raise AttributeError('Unrecognized voting method')
开发者ID:Yashg19,项目名称:enrique,代码行数:10,代码来源:ensemblematcher.py
示例6: make_pipeline
def make_pipeline(*steps):
"""Construct a Pipeline from the given estimators.
This is a shorthand for the Pipeline constructor; it does not require, and
does not permit, naming the estimators. Instead, their names will be set
to the lowercase of their types automatically.
Returns
-------
p : Pipeline
"""
return Pipeline(pipeline._name_estimators(steps))
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:12,代码来源:pipeline.py
示例7: make_pipeline
def make_pipeline(*steps, **kwargs):
"""Construct a Pipeline from the given estimators.
This is a shorthand for the Pipeline constructor; it does not require, and
does not permit, naming the estimators. Instead, their names will be set
to the lowercase of their types automatically.
Parameters
----------
*steps : list of estimators.
memory : None, str or object with the joblib.Memory interface, optional
Used to cache the fitted transformers of the pipeline. By default,
no caching is performed. If a string is given, it is the path to
the caching directory. Enabling caching triggers a clone of
the transformers before fitting. Therefore, the transformer
instance given to the pipeline cannot be inspected
directly. Use the attribute ``named_steps`` or ``steps`` to
inspect estimators within the pipeline. Caching the
transformers is advantageous when fitting is time consuming.
Returns
-------
p : Pipeline
See also
--------
imblearn.pipeline.Pipeline : Class for creating a pipeline of
transforms with a final estimator.
Examples
--------
>>> from sklearn.naive_bayes import GaussianNB
>>> from sklearn.preprocessing import StandardScaler
>>> make_pipeline(StandardScaler(), GaussianNB(priors=None))
... # doctest: +NORMALIZE_WHITESPACE
Pipeline(memory=None,
steps=[('standardscaler',
StandardScaler(copy=True, with_mean=True, with_std=True)),
('gaussiannb',
GaussianNB(priors=None, var_smoothing=1e-09))])
"""
memory = kwargs.pop('memory', None)
if kwargs:
raise TypeError('Unknown keyword arguments: "{}"'
.format(list(kwargs.keys())[0]))
return Pipeline(pipeline._name_estimators(steps), memory=memory)
开发者ID:scikit-learn-contrib,项目名称:imbalanced-learn,代码行数:47,代码来源:pipeline.py
示例8: make_sparkunion
def make_sparkunion(*transformers):
"""Construct a FeatureUnion from the given transformers.
This is a shorthand for the FeatureUnion constructor; it does not require,
and does not permit, naming the transformers. Instead, they will be given
names automatically based on their types. It also does not allow weighting.
Examples
--------
>>> from sklearn.decomposition import PCA, TruncatedSVD
>>> make_union(PCA(), TruncatedSVD()) # doctest: +NORMALIZE_WHITESPACE
FeatureUnion(n_jobs=1,
transformer_list=[('pca', PCA(copy=True, n_components=None,
whiten=False)),
('truncatedsvd',
TruncatedSVD(algorithm='randomized',
n_components=2, n_iter=5,
random_state=None, tol=0.0))],
transformer_weights=None)
Returns
-------
f : FeatureUnion
"""
return SparkFeatureUnion(_name_estimators(transformers))
开发者ID:HendryLi,项目名称:sparkit-learn,代码行数:22,代码来源:pipeline.py
示例9: make_transformer_pipeline
def make_transformer_pipeline(*steps):
"""Construct a TransformerPipeline from the given estimators.
"""
return TransformerPipeline(_name_estimators(steps))
开发者ID:bmweiner,项目名称:sklearn-pandas,代码行数:4,代码来源:pipeline.py
示例10: make_dataframe_pipeline
def make_dataframe_pipeline(steps):
"""Construct a DataFramePipeline from the given estimators."""
return DataFramePipeline(_name_estimators(steps))
开发者ID:asford,项目名称:sklearn-pandas,代码行数:3,代码来源:dataframe_pipeline.py
示例11: make_alpha_pipeline
def make_alpha_pipeline(*steps):
return AlphaPipeline(_name_estimators(steps))
开发者ID:digideskio,项目名称:alphaware,代码行数:2,代码来源:pipeline.py
示例12: __init__
def __init__(self, classifiers):
self.classifiers = classifiers
self.named_classifiers = {key: value for key, value in _name_estimators(classifiers)}
开发者ID:nlinc1905,项目名称:Ensemble-Models-Majority-Vote-FWLS,代码行数:3,代码来源:sls_logistic_reg_classifier.py
示例13: transform
def transform(self, X, y=None):
xform_data = self.transform_.transform(X, y)
return np.append(X, xform_data, axis=1)
class LogExpPipeline(Pipeline):
def fit(self, X, y):
super(LogExpPipeline, self).fit(X, y)
def predict(self, X):
return super(LogExpPipeline, self).predict(X)
#
# Model/pipeline with scaling,pca,svm
# knn
knn_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
KNeighborsClassifier(n_neighbors = 15, metric = 'cityblock')]))
#
svm_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
SVC(kernel='rbf', C=14)]))
# results = cross_val_score(svm_pipe, train, y_train, cv=5, scoring='r2')
# print("SVM score: %.4f (%.4f)" % (results.mean(), results.std()))
# exit()
#
# XGBoost model
#
xgb_model = xgb.XGBClassifier(max_depth=4, learning_rate=0.0045, subsample=0.921,nthread=6,
objective='multi:softmax', n_estimators=500)
开发者ID:xiaofeifei1800,项目名称:Kaggle_Bimbo,代码行数:31,代码来源:stack_class.py
示例14: __init__
def __init__(self, clfs, voting="hard", weights=None):
self.clfs = clfs
self.named_clfs = {key: value for key, value in _name_estimators(clfs)}
self.voting = voting
self.weights = weights
开发者ID:h3nj3,项目名称:crowdflower-search,代码行数:6,代码来源:ensemble2.py
示例15: transform
def transform(self, X, y=None):
xform_data = self.transform_.transform(X, y)
return np.append(X, xform_data, axis=1)
class LogExpPipeline(Pipeline):
def fit(self, X, y):
super(LogExpPipeline, self).fit(X, np.log1p(y))
def predict(self, X):
return np.expm1(super(LogExpPipeline, self).predict(X))
#
# Model/pipeline with scaling,pca,svm
# knn
knn_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
KNeighborsRegressor(n_neighbors = 15, metric = 'cityblock')]))
#
svm_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
SVR(kernel='rbf', C=30, epsilon=0.05)]))
# results = cross_val_score(svm_pipe, train, y_train, cv=5, scoring='r2')
# print("SVM score: %.4f (%.4f)" % (results.mean(), results.std()))
# exit()
#
# Model/pipeline with scaling,pca,ElasticNet
#
en = ElasticNet(alpha=0.01, l1_ratio=0.9)
#
# XGBoost model
开发者ID:xiaofeifei1800,项目名称:Kaggle_Bimbo,代码行数:32,代码来源:stack_SVM_EN_XG_RF.py
注:本文中的sklearn.pipeline._name_estimators函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论