我正在使用 scikit-learn 包构建一个标准的 RandomForest 分类器(命名模型,请参见下面的代码)。现在,我想获取一个 Randomforest 分类器的所有参数(包括它的树(估计器)),以便我可以手动绘制 RandomForest 分类器的每棵树的流程图。我想知道是否有人知道如何做到这一点?
先感谢您。
满
#Import Library
from sklearn.ensemble import RandomForestClassifier #use RandomForestRegressor for regression problem
#Assumed you have, X (predictor) and Y (target) for training data set and x_test(predictor) of test_dataset
# Create Random Forest object
model= RandomForestClassifier(n_estimators=10, max_depth=5) #n_estimators=1000 oob_score = True
#====
#X, y = input_X, input_y
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.2, random_state = 4)
# Train the model using the training sets and check score
model.fit(X_train, y_train)
#Predict Output
y_pred_train = model.predict(X_train)
y_pred_test = model.predict(X_test)
#accuracy
from sklearn.metrics import accuracy_score
print(accuracy_score(y_train,y_pred_train))
print(accuracy_score(y_test,y_pred_test))