0% found this document useful (0 votes)
2 views

3

The document presents a Python script that uses linear regression to analyze the relationship between weight and height. It imports necessary libraries, creates a DataFrame with weight and height data, fits a linear regression model, and visualizes the results with a scatter plot and regression line. The final output is a plotted graph showing the data points and the linear regression line.

Uploaded by

anuj rawat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

3

The document presents a Python script that uses linear regression to analyze the relationship between weight and height. It imports necessary libraries, creates a DataFrame with weight and height data, fits a linear regression model, and visualizes the results with a scatter plot and regression line. The final output is a plotted graph showing the data points and the linear regression line.

Uploaded by

anuj rawat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

v8futiksp

December 26, 2024

[1]: import pandas as pd


import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

# Data
data = {
'weight': [140, 155, 159, 179, 192, 200, 212],
'height': [60, 62, 67, 70, 71, 72, 75]
}

# Create DataFrame
df = pd.DataFrame(data)

# Separate the features and target variable


X = df[['weight']]
y = df['height']

# Create and fit the model


model = LinearRegression()
model.fit(X, y)

# Predictions
predictions = model.predict(X)

# Plotting
plt.scatter(df['weight'], df['height'], color='blue', label='Data points')
plt.plot(df['weight'], predictions, color='red', linewidth=2, label='Linear␣
↪regression line')

plt.xlabel('Weight in lbs')
plt.ylabel('Height in inches')
plt.title('Linear Regression Model')
plt.legend()
plt.show()

1
2

You might also like