资源简介
波士顿房价预测的BP神经网络实现
1) 训练数据 housing.csv 使用波士顿房价数据
2) 使用Python代码实现前向和后向传播
3) 损失函数使用方差
代码片段和文件信息
# Package imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def clc_accuracy(y_true y_predict):
“““ use sklearn to calcuate the R2 score“““
from sklearn.metrics import r2_score
score = r2_score(y_true y_predict)
return score
def sigmoid(Z):
“““
Compute the sigmoid of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- sigmoid(x)
“““
A = 1.0/(1.0+np.exp(-Z))
return A
def sigmoid_backward(dA cache):
“““
Implement the backward propagation for a single SIGMOID unit.
Arguments:
dA -- post-activation gradient of any shape
cache -- ‘Z‘ where we store for computing backward propagation efficiently
Returns:
dZ -- Gradient of the cost with respect to Z
“““
Z = cache
s = 1.0 / (1.0 + np.exp(-Z))
dZ = dA * s * (1 - s)
assert (dZ.shape == Z.shape)
return dZ
def relu(Z):
“““
Implement the RELU function.
Arguments:
Z -- Output of the linear layer of any shape
Returns:
A -- Post-activation parameter of the same shape as Z
cache -- a python dictionary containing “A“ ; stored for computing the backward pass efficiently
“““
A = np.maximum(0 Z)
assert (A.shape == Z.shape)
return A
def relu_backward(dA cache):
“““
Implement the backward propagation for a single RELU unit.
Arguments:
dA -- post-activation gradient of any shape
cache -- ‘Z‘ where we store for computing backward propagation efficiently
Returns:
dZ -- Gradient of the cost with respect to Z
“““
Z = cache
dZ = np.array(dA copy=True) # just converting dz to a correct object.
# When z <= 0 you should set dz to 0 as well.
dZ[Z <= 0] = 0
assert (dZ.shape == Z.shape)
return dZ
def layer_sizes(X Y):
“““
Arguments:
X -- input dataset of shape (input size number of examples)
Y -- labels of shape (output size number of examples)
Returns:
n_x -- the size of the input layer
n_h -- the size of the hidden layer
n_y -- the size of the output layer
“““
n_x = X.shape[0] # size of input layer number of features ?
n_h = 4
n_y = Y.shape[0] # size of output layer
return (n_x n_h n_y)
def initialize_parameters(n_x n_h n_y):
“““
Argument:
n_x -- size of the input layer
n_h -- size of the hidden layer
n_y -- size of the output layer
Returns:
params -- python dictionary containing your parameters:
W1 -- weight matrix of shape (n_h n_x)
b1 -- bias vector of shape (n_h 1)
W2 -- weight matrix of shape (n_y n_h)
b2 -- bias vector of shape (n_y 1)
“““
np.random.seed(2) # we set up a seed so that your output matches ours although the initialization is random.
W1 = np.random.randn(n_h n_x) * 0.01
b1 = np.zeros((n_h 1))
W2 = np.random.r
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11828 2018-08-29 08:47 pred_nn.py
文件 12435 2018-04-28 00:36 housing.csv
相关资源
- PyQwt-5.2.1-cp37-cp37m-win_amd64.whl
- Python3.x+Pyqt5实现主窗体与子窗体相互
- Python实现动物识别产生式系统
- py2exe for 2.764位
- testbrowse.py
- python实现的k-means算法
- 问卷星爬虫带验证码
- python LDA学习
- 随机森林的代码实现和相应的数据集
-
Python sc
ripts For ABAQUS: Learn By Example - 小甲鱼零基础入门学习Python视频教程
- 基于tensorflow的二分类的python实现注释
- 《PyTorch生成对抗网络编程》思维导图
- 基于Python实现LFM种子传播算法
- 密码学重合指数计算python实现
- fire_finder.rar
- python新手算法函数思想入门项目,包
- 已知空间坐标和对应的属性,利用p
- 小甲鱼pythons视频+课件+源代码(96天)
- 找出最长的句子最长的单词
- 如何封装一个带传参的python程序成可
- 疯狂的python学习笔记
- wxPython写的类似qq截图的小程序
- Python3.6.4+Django2.0.2 单表的增删改查和
- python三边定位模块
- Python帮助手册CHM版
- MIC数据关联性挖掘算法Python源码
- 船舶AIS数据轨迹可视化python代码.rar
- python mysql 简单银行存取款转账系统
- cpu_nms.py
评论
共有 条评论