एक linear regression सेट करें
एक univariate linear regression एक अकेले फीचर और target टेENSOR के बीच संबंध को पहचानती है। इस अभ्यास में, हम किसी प्रॉपर्टी के प्लॉट के आकार और कीमत का उपयोग करेंगे। जैसा कि वीडियो में चर्चा हुई, हम दोनों टेENSOR के नैचुरल लॉगरिदम लेंगे, जो price_log और size_log के रूप में उपलब्ध हैं।
इस अभ्यास में, आप मॉडल और loss फंक्शन को परिभाषित करेंगे। इसके बाद आप intercept और slope के दो अलग-अलग मानों के लिए loss फंक्शन का मूल्यांकन करेंगे। ध्यान रखें कि भविष्यवाणी किए गए मान intercept + features*slope से दिए जाते हैं। साथ ही, आपके लिए keras.losses.mse() उपलब्ध है। इसके अतिरिक्त, slope और intercept वैरिएबल के रूप में परिभाषित किए गए हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में TensorFlow परिचय
अभ्यास निर्देश
intercept,features, औरslopeका उपयोग करते हुए, औरadd()याmultiply()का उपयोग किए बिना, linear regression के प्रेडिक्टेड वैल्यू रिटर्न करने वाला एक फंक्शन परिभाषित करें।- मॉडल के वैरिएबल
interceptऔरslopeको आर्ग्युमेंट्स के रूप में जोड़करloss_function()को पूरा करें। targetsऔरpredictionsका उपयोग करके mean squared error गणना करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define a linear regression model
def linear_regression(intercept, slope, features = size_log):
return ____
# Set loss_function() to take the variables as arguments
def loss_function(____, ____, features = size_log, targets = price_log):
# Set the predicted values
predictions = linear_regression(intercept, slope, features)
# Return the mean squared error loss
return keras.losses.____
# Compute the loss for different slope and intercept values
print(loss_function(0.1, 0.1).numpy())
print(loss_function(0.1, 0.5).numpy())