In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to analyze the regression problems in Tensorflow2.0. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Brief introduction
In real life, the problem of continuous value prediction is very common, such as stock price trend forecast, weather forecast medium temperature.
The prediction of degree and humidity, age, traffic flow and so on. For a continuous range of real numbers for predicted values, or
The operator belongs to a continuous interval of real numbers, which we call the Regression problem. In particular, if a linear model is used to approximate the real model, then this kind of method is called Linear Regression (LR).
Here's an example of a simple linear regression problem.
problem
The data is sampled directly from the real model y=1.477*x+0.0889 of the specified wband 1.477, baud 0.089.
Program listing import tensorflow as tfimport numpy as np# 1. Collected data data = [] # Save the list of sample sets for i in range: # cyclic sampling 100points x = np.random.uniform (- 10.10) # randomly sampled a number eps = np.random.normal (0.1,0.1) from the uniform distribution of [- 10Magin10] # from a mean of 0.1, The random sampling noise y = 1.477*x+0.089+eps # in the Gaussian distribution with a variance of 0.1 ^ 2 is converted into a 2D Numpy array # 2. The simulated output data.append ([x, y]) # saves the sample point data = np.array (data) #. Calculation error def mse (b, w, points): # according to the current wheel's wjournal b parameter Calculate the loss of mean square error totalError = 0for i in range (0, len (points)): # cycle iteration all points x = points [I, 0] # get the Abscissa of the I point xy = points [I, 1] # get the vertical coordinate ytotalError + = (y-(w*x+b)) * * 2 # calculate the cumulative error return totalError/float (len (points)) # and get the mean square error # 3. Calculate the gradient def step_gradient (b_current, w_current, points, learning_rate): b_gradient = 0w_gradient = 0M = float (len (points)) # Total samples for i in range (0, len (points)): X = points [I, 0] y = points [I 1] b_gradient + = (2amp M) * ((w_current * x + b_current)-y) # derivative of error function to b w_gradient + = (2CMM) * x * ((w_current * x + b_current)-y) # derivative of error function to w # update w according to gradient descent algorithm Bnew_b = b_current-(learning_rate * b_gradient) new_w = w_current-(learning_rate * w_gradient) return [new_b, new_w] # 4. Gradient update def gradient_descent (points, starting_b, starting_w, learning_rate, epos): B = starting_b # initialization bw = starting_wfor step in range (epos): B, w = step_gradient (b, w, np.array (points), learning_rate) loss = mse (b, w, points) if step% 50 = 0:print ('epos', step,': loss', loss,'; w, w,' Return {b, w} def main (): lr = 0.01init_b = 0init_w = 0epos = 10000 [b, w] = gradient_descent (data, init_b, init_w, lr, epos) loss = mse (b, w, data) print ('Final loss:', loss,' Final loss:', loss, w, 'bdef main, b) return 0if _ name__ = "_ main__": main ()
Training results:
From the training results, it can be found that the wline b trained by the established linear model is very close to the real model.
How to analyze the regression problem in Tensorflow2.0 is shared here. I hope the above content can help you to some extent and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.