本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.feature_importances_方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.feature_importances_方法的具体用法?Python RandomForestClassifier.feature_importances_怎么用?Python RandomForestClassifier.feature_importances_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.feature_importances_方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: abclassifier
# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import feature_importances_ [as 别名]
def abclassifier(training_samples, eval_samples):
X_train, Y_train = training_samples
X_eval, Y_eval = eval_samples
do_grid_search=False
clf = RandomForestClassifier(n_estimators=2000, criterion='gini', max_depth=None,
min_samples_split=8, min_samples_leaf=1, min_weight_fraction_leaf=0.0,
max_features=40, max_leaf_nodes=None, bootstrap=True, oob_score=False,
n_jobs=10, random_state=None, verbose=0, warm_start=False, class_weight=None)
if do_grid_search:
to_be_tuned_parameters = {
'n_estimators':[500, 1000, 2000],
'max_features':['log2', 'auto', None],
'min_samples_split':[2, 4, 8],
'min_samples_leaf': [1, 2],
}
clf = GridSearchCV(clf, to_be_tuned_parameters, cv=5, n_jobs=5, scoring='log_loss')
#Best parameters set found on development set:
#()
#{'max_features': 'log2', 'min_samples_split': 8, 'criterion': 'gini', 'min_samples_leaf': 1}
clf = AdaBoostClassifier(base_estimator=clf, n_estimators=200, learning_rate=0.2, algorithm='SAMME.R', random_state=None)
print(clf)
clf.fit(X_train, Y_train)
if do_grid_search:
print("Best parameters set found on development set:")
print()
print(clf.best_params_)
print()
print("Grid scores on development set:")
print()
for params, mean_score, scores in clf.grid_scores_:
print("%0.3f (+/-%0.03f) for %r"
% (mean_score, scores.std() * 2, params))
else:
scores = cross_validation.cross_val_score(clf, X_train, Y_train, cv=5, n_jobs=5, scoring='log_loss')
print scores, np.mean(scores), np.median(scores)
Y_eval = clf.predict(X_eval)
Y_prob = clf.predict_proba(X_eval)
return Y_eval, Y_prob, clf.feature_importances_()