





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






The script starts by loading the "big three" of Python data science:
The model uses Gradient Descent to iteratively minimize the difference between predicted and actual prices. By adjusting the weight (w)or theta0 and bias (b) or theta1over 1, rounds, it converges on a mathematical formula that can predict the price of any house based on its size.
The for i in range(epochs): line starts a loop that repeats 1,000 times. Inside that loop, four things happen:
1. Making a Prediction y_pred = theta0 + theta1 * X_train_scaled: The model calculates a "guessed price" (y_pred) for every house using its current theta0 and theta1. At the very first step, since both are 0, every guess is 0. 2. Calculating the Error (The "Cost function") cost = (1 / (2 * n)) * np.sum((y_pred - y_train) ** 2): This measures how wrong the model is. It takes the difference between the guess (y_pred) and the actual price (y_train), squares it (to make all errors positive), and finds the average. A high cost means the model is doing a poor job. 3. Calculating the Gradients (The "Direction") d_theta0 = (1 / n) * np.sum(y_pred - y_train) d_theta1 = (1 / n) * np.sum((y_pred - y_train) * X_train_scaled) These lines calculate the "slope" of the error.