求python写的随机森林的roc代码
发布网友
发布时间:2022-05-02 03:34
我来回答
共1个回答
热心网友
时间:2022-06-27 18:41
随机森林在R packages和Python scikit-learn中的实现是当下非常流行的,下列是在R和Python中载入随机森林模型的具体代码:
Python
#Import Library
fromsklearn.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=1000)
# Train the model using the training sets and check score
model.fit(X, y)
#Predict Output
predicted= model.predict(x_test)
R Code
library(randomForest)
x<- cbind(x_train,y_train)
# Fitting model
fit<- randomForest(Species ~ ., x,ntree=500)
summary(fit)
#Predict Output
predicted= predict(fit,x_test)