本文整理汇总了Python中sklearn.ensemble.AdaBoostClassifier.set_params方法的典型用法代码示例。如果您正苦于以下问题:Python AdaBoostClassifier.set_params方法的具体用法?Python AdaBoostClassifier.set_params怎么用?Python AdaBoostClassifier.set_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.AdaBoostClassifier
的用法示例。
在下文中一共展示了AdaBoostClassifier.set_params方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifier
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import set_params [as 别名]
def classifier(self, scoring, cv, eval_using):
adaclf = AdaBoostClassifier(algorithm='SAMME')
xtr = StandardScaler().fit_transform(self.xtr)
xte = StandardScaler().fit_transform(self.xte)
# iterate over each grid score for param tuner
for score in scoring:
print('Tuning parameters of inital classifiers...')
passive_params = param_tuner(PassiveAggressiveClassifier(),
score=score, cv=cv, xtr=xtr,
ytr=self.ytr)
passclf = PassiveAggressiveClassifier().set_params(**passive_params)
sgd_params = param_tuner(SGDClassifier(), score=score, cv=cv,
xtr=xtr, ytr=self.ytr)
sgdclf = SGDClassifier().set_params(**sgd_params)
# cant use resampling/bagging with passive aggressive classifier
# will raise ValueError: The number of class labels must be > 1
# since resampling may results in training sets with 1 class.
print('\n'+'Tuning meta-classifiers with tuned classifier/s...')
bagsgd_params = param_tuner(BaggingClassifier(sgdclf),
score=score, cv=cv, xtr=xtr,
ytr=self.ytr)
bg_sgdclf = BaggingClassifier(sgdclf).set_params(**bagsgd_params)
adasgd_params = param_tuner(adaclf.set_params(base_estimator=sgdclf),
score =score, cv=cv, xtr=xtr,
ytr=self.ytr)
ada_sgdclf = adaclf.set_params(**adasgd_params)
print('Voting on meta-classifiers/classifiers then predicting...')
vote = VotingClassifier(estimators=[('BagSGD', bg_sgdclf),
('adaboostSGD', ada_sgdclf),
('Passive', passclf)],
voting='hard').fit(xtr, self.ytr)
start = time.time()
y_true, y_pred = self.yte, vote.predict(xte)
print('\n' + '-'*5, 'FINAL PREDICTION RESULTS','-'*5 +'\n',
'{0:.4f}'.format(time.time()-start)+'--prediction time(secs)')
clf_evaluation = report(*eval_using, y_true=y_true, y_pred=y_pred)
for reports in clf_evaluation:
print('---',reports)
print(clf_evaluation[reports])
示例2: adbTuning
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import set_params [as 别名]
def adbTuning(self, pX, change = 3):
n = pX.shape[0]
adb = AdaBoostClassifier()
best_auc = 0
best_param = None
for i in range(change):
params = {
'n_estimators': 3+int(10*np.random.random()),
'random_state':2016
}
adb.set_params(**params)
auc = cross_val_score(adb, pX, self.y, scoring="roc_auc").mean()
if auc > best_auc:
best_auc = auc
best_param = params
print 'adaboost ' + str(best_auc)
return best_auc, AdaBoostClassifier(**best_param)
示例3: GridSearchCV
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import set_params [as 别名]
# search = GridSearchCV(AdaBoostClassifier(DecisionTreeClassifier(random_state=42), random_state=42),
# grid, make_scorer(f1_score), cv=StratifiedKFold(labels), n_jobs=-1)
# search.fit(features, labels)
# print search.best_score_
# print search.best_params_
# clf = search.best_estimator_
### To speed up the process of training the grid search is not included and the best parameters used.
### This is as recommended by the reviewer
best_params = {
'n_estimators': 4,
'base_estimator__criterion': 'gini',
'base_estimator__max_depth': 3,
'base_estimator__min_samples_leaf': 11}
clf = AdaBoostClassifier(DecisionTreeClassifier(random_state=42), random_state=42)
clf.set_params(**best_params)
## Task 6: Dump your classifier, dataset, and features_list so anyone can
## check your results. You do not need to change anything below, but make sure
## that the version of poi_id.py that you submit can be run on its own and
## generates the necessary .pkl files for validating your results.
dump_classifier_and_data(clf, my_dataset, features_list)
示例4: GridSearchCV
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import set_params [as 别名]
print 'Best scrore of Adaboost SAMME.R:', grid_search.best_score_
pdb.set_trace()
grid_search = GridSearchCV(bdt_discrete, param_grid=param_grid, cv=10)
grid_search.fit(X_train, y_train)
print 'Best parameters of Adaboost SAMME:' , grid_search.best_params_
print 'Best scrore of Adaboost SAMME:', grid_search.best_score_
pdb.set_trace()
'''
# Train on the training data set
num_estimators = 600;
bdt_real.set_params(n_estimators=num_estimators)
bdt_discrete.set_params(n_estimators=num_estimators)
bdt_real.fit(X_train, y_train)
bdt_discrete.fit(X_train, y_train)
real_test_errors = []
discrete_test_errors = []
# Test on the testing data set and display the accuracies
ypred_r = bdt_real.predict(X_test)
ypred_e = bdt_discrete.predict(X_test)
print 'Accuracy of SAMME.R = ', accuracy_score(ypred_r, y_test)
print 'Accuracy of SAMME = ', accuracy_score(ypred_e, y_test)
# Plot the relationship between error rates and number of trees
示例5: DC
# 需要导入模块: from sklearn.ensemble import AdaBoostClassifier [as 别名]
# 或者: from sklearn.ensemble.AdaBoostClassifier import set_params [as 别名]
# We can now compute the performance of the model on new, held out data from the **test set**:
# In[16]:
#test_score = svc.score(X_test, y_test)
test_score = abc.score(X_test_scaled, y_test)
print 'test_score'
print test_score
print 'abc'
print abc
params = {
'base_estimator': DC(max_depth=5)
}
print 'changing base estimator'
abc.set_params(**params)
#abc.base_estimator = DC(max_depth=5, min_samples_leaf=0.1*len(X_train))
abc.fit(X_train_scaled, y_train)
print 'new train score'
print abc.score(X_train_scaled, y_train)
# This score is clearly not as good as expected! The model cannot generalize so well to new, unseen data.
#
# - Whenever the **test** data score is **not as good as** the **train** score the model is **overfitting**
#
# - Whenever the **train score is not close to 100%** accuracy the model is **underfitting**
#
# Ideally **we want to neither overfit nor underfit**: `test_score ~= train_score ~= 1.0`.
# The previous example failed to generalized well to test data because we naively used the default parameters of the `SVC` class:
# In[17]: