Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Calculate score using R code

wmacooper4
7 - Meteor

This is my issue.  My databases are getting larger, and it bogs down our model runs on SPSS.

What we're looking to do is to do as much as we can using R.  I would use Alteryx to come up with the validation sample and data to input into my model.

 

When I run logistic regression, I have the code to do stepwise to reduce the number of predictor variables, and then the code to run logistic with binary target variable.  Now, when it comes to the Score tool, is there a way to see the actual code that calculates the score_y & score_n?

 

If what I propose is not possible, can I copy and paste the logistic output from R into an Alteryx tool and then connect that to the Score tool on my module to calculate score?

 

Thanks in advance.

10 REPLIES 10
NeilR
Alteryx Alumni (Retired)

If I understand your use case, should be quite doable. Here's an example of code I've run in RStudio...

default <- read.csv("C:/Users/nryan/Desktop/default.csv")
model <- glm(formula = Default ~ Chk_Bal + Savings_Bonds + Debtor_Guarantor, family = "binomial", data = default)
save(model, file = "C:/Users/nryan/Desktop/myModel.RData")

Then in Alteryx, I run the attached with "new" data. Here's the R code to be inserted into the R tool in Alteryx, with the new data flowing into the R tool...

default <- read.Alteryx("#1", mode="data.frame")
load("C:/Users/nryan/Desktop/myModel.RData")
predictions <- predict(model, newdata = default, type = "response")
default["prediction"] <- predictions
write.Alteryx(default, 1)

In the attached example I show how this compares to doing the entire thing in Alteryx. Hope this helps.

Labels