In [47]:
import pandas as pd
import numpy as np

from sklearn import preprocessing
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.svm import LinearSVC
from sklearn.calibration import CalibratedClassifierCV

from sklearn.feature_selection import RFE
from sklearn.model_selection import GridSearchCV
from sklearn import metrics
from sklearn.model_selection import cross_val_score

import matplotlib.pylab as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = 10, 8

In [2]:
## Load cleaned approved loan data
df = pd.read_csv('approved_loan_2015_clean.csv',low_memory=False)

In [22]:
p_optimal='l1'

In [4]:
df.head()


Out[4]:
Unnamed: 0 loan_amnt annual_inc fico_range_low fico_range_high num_actv_bc_tl tot_cur_bal mort_acc num_actv_rev_tl pub_rec_bankruptcies ... sub_grade_F2 sub_grade_F3 sub_grade_F4 sub_grade_F5 sub_grade_G1 sub_grade_G2 sub_grade_G3 sub_grade_G4 sub_grade_G5 int_rate
0 0 16000.0 62000.0 720.0 724.0 4.0 227708.0 3.0 5.0 0.0 ... 0 0 0 0 0 0 0 0 0 8.49
1 1 8000.0 45000.0 670.0 674.0 3.0 148154.0 2.0 11.0 0.0 ... 0 0 0 0 0 0 0 0 0 10.78
2 2 10000.0 41600.0 695.0 699.0 2.0 168304.0 2.0 5.0 0.0 ... 0 0 0 0 0 0 0 0 0 10.78
3 3 24700.0 65000.0 715.0 719.0 5.0 204396.0 4.0 5.0 0.0 ... 0 0 0 0 0 0 0 0 0 11.99
4 4 10000.0 42500.0 705.0 709.0 4.0 41166.0 0.0 4.0 0.0 ... 0 0 0 0 0 0 0 0 0 11.99

5 rows × 78 columns


In [10]:
c=0.0820849986238988

In [13]:
df2 = df.copy()
df2 = df2.ix[:,1:]

In [15]:
df2.head()


Out[15]:
loan_amnt annual_inc fico_range_low fico_range_high num_actv_bc_tl tot_cur_bal mort_acc num_actv_rev_tl pub_rec_bankruptcies dti ... sub_grade_F2 sub_grade_F3 sub_grade_F4 sub_grade_F5 sub_grade_G1 sub_grade_G2 sub_grade_G3 sub_grade_G4 sub_grade_G5 int_rate
0 16000.0 62000.0 720.0 724.0 4.0 227708.0 3.0 5.0 0.0 28.92 ... 0 0 0 0 0 0 0 0 0 8.49
1 8000.0 45000.0 670.0 674.0 3.0 148154.0 2.0 11.0 0.0 21.23 ... 0 0 0 0 0 0 0 0 0 10.78
2 10000.0 41600.0 695.0 699.0 2.0 168304.0 2.0 5.0 0.0 15.78 ... 0 0 0 0 0 0 0 0 0 10.78
3 24700.0 65000.0 715.0 719.0 5.0 204396.0 4.0 5.0 0.0 16.06 ... 0 0 0 0 0 0 0 0 0 11.99
4 10000.0 42500.0 705.0 709.0 4.0 41166.0 0.0 4.0 0.0 31.04 ... 0 0 0 0 0 0 0 0 0 11.99

5 rows × 77 columns


In [16]:
from sklearn.model_selection import train_test_split
# Split training(labeled) and test(unlabled) 
#df_train = df_bi[df_chin_bi['cuisine_Chinese'] != 2]
#df_test = df_chin_bi[df_chin_bi['Loan_status'] == 2]

# reduce data volumn by randomly selecting instances
np.random.seed(99)

ind = np.random.randint(0, len(df2), 100000)
df_reduced = df2.ix[ind, :]

df_labeled = df_reduced[df_reduced['Target']!=2]
df_unlabeled = df_reduced[df_reduced['Target']==2]

X = df_labeled.drop('Target',axis=1)
Y = df_labeled['Target']
X_train_val, X_test, Y_train_val, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)
X_train, X_vali , Y_train , Y_vali = train_test_split(X_train_val, Y_train_val, test_size=0.25, random_state=42)

