BP网络识别钓鱼网站的应用
声明
(1)该博文为个人的学习总结以及学习成果的应用,具体引用的资料请看参考文献。
( 2 )数据来源:https://archive.ics.uci.edu/ml/datasets/Website+Phishing
代码
1、定义相关函数
import numpy as np
# sigmoid函数
def sig(x):
return 1 / (1 + np.exp(-x))
# sigoid函数的一阶导数
def partial_sig(x):
out = np.multiply(sig(x), (np.ones(x.shape) - sig(x))) #np.multiplt()对应位置的乘积
return out
# 计算隐含层的输入
def hidden_in(feature, w0, b0):
return feature * w0 + b0
# 计算隐含层的输出
def hidden_out(hidden_in):
return sig(hidden_in)
# 计算输出层的输入
def predict_in(hidden_out, w1, b1):
return hidden_out * w1 + b1
def predict_out(predict_in):
return sig(predict_in)
模型训练函数
def bp_train(feature, label, n_hidden, maxCycle, alpha, n_output):
m, n = np.shape(feature)
# 1、初始化权重和偏置
np.random.seed(2019)
w0 = np.mat(np.random.normal(0, 1, size = (n, n_hidden)))
b0 = np.mat(np