TensorFlow (1)----linear_regression implementation

Source: Internet
Author: User

TensorFlow is currently a very popular deeplearning framework, and the best way to learn TensorFlow is the TF project on GitHub Https://github.com/tensorflow/tensorflow

Or read the http://wiki.jikexueyuan.com/project/tensorflow-zh/how_tos/reading_data.html in the Chinese course of the geek's college-led translation.

Here to TensorFlow Basic grammar not to repeat, directly affixed to the source:

ImportNumPy as NPImportTensorFlow as TF
#准备数据trainX= Np.linspace (-1, 1, 101) Trainy= 2 * Trainx + NP.RANDOM.RANDN (*trainx.shape) * 0.33
#定义模型
defmodel (X, W):returnTf.mul (X, W)
#初始化数据流图X= Tf.placeholder ('float') Y= Tf.placeholder ('float') W= TF. Variable (0.0, name ='Weights') Y_=Model (X, W)

#评估模型cost= Tf.square (Y-y_) Train_op= Tf.train.GradientDescentOptimizer (0.01). Minimize (cost) Sess=TF. InteractiveSession () Init=tf.initialize_all_variables () #训练sess. Run (init) forIinchRange (100): for(x, Y)inchZip (Trainx, trainy): Sess.run (Train_op, Feed_dict={x:x, y:y})PrintSess.run (W) sess.close ()

TensorFlow (1)----linear_regression implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.