In [23]:
lr = LogisticRegression(C=c, penalty=p_optimal, random_state=99)
lr.fit(X_train, Y_train)


Out[23]:
LogisticRegression(C=0.0820849986239, class_weight=None, dual=False,
          fit_intercept=True, intercept_scaling=1, max_iter=100,
          multi_class='ovr', n_jobs=1, penalty='l1', random_state=99,
          solver='liblinear', tol=0.0001, verbose=0, warm_start=False)

In [24]:
cost_matrix = pd.DataFrame([[0.101, -0.647], [0, 0]], columns=['p', 'n'], index=['Y', 'N'])
print ("Cost matrix")
print (cost_matrix)


Cost matrix
       p      n
Y  0.101 -0.647
N  0.000  0.000

In [25]:
probabilities = lr.predict_proba(X_test)[:, 1]

In [26]:
prediction = probabilities > 0.5

# Build and print a confusion matrix
confusion_matrix_large = pd.DataFrame(metrics.confusion_matrix(Y_test, prediction, labels=[1, 0]).T,
                                columns=['p', 'n'], index=['Y', 'N'])
print (confusion_matrix_large)


      p     n
Y  4209  1522
N   329   475

In [42]:
#MANUAL ROC CALCULATION

n=[1,2,3,4,5,6,7,8,9]
TPR=[]
FPR=[]

for i in n:
    prediction = probabilities > ((i*1.0)/10)
    confusion_matrix_large = pd.DataFrame(metrics.confusion_matrix(Y_test, prediction, labels=[1, 0]).T,columns=['p', 'n'], index=['Y', 'N'])
    TPR.append(1.0*confusion_matrix_large['p']['Y']/(1.0*(confusion_matrix_large['p']['Y']+confusion_matrix_large['p']['N'])))
    FPR.append(1.0*confusion_matrix_large['n']['Y']/(1.0*(confusion_matrix_large['n']['Y']+confusion_matrix_large['n']['N'])))

In [51]:
fpr, tpr, thresholds = metrics.roc_curve(Y_test, lr.predict_proba(X_test)[:,1])

In [56]:
thresholds


Out[56]:
array([ 0.9834676 ,  0.95883673,  0.95877152, ...,  0.20111337,
        0.20065485,  0.15679253])

In [57]:
profits=[]
for i in thresholds:
    prediction = probabilities > i
    confusion_matrix_large = pd.DataFrame(metrics.confusion_matrix(Y_test, prediction, labels=[1, 0]).T,columns=['p', 'n'], index=['Y', 'N'])
    profits.append((1.0*confusion_matrix_large['p']['Y'])*cost_matrix['p']['Y']+(1.0*confusion_matrix_large['n']['Y'])*cost_matrix['n']['Y'])

In [58]:
profits


