Skip to content
Asaf Schers edited this page May 18, 2017 · 9 revisions

Random Forest

Generating PMML in R

# Install and require randomForest, pmml packages

install.packages('randomForest')
install.packages('pmml')
library("randomForest")
library('pmml')

# Login to Kaggle and download titanic dataset 
# https://www.kaggle.com/c/titanic/data 
# Load CSV to data frame -

titanic.train <- read.table("titanic_train.csv", header = TRUE, sep = ",")
titanic.train$Survived <- as.factor(titanic.train$Survived)

# Train RF model

titanic.rf <- randomForest(Survived ~ . - Name - Cabin - Ticket,  data = titanic.train, na.action = na.roughfix)

# Generate pmml from model

pmml <- pmml(titanic.rf)
saveXML(pmml, 'titanic_rf.pmml')

Classifying in ruby by PMML

random_forest = Scourby.get_model 'random_forest.pmml'
features = {a: 1, b: true, c: 'YES'}
random_forest.predict(features)
random_forest.decisions_count(features)

Gradient Boosted model

Generating PMML in R

Classifying in ruby by PMML

Clone this wiki locally