本文整理汇总了Python中sklearn.ensemble.ExtraTreesRegressor.feature_importances方法的典型用法代码示例。如果您正苦于以下问题:Python ExtraTreesRegressor.feature_importances方法的具体用法?Python ExtraTreesRegressor.feature_importances怎么用?Python ExtraTreesRegressor.feature_importances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.ExtraTreesRegressor
的用法示例。
在下文中一共展示了ExtraTreesRegressor.feature_importances方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_regressor
# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import feature_importances [as 别名]
def get_regressor(x, y, n_estimators=1500, n_tries=5,
verbose=False):
"""Calculate an ExtraTreesRegressor on predictor and target variables
Parameters
----------
x : numpy.array
Predictor vector
y : numpy.array
Target vector
n_estimators : int, optional
Number of estimators to use
n_tries : int, optional
Number of attempts to calculate regression
verbose : bool, optional
If True, output progress statements
Returns
-------
classifier : sklearn.ensemble.ExtraTreesRegressor
The classifier with the highest out of bag scores of all the
attempted "tries"
oob_scores : numpy.array
Out of bag scores of the classifier
"""
if verbose:
sys.stderr.write('Getting regressor\n')
clfs = []
oob_scores = []
for i in range(n_tries):
if verbose:
sys.stderr.write('%d.' % i)
clf = ExtraTreesRegressor(n_estimators=n_estimators, oob_score=True,
bootstrap=True, max_features='sqrt',
n_jobs=1, random_state=i).fit(x, y)
clfs.append(clf)
oob_scores.append(clf.oob_score_)
clf = clfs[np.argmax(oob_scores)]
clf.feature_importances = pd.Series(clf.feature_importances_,
index=x.columns)
return clf, oob_scores
示例2: get_regressor
# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import feature_importances [as 别名]
def get_regressor(x, y, n_estimators=1500, pCut=0.05, n_tries=5,
verbose=False):
if verbose:
sys.stderr.write('getting regressor\n')
clfs = []
oob_scores = []
for i in range(n_tries):
if verbose:
sys.stderr.write('%d.' % i)
clf = ExtraTreesRegressor(n_estimators=n_estimators, oob_score=True,
bootstrap=True, max_features='sqrt',
n_jobs=1, random_state=i).fit(x, y)
clfs.append(clf)
oob_scores.append(clf.oob_score_)
clf = clfs[np.argmax(oob_scores)]
clf.feature_importances = pd.Series(clf.feature_importances_,
index=x.columns)
return clf, oob_scores