- Neural Networks with Keras Cookbook
- V Kishore Ayyadevara
- 305字
- 2021-07-02 12:46:32
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.
- 深入核心的敏捷開發:ThoughtWorks五大關鍵實踐
- C++案例趣學
- Getting started with Google Guava
- MongoDB for Java Developers
- 數據結構(Python語言描述)(第2版)
- 云計算通俗講義(第3版)
- Learning Network Forensics
- 青少年Python編程入門
- Android開發:從0到1 (清華開發者書庫)
- R語言與網絡輿情處理
- Python Data Structures and Algorithms
- 編程菜鳥學Python數據分析
- OpenStack Networking Essentials
- Oracle實用教程
- R語言數據挖掘:實用項目解析