官术网_书友最值得收藏!

How to do it...

The model fitting process is done by following these steps (Please refer to Credit default prediction.ipynb file in GitHub while implementing the code):

history = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=10, batch_size=1024, verbose=1,class_weight = {0:1,1:100})

Note that, in the preceding code snippet, we created a dictionary with the weights that correspond to the distinct classes in output that is then passed as an input to the class_weight parameter.

The preceding step ensures that we assign a weightage of 100 to calculating the loss value when the actual outcome is 1 and a weightage of 1 when calculating the loss value when the actual outcome is 0.

The variation of accuracy and loss values over increasing epochs is as follows:

Note that the accuracy values are much lower in this iteration, as we are predicting more number of data points to have a value 1 than in the scenario of equal weightage to both classes.

Once the model is fitted, let's proceed and check for the number of actual defaulters that are captured in the top 10% of predictions, as follows:

pred = model.predict(X_test)
test_data = pd.DataFrame([y_test[:,1]]).T
test_data['pred']=pred[:,1]
test_data = test_data.reset_index(drop='index')
test_data = test_data.sort_values(by='pred',ascending=False)
test_data.columns = ['Defaultin2yrs','pred']
print(test_data[:4500]['Defaultin2yrs'].sum())

You notice that compared to the previous scenario of 1,580 customers being captured in the the top 10%, we have 1,640 customers captured in the top 10% in this scenario, and thus a better outcome for the objective we have set where we have captured 36% of all defaulters in top 10% of high probable customers in this scenario, when compared to 35% in the previous scenario.

It is not always necessary that accuracy improves as we increase class weights. Assigning class weights is a mechanism to give higher weightage to the prediction of our interest.
主站蜘蛛池模板: 乐清市| 银川市| 集安市| 合作市| 和平区| 汉源县| 朔州市| 宁陵县| 湘阴县| 沙洋县| 临沂市| 海阳市| 常德市| 泸定县| 定陶县| 肇州县| 政和县| 盘锦市| 大丰市| 富川| 积石山| 天津市| 荔浦县| 崇义县| 哈尔滨市| 汝南县| 卢氏县| 曲周县| 泾川县| 平南县| 开鲁县| 凉山| 英吉沙县| 邵东县| 朝阳区| 剑川县| 方山县| 曲松县| 哈尔滨市| 房山区| 大荔县|