《Python金融大数据风控建模实战》 第15章 神经网络模型
本章引言
神经网络模型是深度学习的基础。 从神经网络的结构中可以发现,模型的未知参数就是一系列权重值,网络结构越复杂其非线性表达能力越强,同时需要学习的权重就越多。误差反向传播算法(error BackPropagation,BP算法)是神经网络的学习策略中最著名的算法代表,不仅用于前馈神经网络的学习,还可以用于其他类型的神经网络,如递归神经网络的训练,而且在深度学习中也是采用BP算法进行网络训练的。
Python代码实现及注释
# 第15章:神经网络模型
import os
import sys
#path = __file__
#path = os.path.abspath(path + ((os.sep + '..') * 2))
#sys.path.append(path)
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
import variable_encode as var_encode
from sklearn.metrics import confusion_matrix,recall_score, auc, roc_curve,precision_score,accuracy_score
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.sans-serif']=['SimHei'] # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False # 正常显示负号
import warnings
warnings.filterwarnings("ignore") ##忽略警告
##数据读取
def data_read(data_path,file_name):
df = pd.read_csv( os.path.join(data_path, file_name), delim_whitespace = True, header = None )
##变量重命名
columns = ['status_account','duration','credit_history','purpose', 'amount',
'svaing_account', 'present_emp', 'income_rate', 'personal_status',
'other_debtors', 'residence_info', 'property', 'age',
'inst_plans', 'housing', 'num_credits',
'job', 'dependents', 'telephone', 'foreign_worker',