【Python】scikit-learn机器学习(二)——BP神经网络
来源:互联网 发布:网络连接异常 编辑:程序博客网 时间:2024/05/23 17:43
环境
Mac os
python3.6
代码
# coding:utf-8"""Author: roguesirDate: 2017/8/30GitHub: https://roguesir.github.comBlog: http://blog.csdn.net/roguesir"""from __future__ import print_functionimport tensorflow as tfimport numpy as npdef add_layer(inputs, in_size, out_size, activation_function=None): # add one more layer and return the output of this layer Weights = tf.Variable(tf.random_normal([in_size, out_size])) biases = tf.Variable(tf.zeros([1, out_size]) + 0.1) Wx_plus_b = tf.matmul(inputs, Weights) + biases if activation_function is None: outputs = Wx_plus_b else: outputs = activation_function(Wx_plus_b) return outputs# Make up some real datax_data = np.linspace(-1,1,300)[:, np.newaxis]noise = np.random.normal(0, 0.05, x_data.shape)y_data = np.square(x_data) - 0.5 + noise# define placeholder for inputs to networkxs = tf.placeholder(tf.float32, [None, 1])ys = tf.placeholder(tf.float32, [None, 1])# add hidden layerl1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu)# add output layerprediction = add_layer(l1, 10, 1, activation_function=None)# the error between prediction and real dataloss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction), reduction_indices=[1]))train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)# important stepif int((tf.__version__).split('.')[1]) < 12: init = tf.initialize_all_variables()else: init = tf.global_variables_initializer()sess = tf.Session()sess.run(init)for i in range(1000): # training sess.run(train_step, feed_dict={xs: x_data, ys: y_data}) if i % 50 == 0: # to see the step improvement print(sess.run(loss, feed_dict={xs: x_data, ys: y_data}))
阅读全文
0 0
- 【Python】scikit-learn机器学习(二)——BP神经网络
- 机器学习----神经网络(二)BP算法
- 机器学习实践指南(二)—— 作为 baseline 的 SVM(scikit-learn)
- 机器学习笔记——Scikit-learn库中的数据预处理:独热编码(二)
- 【Python】scikit-learn机器学习(一)——一元回归模型
- 【Python】scikit-learn机器学习(八)——K-means聚类
- 机器学习——BP神经网络模型
- 机器学习——BP神经网络算法
- 机器学习——BP神经网络算法应用(上)
- 机器学习——BP神经网络算法应用(下)
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Python机器学习scikit-learn工具
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- python机器学习库scikit-learn
- Nginx Rtmp Module
- 欢迎使用CSDN-markdown编辑器
- 我心中SpringBoot
- XListView+MyBaseAdapter适配器
- kuangbin 数论 F
- 【Python】scikit-learn机器学习(二)——BP神经网络
- B. Arpa and an exam about geometry
- 数据大于long long最大值,处理方法 子串加法运算
- 链式二叉树的C语言代码
- 欢迎使用CSDN-markdown编辑器
- Eclipse中文版之完美汉化教程(详细图解)
- 学生总结(六)---meclean的作用
- JAVA设计模式之装饰模式(decorator)
- Turtlebot3入门手册之三:PC端软件配置