1. 随机森林回归
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression

X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
regr = RandomForestRegressor(max_depth=2, random_state=0)
regr.fit(X, y)

print(regr.predict([[0, 0, 0, 0]]))
  1. GBDT回归
from sklearn.datasets import make_regression
from sklearn.ensemble import GradientBoostingRegressor

X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
regr = GradientBoostingRegressor(random_state=0)
regr.fit(X, y)

print(regr.predict([[0, 0, 0, 0]]))
  1. 多分类
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

X, y = make_classification(n_features=4, random_state=0)
clf = RandomForestClassifier(max_depth=2, random_state=0)
clf.fit(X, y)

print(clf.predict([[0, 0, 0, 0]]))
print(accuracy_score(y, clf.predict(X)))
``
用随机森林进行回归gbdt多分类编程这三个的代码实现

原文地址: http://www.cveoy.top/t/topic/hpFG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录