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

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.
主站蜘蛛池模板: 三亚市| 织金县| 漠河县| 马尔康县| 惠东县| 民勤县| 保定市| 安远县| 罗城| 浠水县| 革吉县| 文成县| 江孜县| 青川县| 龙井市| 武宁县| 马鞍山市| 陆河县| 安岳县| 资溪县| 基隆市| 广汉市| 宁陵县| 方山县| 临澧县| 巫溪县| 崇左市| 新竹市| 嵊州市| 饶平县| 建瓯市| 沾化县| 托克托县| 论坛| 彝良县| 鸡东县| 平凉市| 清水县| 凤山市| 都匀市| 泰来县|