0% found this document useful (0 votes)
13 views3 pages

LAB7

This document provides a Python script to perform a simple linear regression analysis on house data, specifically relating area to price. It utilizes libraries such as pandas, numpy, and matplotlib, along with scikit-learn's LinearRegression model. The script includes data preparation, model training, prediction, and visualization of the results.

Uploaded by

relele4241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

LAB7

This document provides a Python script to perform a simple linear regression analysis on house data, specifically relating area to price. It utilizes libraries such as pandas, numpy, and matplotlib, along with scikit-learn's LinearRegression model. The script includes data preparation, model training, prediction, and visualization of the results.

Uploaded by

relele4241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXP-8 To perform a simple Linear Regression with python

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from sklearn.linear_model import LinearRegression

# Sample House Data

data = {

'Area': [1000, 1200, 1500, 1800, 2000, 2200, 2500, 2700, 3000],

'Price': [200000, 240000, 300000, 360000, 400000, 440000, 500000, 540000, 600000]

df = pd.DataFrame(data)

# Features and Target

X = df[['Area']]

y = df['Price']

# Train the Model

regressor = LinearRegression()

regressor.fit(X, y)

# Predict on the same X for full-line visualization

y_pred = regressor.predict(X)
# Print Coe icients

print("Slope (coef_):", regressor.coef_)

print("Intercept:", regressor.intercept_)

# Plotting

plt.scatter(X, y, color='blue', label='Actual Data Points')

plt.plot(X, y_pred, color='red', linewidth=2, label='Regression Line')

plt.xlabel('Area (sq ft)')

plt.ylabel('Price ($)')

plt.title('Simple Linear Regression - Area vs Price')

plt.legend()

plt.grid(True)

plt.show()
OUTPUT:

You might also like