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
Solved! Go to Solution.
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:
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:
Hopefully this gets you close to your desired output!
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.
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:
Thank you so much this is amazing.
Hi @razzy , if my answer helped, please mark it as an accepted solution so others can find it in the future.