Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. y_column = "churn"
  2. X_columns = df_X_train.columns
  3.  
  4. data_plot = df_X_train.copy()
  5. data_plot[y_column] = y_train
  6.  
  7. plt.figure(figsize=(15, 30))
  8.  
  9. for i_col in range(len(X_columns)):
  10.  
  11. # Create subplot for each column
  12. plt.subplot(7, 3, i_col+1)
  13.  
  14. # Get column and label values
  15. x_col = data_plot[X_columns[i_col]].values
  16. y_col = data_plot[y_column].values
  17.  
  18. # Plot histograms
  19. bins = np.linspace(0, x_col.max(), 21)
  20. plt.hist(x_col[y_col == 0], bins=bins, color='r', alpha=0.5, label='0')
  21. plt.hist(x_col[y_col == 1], bins=bins, color='b', alpha=0.5, label='1')
  22.  
  23. # Labels and legend
  24. plt.xlabel(X_columns[i_col])
  25. plt.ylabel('Counts')
  26. plt.legend(loc='best')
  27.  
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement