Logistic regression, processing mnist, for example, please refer to.
# coding = utf_8 import os os.environ["tf_cpp_min_log_level"] = ' 2 ' Import tensorflow as TF import NumPy as NP from Tenso Rflow.examples.tutorials.mnist Import input_data def init_weights (shape): return TF. Variable (Tf.random_normal (shape, StdDev = 0.01)) def model (X, W): Return Tf.matmul (x, W) mnist = Input_data.read_da Ta_sets ("/tmp/data", One_hot=true) TrX, TrY, TeX, Tey = Mnist.train.images, Mnist.train.labels,mnist.test.images, Mnist.test.labels X = Tf.placeholder ("float", [None, 784]) Y = Tf.placeholder ("float", [None,]) W = init_weights ([7
Y_model = Model (X, W) loss = Tf.reduce_mean (Tf.nn.softmax_cross_entropy_with_logits (Logits=y_model, labels=y)) Train_op = Tf.train.GradientDescentOptimizer (0.05). Minimize (loss) Predict_op = Tf.argmax (y_model,1) with TF. Session () as Sess:init = Tf.global_variables_initializer () sess.run (init) to I in range (m): for S
Tart, end in Zip (range (0,len (TRX), 128), range (128, Len (TRX), 128)): Sess.run (Train_op, Feed_dict={x:tex, Y:tey}) print (I,np.mean (np.argmax) = = Tey,axis=1 (Sess.run, F
eed_dict= {X:tex, y:tey}))
extracting/tmp/data\train-images-idx3-ubyte.gz extracting/tmp/data\train-labels-idx1-ubyte.gz extracting/tmp/
data\t10k-images-idx3-ubyte.gz extracting/tmp/data\t10k-labels-idx1-ubyte.gz 0 0.8899 1 0.9029 2 0.9104 3 0.9154 4 0.9184 5 0.921 6 0.9235 7 0.9248 8 0.9256 9 0.9282 10 0.9293 11 0.9312 12 0.9326 13 0.9331 14 0.9339 15 0.9346 16 0.9357 the 17 0.93 68 18 0.9371 19 0.9375 20 0.9382 21 0.9391 22 0.9394 23 0.9399 24 0.94 25 0.9402 26 0.9406 27 0.9412 28 0.9416 29 the 0.9423 3 0 0.9426 31 0.9433 32 0.9435 33 0.9438 34 0.9444 35 0.9445 36 0.9447 37 0.9452 38 0.9455 39 0.9455 40 0.9457 41 0.946 the 42 0 .9458 43 0.9462 44 0.9467 45 0.947 46 0.9473 47 0.9478 48 0.948 49 0.9481 50 0.9484 51 0.9484 52 0.9491 53 0.9494 54 0.949 6 55 0.95 56 0.95 57 0.95 58 0.9501 59 0.9501 60 0.9503 61 0.9509 62 0.9512 63 0.9513 64 0.9517 65 0.9518 66 0.9519 67 0.9 521 68 0.9521 69 0.9521 70 0.9522 71 0.9525 72 0.9528 73 0.9529 74 0.9534 75 0.9536 76 0.9536 77 0.9538 78 0.9539 79-0.954 3 80 0.9546 81 0.9546 82 0.9546 83 0.9545 84 0.9547 85 0.9547 86 0.9549 87 0.955 88 0.9554 89 0.9554 90 0.9556 91 0.9559 92 0.956 93 0.9562 94 0.9562 95-0.9
564 0.9565 0.9566 0.9571 0.9573 Process finished with exit code 0