Linear regression

Python में TensorFlow परिचय

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Linear regression क्या है?

यह चित्र वर्ग फीट में घर के आकार के प्राकृतिक लघुगणक बनाम डॉलर में घर की कीमत के प्राकृतिक लघुगणक का स्कैटर प्लॉट दिखाता है.

Python में TensorFlow परिचय

Linear regression क्या है?

यह चित्र स्कैटर प्लॉट पर फिट की गई रिग्रेशन लाइन दिखाता है, जहाँ वर्ग फीट में घर के आकार के प्राकृतिक लघुगणक को डॉलर में घर की कीमत के प्राकृतिक लघुगणक के विरुद्ध प्लॉट किया गया है.

Python में TensorFlow परिचय

Linear regression मॉडल

  • Linear regression मॉडल एक रैखिक संबंध मानता है:
    • $price = intercept + size*slope + error$
  • यह univariate regression का उदाहरण है।
    • केवल एक फीचर है, size.
  • Multiple regression मॉडल में एक से अधिक फीचर होते हैं.
    • जैसे size और location
Python में TensorFlow परिचय

TensorFlow में Linear regression

# Define the targets and features
price = np.array(housing['price'], np.float32)
size = np.array(housing['sqft_living'], np.float32)

# Define the intercept and slope
intercept = tf.Variable(0.1, np.float32)
slope = tf.Variable(0.1, np.float32)
# Define a linear regression model
def linear_regression(intercept, slope, features = size):
    return intercept + features*slope
# Compute the predicted values and loss
def loss_function(intercept, slope, targets = price, features = size):
    predictions = linear_regression(intercept, slope)
    return tf.keras.losses.mse(targets, predictions)
Python में TensorFlow परिचय

TensorFlow में Linear regression

# Define an optimization operation
opt = tf.keras.optimizers.Adam()
# Minimize the loss function and print the loss
for j in range(1000):
    opt.minimize(lambda: loss_function(intercept, slope),\
    var_list=[intercept, slope])
    print(loss_function(intercept, slope))
tf.Tensor(10.909373, shape=(), dtype=float32)
...
tf.Tensor(0.15479447, shape=(), dtype=float32)
# Print the trained parameters
print(intercept.numpy(), slope.numpy())
Python में TensorFlow परिचय

अभ्यास करते हैं!

Python में TensorFlow परिचय

Preparing Video For Download...