09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Regression

3. Now, we calculate the two regression coefficients using the equations we

defined. You can see the result is very much near the linear relationship we

have simulated:

W = sum(price*(area-np.mean(area))) / sum((area-np.mean(area))**2)

b = np.mean(price) - W*np.mean(area)

print("The regression coefficients are", W,b)

-----------------------------------------------

-----------------------------------------------

The regression coefficients are 24.815544052284988

43.4989785533412

4. Let us now try predicting the new prices using the obtained weight and bias

values:

y_pred = W * area + b

5. Next, we plot the predicted prices along with the actual price. You can see

that predicted prices follow a linear relationship with the area:

plt.plot(area, y_pred, color='red',label="Predicted Price")

plt.scatter(data['area'], data['price'], label="Training Data")

plt.xlabel("Area")

plt.ylabel("Price")

plt.legend()

[ 92 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!