pastebin

Paste Search Dynamic
Recent pastes
azureml main
  1. def azureml_main(frame1):
  2.     import matplotlib
  3.     matplotlib.use('agg')
  4.  
  5.     import pandas as pd
  6.     import numpy as np
  7.     import matplotlib.pyplot as plt
  8.     import statsmodels.graphics.boxplots as sm
  9.  
  10.     Azure = true
  11. ## Create a series of bar plots for the various levels of the
  12. ## string columns in the data frame by readmi_class.
  13.     names = list(frame1)
  14.     num_cols = frame1.shape[1]
  15.     for indx in range(num_cols - 1):
  16.             if(frame1.ix[:, indx].dtype not in [np.int64, np.int32, np.float64]):
  17.                 temp1 = frame1.ix[frame1.readmi_class == 'YES', indx].value_counts()
  18.                 temp0 = frame1.ix[frame1.readmi_class == 'NO', indx].value_counts()  
  19.                 fig = plt.figure(figsize = (12,6))
  20.                 fig.clf()
  21.                 ax1 = fig.add_subplot(1, 2, 1)
  22.                 ax0 = fig.add_subplot(1, 2, 2)
  23.                 temp1.plot(kind = 'bar', ax = ax1)
  24.                 ax1.set_title('Values of ' + names[indx] + 'n for readmitted patients')
  25.                 temp0.plot(kind = 'bar', ax = ax0)
  26.                 ax0.set_title('Values of ' + names[indx] + 'n for patients not readmitted')
  27.              
  28.                 if(Azure == true): fig.savefig('bar_' + names[indx] +'.png')
  29.                     ## Now make some box plots of the columns with numerical values.
  30.     for indx in range(num_cols):
  31.             if(frame1.ix[:, indx].dtype in [np.int64, np.int32, np.float64]):
  32.                 temp1 = frame1.ix[frame1.readmi_class == 'YES', indx]
  33.                 temp0 = frame1.ix[frame1.readmi_class == 'NO', indx]
  34.          
  35.                 fig = plt.figure(figsize = (12,6))            
  36.                 fig.clf()
  37.                 ax1 = fig.add_subplot(1, 2, 1)            
  38.                 ax0 = fig.add_subplot(1, 2, 2)        
  39.                 ax1.boxplot(temp1.as_matrix())
  40.                 ax1.set_title('Box plot of ' + names[indx] + 'n for readmitted patients')
  41.                 ax0.boxplot(temp0.as_matrix())
  42.                 ax0.set_title('Box plot of ' + names[indx] + 'n for patients not readmitted')
  43.              
  44.                 if(Azure == true): fig.savefig('box_' + names[indx] +'.png')              
  45.     return frame1
  46.  
  47.  
Parsed in 0.018 seconds