日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow--logistic regression

發布時間:2025/5/22 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow--logistic regression 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist=input_data.read_data_sets("tmp/data", one_hot=True)learning_rate=0.01 training_epochs=25 batch_size=100 display_step=1

# placeholder x,y 用來存儲輸入,輸入圖像x構成一個2維的浮點張量,[None,784]是簡單的平鋪圖,'None'代表處理的批次大小,是任意大小 x=tf.placeholder(tf.float32,[None,784]) y=tf.placeholder(tf.float32,[None,10])# variables 為模型定義權重和偏置 w=tf.Variable(tf.zeros([784,10])) b=tf.Variable(tf.zeros([10]))pred=tf.nn.softmax(tf.matmul(x,w)+b) # w*x+b要加上softmax函數

# reduce_sum 對所有類別求和,reduce_mean 對和取平均 cost=tf.reduce_mean(-tf.reduce_sum(y*tf.log(pred),reduction_indices=1))

# 往graph中添加新的操作,計算梯度,計算參數的更新 optimizer=tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)init=tf.initialize_all_variables()with tf.Session() as sess:sess.run(init)for epoch in range(training_epochs):total_batch=int(mnist.train.num_examples/batch_size)for i in range(total_batch):batch_xs,batch_ys=mnist.train.next_batch(batch_size)sess.run(optimizer,feed_dict={x:batch_xs,y:batch_ys})if( epoch+1)%display_step==0:print "cost=", sess.run(cost,feed_dict={x:batch_xs,y:batch_ys})prediction=tf.equal(tf.argmax(pred,1),tf.argmax(y,1))accuracy=tf.reduce_mean(tf.cast(prediction,tf.float32))print "Accuracy:" ,accuracy.eval({x:mnist.test.image,y:mnist.test.labels})

  

logistic 函數:

二分類問題

?

softmax 函數:

將k維向量壓縮成另一個k維向量,進行多分類,logistic 是softmax的一個例外

?

轉載于:https://www.cnblogs.com/fanhaha/p/7617497.html

總結

以上是生活随笔為你收集整理的tensorflow--logistic regression的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。