Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ROC plot for h2o package

# for example I have 4 H2OModels
list(logit_fit,dt_fit,rf_fit,xgb_fit) %>% 
  # map a function to each element in the list
  map(function(x) x %>% h2o.performance(valid=T) %>% 
        # from all these 'paths' in the object
        .@metrics %>% .$thresholds_and_metric_scores %>% 
        # extracting true positive rate and false positive rate
        .[c('tpr','fpr')] %>% 
        # add (0,0) and (1,1) for the start and end point of ROC curve
        add_row(tpr=0,fpr=0,.before=T) %>% 
        add_row(tpr=0,fpr=0,.before=F)) %>% 
  # add a column of model name for future grouping in ggplot2
  map2(c('Logistic Regression','Decision Tree','Random Forest','Gradient Boosting'),
        function(x,y) x %>% add_column(model=y)) %>% 
  # reduce four data.frame to one
  reduce(rbind) %>% 
  # plot fpr and tpr, map model to color as grouping
  ggplot(aes(fpr,tpr,col=model))+
  geom_line()+
  geom_segment(aes(x=0,y=0,xend = 1, yend = 1),linetype = 2,col='grey')+
  xlab('False Positive Rate')+
  ylab('True Positive Rate')+
  ggtitle('ROC Curve for Four Models')
Comment

PREVIOUS NEXT
Code Example
Python :: dataflair python 
Python :: Flask - store object directly in a session [duplicate] 
Python :: python image processing and resizing 
Python :: how to load images from folder in python 
Python :: cv2 warpaffine rotate 
Python :: Obtener el valor ASCII de un carácter en Python 
Python :: Shelve Data Storage 
Python :: how to code a jumping function in python 
Python :: nunique sort 
Python :: python random number 1 100 
Python :: inserting a charcater in a pyhtong string at a specific index 
Python :: gizeh python 
Python :: 1038 solution python 
Python :: i want to check my python code online 
Python :: how to run django server outside world 
Python :: django celery email 
Python :: changing correlation encoding values 
Python :: using the return statement, defining a function, with input from the user. 
Python :: pandas apply dont convert to timestamp 
Python :: how to convert input time value to datetime 
Python :: Iterate over several iterables in parallel 
Python :: accessing list elements in python 
Python :: Python Tkinter Menu Widget Syntax 
Python :: flask env variable 
Python :: Create Admin Interface For Objects 
Python :: pandas get most occurring value for each id 
Python :: Example of inheritance and constructor in subclass 
Python :: database setup in django aws 
Python :: how to find most occurring items in sequence python 
Python :: python first letter to capitalize 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =