Alteryx Designer Desktop Discussions

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

Random Forest Data Output from Model (R tool)

razzy
8 - Asteroid

HI All,

I did a predictive model  using Random forest. I have my model working well,  i have been able to extract the data from the output of the variable of importance using the code below

 

# Read in serialized model object
modelObj <- read.Alteryx("#1", mode="data.frame")

# Unserialize model
model <- unserializeObject(as.character(modelObj$Object[1]))

# load library
library(randomForest)

# extract feature importance
importance <- importance(model)

# convert to data frame
output <- data.frame(var = row.names(importance), importance)

# write out data frame
write.Alteryx(output, 1)

 

What i would now like help with is also to write out the Classification report data that entails ( Precision, Recall, F1score, etc). In addition i would also want to output the confusion matrix data so i could plot it.  Any help would be great as i am not to detailed in R 

 

5 REPLIES 5
phottovy
13 - Pulsar
13 - Pulsar

Hi @razzy ,

 

I modified the sample predictive workflow in Alteryx to make a basic classification report for you. First, you are able to see a confusion matrix for your training data by looking at "R" output of the Forest tool:

phottovy_0-1653422241486.png

phottovy_1-1653422251467.png

 

I also added some basic logic to compare the model predictions to the actual values. I didn't calculate each metric but I gave you all the pieces to plug into each formula:

phottovy_2-1653422387709.png 

phottovy_3-1653422402128.png

 

Hopefully this gets you close to your desired output!

 

 

razzy
8 - Asteroid

Thank you so much for responding to this , so my model is  a classification but not binary, i have used your  example but i  was unable to compute Label of (TN,FP, FN,TP). I am attaching my dataset can you please help with how i can go around that. My goal is actual to output a result like this one shown here as a screen shot. I did however got the confusion matrix. Attached is my dataset.

razzy_0-1653505878217.png

 

phottovy
13 - Pulsar
13 - Pulsar

I had some fun with this one. I added a section below my original workflow that I believe calculates the values correctly. For the sake of time, I did not calculate the micro/macro/weighted avgs at the bottom but you should have all the pieces if you want to add those.

 

Output from your sample data:

phottovy_0-1653512494807.png

 

razzy
8 - Asteroid

Thank you so much this is amazing.

phottovy
13 - Pulsar
13 - Pulsar

Hi @razzy , if my answer helped, please mark it as an accepted solution so others can find it in the future.

Labels