资源简介
机器学习,神经网络多层感知器实现,稍事修改即可实现手写数字识别,鸢尾花识别实验等
代码片段和文件信息
import math
import random
import matplotlib.pyplot as plt
import numpy as np
class moon_data_class(object):
def __init__(self N d r w): # 总数 距离 半径 宽度
self.N = N
self.w = w
self.d = d
self.r = r
def dbmoon(self):
N1 = 10 * self.N
N = self.N
r = self.r
w2 = self.w / 2
d = self.d
done = True
data = np.empty(0) #创建空的数组
while done:
# generate Rectangular data
tmp_x = 2 * (r + w2) * (np.random.random([N1 1]) - 0.5)
tmp_y = (r + w2) * np.random.random([N1 1])
tmp = np.concatenate((tmp_x tmp_y) axis=1)
tmp_ds = np.sqrt(tmp_x * tmp_x + tmp_y * tmp_y)
# generate double moon data ---upper
idx = np.logical_and(tmp_ds > (r - w2) tmp_ds < (r + w2))
idx = (idx.nonzero())[0]
if data.shape[0] == 0:
data = tmp.take(idx axis=0)
else:
data = np.concatenate((data tmp.take(idx axis=0)) axis=0)
if data.shape[0] >= N:
done = False
# print (data)
db_moon = data[0:N :]
# print (db_moon)
# generate double moon data ----down
data_t = np.empty([N 2])
data_t[: 0] = data[0:N 0] + r
data_t[: 1] = -data[0:N 1] - d
db_moon = np.concatenate((db_moon data_t) axis=0)
return db_moon
def rand(a b):
return (b - a) * random.random() + a #随机数
def sigmoid(x): # 定义激活函数 sigmoid函数 logistics函数 逻辑斯弟
return 1.0 / (1.0 + math.exp(-x))
def sigmoid_derivate(x): # 定义激活函数的导数
return x * (1 - x) # sigmoid函数的导数
class BP_NET(object): # 定义神经网络
def __init__(self):
self.input_n = 0 #输入层+偏置项 三维 1,xy
self.hidden_n = 0 #隐藏层数量 5
self.output_n = 0 #输出层数量 1
self.input_cells = [] #矩阵化 输入层输出 隐藏层输入
self.bias_input_n = []
self.bias_output = []
self.hidden_cells = [] #隐藏层激活函数值,及隐藏层输出
self.output_cells = [] # 输出层输出
self.input_weights = []
self.output_weights = []
self.input_correction = []
self.output_correction = []
def setup(self ni nh no): #初始化神经网络:输入层,隐藏层,输出层元素个数
self.input_n = ni + 1 # 输入层+偏置项 3
self.hidden_n = nh #隐藏层数量 5
self.output_n = no #输出层数量 1
self.input_cells = [1.0] * self.input_n #矩阵化
self.hidden_cells = [1.0] * self.hidden_n
self.output_cells = [1.0] * self.output_n
self.input_weights = np.zeros((self.input_nself.hidden_n)) #隐藏层 权值 3*5
self.output_weights = np.zeros((self.hidden_nself.output_n)) #输出层 权值 5*1
for i in range(self.input_n): # 3*5
for h in range(self.hidden_n):
self.input_weights[i][h] = rand(-0.2 0.2) # 隐藏层 权值 5*3 赋值随机数
- 上一篇:python爬取链家网租房数据
- 下一篇:python架构师课程
相关资源
- Deep Learning Cookbook_ practical recipes to g
- deeplearningPID
- deep learning with python 中文版
- Introduction to machine learning with python (
- Learning Data Mining With Python book 代码及数
- Introduction to Machine Learning with Python.p
- Deep Learning for Natural Language Processing
- Deep Learning With Python - Jason Brownlee
-
Python-汉字的神经风格转移Neuralst
y - Python-神经网络模型能够从音频演讲中
- NeMo_脉冲神经网络工具_spiking neural n
- 《深度学习Deep Learning with Python 2017》
- Learning Data Mining with Python - Second Edit
- 《深入浅出Python机器学习》源程序.
- Practical Machine Learning and Image Processin
- python+keras+deeplearning
- 基于Python的深度学习
- Hands-On Unsupervised Learning Using Python.pd
- Python Machine Learning( Python机器学习.
- Hands On Machine Learning with Python: Concept
- XGBoost with Python (book + complete code fo
- Python for ProbabilityStatisticsand Machine Le
- MLP/RNN/LSTM模型进行IMDb情感分析
- deep_learning_with_python.pdf(Jason Brownlee)
- python machine learning(2nd
- Deep Learning with Python by Francois Chollet (
- master machine learning一套书籍
- Hands-On_Reinforcement_Learning_with_Python
- Make Your Own Neural Network - 搭建自己的神
- BrownLee Better Deep Learning
评论
共有 条评论