tensorflow tutorials(三):用tensorflow建立逻辑回归模型
来源:互联网 发布:java base64 字符串 编辑:程序博客网 时间:2024/06/05 14:25
声明:版权所有,转载请联系作者并注明出处
import tensorflow as tfimport numpy as npfrom tensorflow.examples.tutorials.mnist import input_datadef init_weights(shape): return tf.Variable(tf.random_normal(shape, stddev=0.01))def model(X, W): return tf.matmul(X, W) # notice we use the same model as linear regression, this is because there is a baked in cost function which performs softmax and cross entropymnist = input_data.read_data_sets("/tmp/data", one_hot=True)train_X, train_Y, test_X, test_Y = mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labelsX = tf.placeholder("float", [None, 784]) # create symbolic variablesY = tf.placeholder("float", [None, 10])W = init_weights([784, 10]) # like in linear regression, we need a shared variable weight matrix for logistic regressionpy_x = model(X, W)# defined the cost function, compute mean cross entropy (softmax is applied internally)cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, Y)) # construct optimizertrain_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # Launch the graph in a sessionwith tf.Session() as sess: # you need to initialize all variables tf.initialize_all_variables().run() for i in range(100): for start, end in zip(range(0, len(train_X), 128), range(128, len(train_X)+1, 128)): sess.run(train_op, feed_dict={X: train_X[start:end], Y: train_Y[start:end]}) print(i, np.mean(np.argmax(test_Y, axis=1) == sess.run(tf.argmax(py_x, 1), feed_dict={X: test_X})))
1 0
- tensorflow tutorials(三):用tensorflow建立逻辑回归模型
- tensorflow tutorials(一):用tensorflow建立线性回归模型
- tensorflow tutorials(二):用tensorflow建立岭回归模型
- TensorFlow学习笔记(三):TensorFlow实现逻辑回归模型
- Tensorflow实现逻辑回归模型
- TensorFlow系列(1)——建立线性回归模型
- tensorflow逻辑回归
- tensorflow之逻辑回归
- Tensorflow实现逻辑回归
- tensorflow逻辑回归例子
- tensorflow逻辑回归测试
- Tensorflow--逻辑回归
- 用TensorFlow写逻辑斯蒂回归
- TensorFlow学习笔记(二):TensorFlow实现线性回归模型
- 机器学习与TensorFlow编程(2)逻辑线性回归模型
- 逻辑回归之tensorflow实现
- 用tensorflow构建线性回归模型
- TensorFlow个人学习(回归模型)
- 【Tomcat】Tomcat配置https证书
- Atom Latex Settings
- Linux启动分析之Initramfs
- UVa11609 Teams
- Web前端填坑记录(持续更新)
- tensorflow tutorials(三):用tensorflow建立逻辑回归模型
- 对级排序学习pairwise learning 偏好关系学习(RankBost)
- css控制一个div在其父级的div垂直居中显示
- 封装tableView、collectView,简化使用
- 监听用C/C++代码监听App是否被卸载
- iOS开发------ 小知识点总结,也许你用得上
- ¥小会计¥ 将一个小于一亿的整数转换成大写金额
- Apache和Tomcat二者的区别
- 3.6