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

ML Exp.2 by Prashant

Uploaded by

deadm2996
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)
27 views3 pages

ML Exp.2 by Prashant

Uploaded by

deadm2996
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

EXPERIMENT:- 2

Student Name: Prashant UID:22MCA20999


Branch: MCA Section: MCA-3/B
Semester: 3rd Date of Performance: 8-08-2023
Subject Name: Machine Learning Subject Code:22CAP-702

Task to be done:

Write a program for linear regression in python?

Examples of Linear Regression


The weight of the person is linearly related to their height. So, this shows a linear relationship
between the height and weight of the person. According to this, as we increase the height, the
weight of the person will also increase.

Code:

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

# Sample data
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) # Input features (reshaped to a 2D array)
y = np.array([2, 4, 5, 4, 5]) # Target values

# Create and fit the linear regression model


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

# Predict with the trained model


X_test = np.array([6, 7]).reshape(-1, 1) # New data points for prediction
predictions = model.predict(X_test)
# Print the predictions
print(predictions)

# Plot the data and the regression line


plt.scatter(X, y, color='blue', label='Data')
plt.plot(X_test, predictions, color='red', label='Regression Line')
plt.xlabel('Input')
plt.ylabel('Target')
plt.legend()
plt.show()
OUTPUT:

Learning Outcomes:-

1. I Understand Linear Regression Concepts.


2. Data Preparation and Visualization.

You might also like