我正在使用随机森林与科学知识。射频覆盖数据,预测结果较差。
超调不取决于RF: NBtree、Depth_Tree的参数。
过度适应发生在许多不同的参数(通过grid_search测试它)。
补救措施:调整初始数据/下采样,以影响拟合结果(人工预处理噪声样本)。
Loop on random generation of RF fits,
Get RF prediction on the data for prediction
Select the model which best fits the "predicted data" (not the calibration data).这个蒙特卡洛斯非常消耗,只是想知道是否有另一种方法来做交叉验证的随机森林?(非超参数优化)
编辑
发布于 2016-07-02 01:30:30
与scikit中的任何分类器进行交叉验证实际上是微不足道的:
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
import numpy as np
clf = RandomForestClassifier() #Initialize with whatever parameters you want to
# 10-Fold Cross validation
print np.mean(cross_val_score(clf, X_train, y_train, cv=10))如果您希望运行网格搜索,您可以通过GridSearchCV类轻松地完成它。为了做到这一点,您必须提供一个param_grid,根据文档,它是
以参数名称(字符串)作为键和参数设置列表作为值的字典,或者这类字典的列表,在这种情况下,将探索列表中每个字典所跨越的网格。这允许对任何参数设置序列进行搜索。
因此,您可以将您的param_grid定义为:
param_grid = {
'n_estimators': [5, 10, 15, 20],
'max_depth': [2, 5, 7, 9]
}然后您可以使用GridSearchCV类,如下所示
from sklearn.model_selection import GridSearchCV
grid_clf = GridSearchCV(clf, param_grid, cv=10)
grid_clf.fit(X_train, y_train)然后,您可以使用grid_clf. best_estimator_获得最佳模型,使用grid_clf. best_params_获得最佳参数。类似地,您可以使用grid_clf.cv_results_获取网格分数。
希望这能有所帮助!
https://stackoverflow.com/questions/38151615
复制相似问题