Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import sklearn.datasets
- import sklearn.model_selection
- import sklearn.linear_model
- import numpy
- #import compue_auc
- import scipy.stats
- import random
- import pandas as pd
- #import numpy as np
- from scipy.stats import sem
- from sklearn.metrics import roc_auc_score
- import matplotlib.pyplot as plt
- #https://github.com/APavlides/cap_curve/blob/master/cap_curve.py
- data = pd.read_excel(r'ur_path')
- """
- if necessary to read specific sheet, use sheet_name = 'ur_sheet'
- pd.read_excel(r'ur_path', sheet_name = '')
- """
- pred = data['pred'] #change for your column name/names
- y_test = data['flag'] #change for your column name
- # length of the test data
- total = len(y_test)
- # Counting '1' labels in test data
- one_count = np.sum(y_test)
- # counting '0' labels in test data
- zero_count = total - one_count
- plt.figure(figsize=(10, 6))
- # x-axis ranges from 0 to total people contacted
- # y-axis ranges from 0 to the total positive outcomes.
- plt.plot([0, total], [0, one_count], c='b',
- linestyle='--', label='Random Model')
- plt.legend()
- lm = [y for _, y in sorted(zip(pred, y_test), reverse = True)]
- x = np.arange(0, total + 1)
- y = np.append([0], np.cumsum(lm))
- plt.plot(x, y, c = 'b', label = 'Random classifier', linewidth = 2)
- plt.plot([0, one_count, total], [0, one_count, one_count],
- c = 'grey', linewidth = 2, label = 'Perfect Model')
- plt.savefig(f'test.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement