R Model Train & Score

March 5, 2015

542 views
280 downloads


Report Abuse
Demonstration of using the Train R Model functionality to train, score and evaluate a logistic regression model.
The goal here is to demonstrate how to use the R learners, specifically what is needed to use the built-in Evaluate module to generate standard metrics. The secret is to use R's attr() function to assign the necessary attributes to the resulting class, label and probability columns. Specifically, in the Score part of the Create R Model, I use: prob <- predict(model, dataset, type="response") attr(prob, 'feature.channel') = 'Binary Classification Scores' attr(prob, 'score.type') = 'Calibrated Score' classes <- as.factor(as.numeric(prob >= 0.5)) attr(classes, 'feature.channel') = 'Binary Classification Scores' attr(classes, 'score.type') = 'Assigned Labels' scores <- data.frame(     'Scored Labels'=classes,      'Scored Probabilities'=prob) The R script after Score Model assigns the appropriate label attribute: dataset1 <- maml.mapInputPort(1) # class: data.frame attr(dataset1$Class, 'label.type') = 'True Labels' print(str(dataset1)) maml.mapOutputPort("dataset1")