Weights में कई बार अपडेट करना
अब आप कई बार अपडेट करेंगे ताकि आप अपने मॉडल के weights को काफी हद तक बेहतर बना सकें, और देख सकें कि हर अपडेट के साथ predictions कैसे सुधरते हैं.
कोड साफ रखने के लिए, एक प्री-लोडेड get_slope() फंक्शन दिया गया है जो input_data, target, और weights को आर्ग्युमेंट्स के रूप में लेता है. इसी तरह एक get_mse() फंक्शन भी है जो वही आर्ग्युमेंट्स लेता है. input_data, target, और weights पहले से लोड हैं.
इस नेटवर्क में कोई hidden layer नहीं है. यह सीधे input (3 nodes) से एक output node तक जाता है. ध्यान दें कि weights एक single array है.
हमने matplotlib.pyplot भी प्री-लोड कर रखा है, और आपके gradient descent स्टेप्स पूरे होने के बाद error history प्लॉट कर दी जाएगी.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Deep Learning परिचय
अभ्यास निर्देश
forलूप का उपयोग करके weights को क्रमिक रूप से अपडेट करें:get_slope()फंक्शन से slope 계산 करें.0.01की learning rate के साथ weights अपडेट करें.- अपडेटेड weights के साथ
get_mse()फंक्शन का उपयोग कर mean squared error (mse) 계산 करें. mseकोmse_histमें append करें.
- 'उत्तर सबमिट करें' दबाएँ ताकि
mse_histvisualize हो. आपको क्या रुझान दिखता है?
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
n_updates = 20
mse_hist = []
# Iterate over the number of updates
for i in range(n_updates):
# Calculate the slope: slope
slope = ____(____, ____, ____)
# Update the weights: weights
weights = ____ - ____ * ____
# Calculate mse with new weights: mse
mse = ____(____, ____, ____)
# Append the mse to mse_hist
____
# Plot the mse history
plt.plot(mse_hist)
plt.xlabel('Iterations')
plt.ylabel('Mean Squared Error')
plt.show()