- 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.
- 嵌入式軟件系統測試:基于形式化方法的自動化測試解決方案
- 深入淺出Windows API程序設計:編程基礎篇
- Internet of Things with the Arduino Yún
- 深入理解Elasticsearch(原書第3版)
- Getting Started with Gulp
- Java SE實踐教程
- Python程序設計與算法基礎教程(第2版)(微課版)
- Windows Phone 8 Game Development
- Node.js從入門到精通
- 深入解析Java編譯器:源碼剖析與實例詳解
- 實驗編程:PsychoPy從入門到精通
- Building Apple Watch Projects
- 現代C++語言核心特性解析
- Microsoft XNA 4.0 Game Development Cookbook
- 菜鳥成長之路