Out[58]:
[0.0,
 2.4240000000000004,
 2.5250000000000004,
 3.3929999999999998,
 3.4939999999999998,
 4.5640000000000001,
 4.6650000000000009,
 7.2910000000000004,
 7.3919999999999995,
 10.826000000000001,
 10.927,
 11.694000000000001,
 11.795,
 13.370000000000001,
 12.824000000000002,
 13.288000000000002,
 13.389000000000001,
 13.752000000000002,
 13.853000000000002,
 16.277000000000001,
 16.378,
 17.994,
 18.095000000000002,
 17.448,
 17.548999999999999,
 18.417000000000002,
 18.518000000000001,
 19.225000000000001,
 19.326000000000001,
 18.679000000000002,
 18.780000000000001,
 19.143000000000001,
 19.244,
 19.001000000000001,
 19.102000000000004,
 19.304000000000002,
 19.405000000000001,
 18.616000000000003,
 18.717000000000002,
 18.07,
 18.170999999999999,
 17.928000000000001,
 18.029,
 17.483000000000004,
 17.584000000000003,
 16.937000000000001,
 17.038,
 17.341000000000001,
 17.442,
 17.603000000000002,
 17.057000000000002,
 18.228000000000002,
 18.329000000000001,
 18.085999999999999,
 18.186999999999998,
 17.742000000000004,
 17.843000000000004,
 20.832000000000001,
 20.933000000000007,
 21.397000000000002,
 21.498000000000001,
 23.376000000000001,
 23.477,
 23.234000000000002,
 23.335000000000001,
 23.193000000000005,
 23.294000000000004,
 23.354000000000003,
 23.455000000000002,
 24.121000000000006,
 24.222000000000005,
 25.232000000000003,
 25.333000000000002,
 25.535,
 25.635999999999999,
 26.141000000000002,
 26.242000000000001,
 25.898000000000003,
 25.999000000000002,
 26.362000000000002,
 26.463000000000001,
 26.321000000000005,
 25.775000000000002,
 26.037000000000003,
 26.138000000000002,
 26.097000000000001,
 26.198,
 25.551000000000002,
 25.652000000000001,
 26.823000000000004,
 26.924000000000003,
 27.126000000000001,
 26.479000000000003,
 26.580000000000002,
 28.356999999999999,
 28.457999999999998,
 28.417000000000002,
 28.518000000000001,
 28.275000000000006,
 28.376000000000005,
 28.578000000000003,
 29.748999999999999,
 29.850000000000005,
 30.213000000000005,
 30.314000000000004,
 32.536000000000001,
 32.637,
 32.495000000000005,
 32.596000000000004,
 34.515000000000001,
 33.969000000000001,
 34.432999999999993,
 34.533999999999992,
 33.887,
 33.988000000000014,
 33.846000000000004,
 33.947000000000003,
 34.350999999999999,
 33.805,
 35.683000000000007,
 35.784000000000006,
 35.743000000000002,
 35.844000000000001,
 35.702000000000005,
 35.803000000000004,
 36.165999999999997,
 36.266999999999996,
 36.832000000000001,
 36.933,
 36.387,
 35.841000000000001,
 36.305,
 36.405999999999999,
 35.759,
 35.859999999999999,
 36.324000000000005,
 36.425000000000004,
 36.586000000000013,
 36.687000000000012,
 37.798000000000002,
 37.899000000000001,
 37.352999999999994,
 37.454000000000008,
 37.009000000000007,
 37.110000000000007,
 38.524000000000008,
 38.625000000000007,
 39.088999999999999,
 39.189999999999998,
 39.897000000000006,
 39.998000000000005,
 40.158999999999999,
 40.260000000000012,
 40.522000000000006,
 40.623000000000005,
 40.076999999999998,
 40.177999999999997,
 40.137000000000008,
 39.591000000000008,
 39.146000000000008,
 39.247000000000007,
 40.518999999999998,
 40.619999999999997,
 39.972999999999999,
 40.073999999999998,
 39.790000000000006,
 39.244000000000007,
 39.506000000000007,
 39.607000000000006,
 40.778000000000006,
 40.879000000000005,
 40.535000000000004,
 40.636000000000003,
 42.51400000000001,
 42.615000000000009,
 42.472999999999999,
 42.573999999999998,
 41.927,
 42.027999999999999,
 42.492000000000004,
 42.593000000000004,
 42.350000000000001,
 42.451000000000001,
 42.107000000000014,
 41.561000000000007,
 41.722000000000001,
 41.823,
 41.378,
 41.478999999999999,
 40.832000000000001,
 40.933,
 41.498000000000005,
 41.599000000000004,
 41.052999999999997,
 41.153999999999996,
 41.012000000000008,
 40.466000000000008,
 40.021000000000008,
 40.122000000000007,
 42.000000000000007,
 42.101000000000006,
 42.060000000000002,
 42.161000000000001,
 44.039000000000009,
 44.140000000000008,
 43.594000000000008,
 43.695000000000007,
 43.250000000000007,
 43.351000000000006,
 42.704000000000008,
 42.158000000000001,
 41.813999999999993,
 41.914999999999992,
 41.672000000000011,
 41.77300000000001,
 42.135999999999996,
 42.236999999999995,
 41.994000000000014,
 42.095000000000013,
 42.457999999999998,
 42.559000000000012,
 43.468000000000004,
 43.569000000000003,
 43.629000000000005,
 43.730000000000004,
 44.033000000000001,
 44.134,
 45.447000000000003,
 45.548000000000002,
 45.00200000000001,
 45.103000000000009,
 44.456000000000003,
 44.557000000000002,
 44.213000000000008,
 44.314000000000007,
 44.920000000000016,
 45.021000000000015,
 45.182000000000002,
 45.283000000000001,
 44.736999999999995,
 44.837999999999994,
 44.797000000000011,
 44.89800000000001,
 46.87700000000001,
 46.978000000000009,
 46.331000000000017,
 46.432000000000016,
 45.88600000000001,
 45.987000000000009,
 48.613000000000014,
 48.714000000000013,
 48.370000000000005,
 48.471000000000004,
 47.925000000000011,
 48.02600000000001,
 48.228000000000009,
 47.783000000000001,
 47.884,
 48.146000000000001,
 48.247,
 47.600000000000009,
 47.701000000000008,
 47.155000000000001,
 47.256,
 46.811000000000007,
 46.912000000000006,
 46.366,
 46.466999999999999,
 46.022000000000006,
 46.123000000000005,
 45.88000000000001,
 45.981000000000009,
 46.243000000000009,
 46.344000000000008,
 45.697000000000017,
 45.15100000000001,
 45.210999999999999,
 45.311999999999998,
 44.968000000000004,
 45.069000000000003,
 44.825999999999993,
 44.926999999999992,
 45.128999999999991,
 45.088000000000022,
 45.189000000000021,
 45.39100000000002,
 44.845000000000013,
 44.946000000000012,
 44.299000000000007,
 44.400000000000006,
 44.056000000000012,
 44.157000000000011,
 43.611000000000004,
 43.712000000000003,
 43.570000000000007,
 43.671000000000006,
 43.125,
 43.225999999999999,
 42.98299999999999,
 43.083999999999989,
 43.043000000000021,
 43.14400000000002,
 42.497000000000014,
 42.598000000000013,
 42.800000000000011,
 42.90100000000001,
 42.658000000000001,
 42.759,
 43.021000000000001,
 43.122,
 41.828000000000003,
 41.281999999999996,
 40.836999999999989,
 40.290999999999997,
 40.149000000000015,
 39.603000000000023,
 38.956000000000017,
 39.057000000000016,
 39.016000000000005,
 39.117000000000004,
 39.783000000000001,
 39.236999999999995,
 39.398000000000025,
 39.499000000000024,
 41.923000000000002,
 42.024000000000001,
 42.933000000000021,
 42.387000000000015,
 41.942000000000007,
 42.043000000000006,
 42.911000000000001,
 43.012,
 42.566999999999993,
 42.020999999999987,
 41.373999999999995,
 40.827999999999989,
 41.292000000000016,
 41.393000000000015,
 41.251000000000005,
 41.352000000000004,
 41.310999999999993,
 41.411999999999992,
 40.966999999999999,
 41.067999999999998,
 40.420999999999992,
 40.521999999999991,
 40.72399999999999,
 40.582000000000022,
 40.683000000000021,
 40.64200000000001,
 40.743000000000009,
 41.147000000000006,
 41.248000000000005,
 40.701999999999998,
 40.802999999999997,
 40.257000000000005,
 40.358000000000004,
 39.912999999999997,
 39.367000000000004,
 38.921999999999997,
 39.022999999999996,
 39.184000000000012,
 39.285000000000011,
 38.840000000000018,
 38.941000000000017,
 38.294000000000011,
 38.39500000000001,
 37.748000000000019,
 37.849000000000018,
 38.212000000000003,
 37.019000000000005,
 36.573999999999998,
 36.674999999999997,
 36.330999999999989,
 36.431999999999988,
 36.39100000000002,
 36.492000000000019,
 35.946000000000012,
 36.047000000000011,
 35.501000000000019,
 34.308000000000007,
 34.065000000000012,
 34.166000000000011,
 33.519000000000005,
 33.620000000000005,
 33.175000000000011,
 32.528000000000006,
 32.629000000000005,
 32.486999999999995,
 32.587999999999994,
 32.042000000000002,
 31.495999999999995,
 30.950000000000003,
 30.403999999999996,
 30.161000000000001,
 30.262000000000029,
 29.817000000000007,
 29.918000000000006,
 29.372000000000014,
 28.179000000000002,
 28.441000000000003,
 28.542000000000002,
 28.299000000000007,
 27.753000000000014,
 27.206999999999994,
 27.307999999999993,
 26.418000000000006,
 25.871999999999986,
 26.336000000000013,
 26.437000000000012,
 25.79000000000002,
 25.89100000000002,
 26.960999999999984,
 27.061999999999983,
 26.414999999999992,
 26.717999999999989,
 26.819000000000017,
 26.475000000000023,
 26.576000000000022,
 26.030000000000001,
 26.131,
 25.787000000000006,
 25.888000000000005,
 25.241000000000014,
 24.695000000000022,
 24.552999999999997,
 24.653999999999996,
 25.461999999999989,
 25.562999999999988,
 25.016999999999996,
 25.117999999999995,
 24.673000000000002,
 24.774000000000029,
 24.12700000000001,
 24.228000000000009,
 23.884000000000015,
 23.985000000000014,
 23.338000000000022,
 23.439000000000021,
 22.792000000000002,
 24.508999999999986,
 24.609999999999985,
 26.084000000000003,
 26.185000000000002,
 25.740000000000009,
 25.841000000000008,
 25.194000000000017,
 25.295000000000016,
 25.051999999999992,
 25.152999999999992,
 24.707999999999998,
 24.162000000000006,
 23.514999999999986,
 22.968999999999994,
 22.322000000000003,
 22.423000000000002,
 21.775999999999982,
 21.876999999999981,
 22.038000000000011,
 21.492000000000019,
 21.046999999999997,
 21.147999999999996,
 21.551999999999992,
 21.652999999999992,
 21.006,
 21.106999999999999,
 20.561000000000007,
 20.662000000000006,
 20.116000000000014,
 19.569999999999993,
 18.923000000000002,
 19.730999999999995,
 19.185000000000002,
 18.841000000000008,
 18.942000000000007,
 18.295000000000016,
 18.396000000000015,
 17.951000000000022,
 18.052000000000021,
 18.254000000000019,
 18.355000000000018,
 19.668000000000006,
 19.769000000000005,
 20.031000000000006,
 19.485000000000014,
 18.939000000000021,
 19.04000000000002,
 20.009000000000015,
 19.462999999999994,
 19.522999999999996,
 19.623999999999995,
 18.977000000000004,
 18.431000000000012,
 18.289000000000016,
 17.743000000000023,
 17.298000000000002,
 17.399000000000001,
 17.055000000000007,
 17.156000000000006,
 16.812000000000012,
 16.913000000000011,
 16.36699999999999,
 16.467999999999989,
 16.325999999999993,
 16.426999999999992,
 16.183999999999997,
 16.284999999999997,
 15.638000000000005,
 15.092000000000013,
 14.849000000000018,
 14.950000000000017,
 14.606000000000023,
 14.707000000000022,
 14.90900000000002,
 14.262,
 14.363,
 13.716000000000008,
 12.522999999999996,
 12.078000000000003,
 12.179000000000002,
 11.532000000000011,
 11.63300000000001,
 11.188000000000017,
 11.289000000000016,
 10.641999999999996,
 10.742999999999995,
 10.944999999999993,
 11.045999999999992,
 10.5,
 10.600999999999999,
 9.9540000000000077,
 10.055000000000007,
 9.407999999999987,
 9.7109999999999843,
 9.1650000000000205,
 9.2250000000000227,
 9.3260000000000218,
 8.9819999999999993,
 9.0829999999999984,
 8.436000000000007,
 8.5370000000000061,
 8.092000000000013,
 8.1930000000000121,
 7.9499999999999886,
 8.0509999999999877,
 7.4039999999999964,
 7.5049999999999955,
 6.51400000000001,
 6.6150000000000091,
 6.5740000000000123,
 6.6750000000000114,
 6.02800000000002,
 6.2300000000000182,
 6.3310000000000173,
 6.0880000000000223,
 6.1890000000000214,
 5.7439999999999998,
 5.8449999999999989,
 5.1980000000000075,
 5.2990000000000066,
 4.6520000000000152,
 4.7530000000000143,
 4.3079999999999927,
 4.4089999999999918,
 4.7119999999999891,
 4.1659999999999968,
 3.9230000000000018,
 3.3770000000000095,
 3.8410000000000082,
 3.9420000000000073,
 3.396000000000015,
 2.8500000000000227,
 2.203000000000003,
 3.1119999999999948,
 3.2129999999999939,
 3.3739999999999952,
 3.4749999999999943,
 2.929000000000002,
 2.3830000000000098,
 2.4430000000000121,
 2.5440000000000111,
 2.4020000000000152,
 2.5030000000000143,
 2.5629999999999882,
 2.6639999999999873,
 2.117999999999995,
 2.2189999999999941,
 1.875,
 1.3290000000000077,
 0.88399999999998613,
 0.98500000000001364,
 0.33800000000002228,
 0.43900000000002137,
 0.29700000000002547,
 0.39800000000002456,
 -0.046999999999997044,
 -2.5339999999999918,
 -2.7769999999999868,
 -2.6759999999999877,
 -3.3230000000000075,
 -2.8180000000000121,
 -3.3640000000000043,
 -2.2939999999999827,
 -2.1929999999999836,
 -2.6379999999999768,
 -2.5369999999999777,
 -2.3349999999999795,
 -2.2339999999999804,
 -1.9720000000000084,
 -2.5180000000000007,
 -2.0539999999999736,
 -1.9529999999999745,
 -2.3979999999999961,
 -2.296999999999997,
 -2.8429999999999893,
 -3.3889999999999816,
 -3.9350000000000023,
 -4.4809999999999945,
 -4.9259999999999877,
 -4.8249999999999886,
 -5.3709999999999809,
 -5.2699999999999818,
 -5.1090000000000089,
 -5.6550000000000011,
 -6.3019999999999925,
 -7.4950000000000045,
 -8.1419999999999959,
 -8.0409999999999968,
 -8.4860000000000184,
 -8.3849999999999909,
 -9.0319999999999823,
 -8.4259999999999877,
 -8.97199999999998,
 -9.4170000000000016,
 -9.3160000000000025,
 -9.3569999999999993,
 -9.2560000000000002,
 -9.5999999999999943,
 -9.4989999999999952,
 -10.145999999999987,
 -10.692000000000007,
 -11.338999999999999,
 -11.238,
 -11.884999999999991,
 -11.783999999999992,
 -11.825000000000017,
 -11.72399999999999,
 -11.057999999999993,
 -11.603999999999985,
 -11.64500000000001,
 -11.544000000000011,
 -12.090000000000003,
 -14.576999999999998,
 -15.22399999999999,
 -15.12299999999999,
 -15.669000000000011,
 -15.568000000000012,
 -16.013000000000005,
 -15.912000000000006,
 -16.154999999999973,
 -16.053999999999974,
 -16.700999999999993,
 -17.893999999999977,
 -18.137,
 -18.036000000000001,
 -17.733000000000004,
 -17.632000000000005,
 -18.278999999999996,
 -18.824999999999989,
 -19.370999999999981,
 -19.269999999999982,
 -19.614000000000004,
 -19.513000000000005,
 -18.442999999999984,
 -18.988999999999976,
 -18.424000000000007,
 -18.969999999999999,
 -19.61699999999999,
 -20.163000000000011,
 -20.406000000000006,
 -20.305000000000007,
 -20.951999999999998,
 -20.850999999999999,
 -20.992999999999967,
 -20.891999999999967,
 -21.538999999999987,
 -21.437999999999988,
 -21.98399999999998,
 -22.529999999999973,
 -23.075999999999993,
 -22.974999999999994,
 -23.520999999999987,
 -23.419999999999987,
 -23.460999999999984,
 -23.359999999999985,
 -24.007000000000005,
 -24.552999999999997,
 -24.391999999999996,
 -24.290999999999997,
 -24.938000000000017,
 -24.837000000000018,
 -25.38300000000001,
 -25.282000000000011,
 -25.726999999999975,
 -26.919999999999987,
 -26.758999999999986,
 -26.657999999999987,
 -27.304999999999978,
 -27.850999999999971,
 -28.396999999999963,
 -28.295999999999964,
 -28.943000000000012,
 -28.337000000000018,
 -28.236000000000018,
 -28.88300000000001,
 -28.782000000000011,
 -29.227000000000004,
 -29.126000000000005,
 -29.570999999999998,
 -30.11699999999999,
 -30.763999999999982,
 -30.662999999999982,
 -31.209000000000032,
 -31.108000000000033,
 -31.755000000000024,
 -31.653999999999996,
 -31.451999999999998,
 -32.09899999999999,
 -31.99799999999999,
 -32.341999999999985,
 -32.240999999999985,
 -32.786999999999978,
 -33.33299999999997,
 -33.979999999999961,
 -33.878999999999962,
 -34.324000000000012,
 -34.870000000000005,
 -35.516999999999996,
 -36.062999999999988,
 -36.103999999999985,
 -36.002999999999986,
 -36.548999999999978,
 -36.447999999999979,
 -36.489000000000033,
 -36.388000000000034,
 -37.682000000000016,
 -38.22799999999998,
 -38.874999999999972,
 -39.420999999999964,
 -39.56299999999996,
 -39.461999999999961,
 -39.806000000000012,
 -39.705000000000013,
 -40.352000000000004,
 -40.150000000000006,
 -40.049000000000007,
 -39.585000000000008,
 -39.484000000000009,
 -39.727000000000004,
 -39.625999999999976,
 -38.85899999999998,
 -38.757999999999981,
 -39.404999999999973,
 -39.303999999999974,
 -39.951000000000022,
 -39.850000000000023,
 -39.648000000000025,
 -39.547000000000025,
 -40.093000000000018,
 -39.992000000000019,
 -40.538000000000011,
 -40.437000000000012,
 -41.084000000000003,
 -40.983000000000004,
 -41.427999999999997,
 -41.326999999999998,
 -41.771999999999991,
 -41.670999999999964,
 -42.317999999999955,
 -42.216999999999956,
 -42.864000000000004,
 -42.763000000000005,
 -43.207999999999998,
 -43.106999999999999,
 -43.551999999999992,
 -43.450999999999993,
 -44.097999999999985,
 -45.290999999999968,
 -45.93799999999996,
 -46.484000000000009,
 -47.030000000000001,
 -46.929000000000002,
 -46.525000000000006,
 -46.424000000000007,
 -46.667000000000002,
 -46.566000000000003,
 -47.212999999999994,
 -47.111999999999995,
 -47.758999999999986,
 -47.657999999999987,
 -48.10299999999998,
 -48.001999999999981,
 -49.296000000000021,
 -49.538999999999987,
 -49.437999999999988,
 -49.579999999999984,
 -49.478999999999985,
 -50.125999999999976,
 -50.671999999999969,
 -51.116999999999962,
 -51.663000000000011,
 -52.310000000000002,
 -52.209000000000003,
 -52.754999999999995,
 -52.653999999999996,
 -53.300999999999988,
 -53.199999999999989,
 -53.745999999999981,
 -53.644999999999982,
 -54.089999999999975,
 -53.988999999999976,
 -53.828000000000031,
 -53.727000000000032,
 -53.121000000000009,
 -54.313999999999993,
 -54.556999999999988,
 -54.455999999999989,
 -55.10299999999998,
 -55.648999999999972,
 -56.093999999999966,
 -55.992999999999967,
 -56.640000000000015,
 -56.539000000000016,
 -56.984000000000009,
 -56.88300000000001,
 -56.722000000000008,
 -56.621000000000009,
 -57.268000000000001,
 -57.813999999999993,
 -56.84499999999997,
 -56.743999999999971,
 -56.339999999999975,
 -58.180000000000007,
 -58.625,
 -58.524000000000001,
 -58.968999999999994,
 -59.514999999999986,
 -59.95999999999998,
 -60.506000000000029,
 -61.15300000000002,
 -61.052000000000021,
 -61.699000000000012,
 -61.496999999999986,
 -61.395999999999987,
 -61.739999999999981,
 -61.638999999999982,
 -61.780999999999977,
 -61.679999999999978,
 -62.124999999999972,
 -63.318000000000012,
 -63.864000000000004,
 -63.763000000000005,
 -63.905000000000001,
 -63.804000000000002,
 -64.450999999999993,
 -64.349999999999994,
 -64.49199999999999,
 -64.390999999999991,
 -64.734999999999957,
 -65.281000000000006,
 -65.221000000000004,
 -65.766999999999996,
 -65.908999999999992,
 -65.807999999999993,
 -66.454999999999984,
 -66.353999999999985,
 -66.697999999999979,
 -66.59699999999998,
 -67.243999999999971,
 -67.142999999999972,
 -67.588000000000022,
 -67.487000000000023,
 -67.831000000000017,
 -67.730000000000018,
 -68.175000000000011,
 -68.074000000000012,
 -68.721000000000004,
 -68.620000000000005,
 -68.661000000000001,
 -68.560000000000002,
 -69.206999999999994,
 -69.105999999999995,
 -69.652000000000044,
 -69.551000000000045,
 -70.097000000000037,
 -69.996000000000038,
 -71.29000000000002,
 -71.189000000000021,
 -71.734999999999957,
 -72.280999999999949,
 -72.725999999999942,
 -72.624999999999943,
 -73.271999999999991,
 -75.758999999999958,
 -76.203999999999951,
 -76.102999999999952,
 -76.043000000000006,
 -75.942000000000007,
 -76.286000000000001,
 -76.185000000000002,
 -76.831999999999994,
 -76.730999999999995,
 -77.377999999999986,
 -77.276999999999987,
 -77.317999999999984,
 -77.863999999999976,
 -78.510999999999967,
 -78.409999999999968,
 -77.803999999999974,
 -77.702999999999975,
 -77.946000000000026,
 -77.845000000000027,
 -78.492000000000019,
 -78.39100000000002,
 -78.937000000000012,
 -78.836000000000013,
 -79.382000000000005,
 -79.281000000000006,
 -79.927999999999997,
 -81.222000000000037,
 -81.121000000000038,
 -81.768000000000029,
 -81.66700000000003,
 -82.213000000000022,
 -82.112000000000023,
 -82.658000000000015,
 -83.204000000000008,
 -83.75,
 -83.649000000000001,
 -83.447000000000003,
 -84.093999999999994,
 -83.992999999999995,
 -84.539000000000044,
 -84.438000000000045,
 -85.085000000000036,
 -84.984000000000037,
 -85.428999999999974,
 -85.327999999999975,
 -85.873999999999967,
 -86.419999999999959,
 -87.06699999999995,
 -87.612999999999943,
 -87.956999999999994,
 -88.502999999999986,
 -89.149999999999977,
 -89.69599999999997,
 -89.938999999999965,
 -89.837999999999965,
 -90.52600000000001,
 -90.425000000000011,
 -90.567000000000007,
 -90.466000000000008,
 -91.012,
 -91.557999999999993,
 -91.295999999999992,
 -91.194999999999993,
 -91.841999999999985,
 -93.035000000000025,
 -93.581000000000017,
 -93.480000000000018,
 -93.824000000000012,
 -93.723000000000013,
 -94.269000000000005,
 -94.168000000000006,
 -94.814999999999998,
 -94.713999999999999,
 -94.310000000000002,
 -94.209000000000003,
 -94.451999999999998,
 -94.350999999999999,
 -94.290999999999997,
 -94.189999999999998,
 -94.836999999999989,
 -94.73599999999999,
 -94.47399999999999,
 -95.019999999999982,
 -95.060999999999979,
 -94.95999999999998,
 -94.757999999999981,
 -95.202999999999975,
 -95.101999999999975,
 -93.829999999999984,
 -95.023000000000025,
 -95.064000000000021,
 -94.963000000000022,
 -94.660000000000025,
 -96.5,
 -96.742999999999995,
 -97.935999999999979,
 -98.58299999999997,
 ...]

In [64]:
plt.plot(thresholds,profits)
plt.xlabel("Threshold")
plt.ylabel("Profit")
plt.title("Profits")


Out[64]:
<matplotlib.text.Text at 0x124c08cd0>

In [ ]: