随机森林-sklearn.ensemble.RandomForestRegressor

随机森林回归

class sklearn.ensemble.RandomForestRegressor(n_estimators=10criterion=’mse’max_depth=None,min_samples_split=2min_samples_leaf=1min_weight_fraction_leaf=0.0max_features=’auto’max_leaf_nodes=None,min_impurity_decrease=0.0min_impurity_split=Nonebootstrap=Trueoob_score=Falsen_jobs=1random_state=None,verbose=0warm_start=False)

随机森林是一种目标估计,通过对数据集上的部分样本形成一个分类决策树,并使用averaging去提高预测准确率和控制过拟合发生。

注:http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html


用法:

>>>from sklearn.ensemble import RandomForestRegressor

>>>data=[[0,0,0],[1,1,1],[2,2,2]]

>>>target=[0,1,2]

>>>rfr=RandomForestRegressor()

>>>rfr.fit(data,target)   #训练数据

>>>print(rfr.predict([[1,1,1]]))    #预测数据

[1.]

>>>print(rfr.predict([[1,1,1],[2,2,2]]))

[0.7  1.8]

你可能感兴趣的:(sklearn)