The document is a lab manual for implementing linear regression using Python with libraries such as NumPy, Matplotlib, and scikit-learn. It includes code for generating synthetic data, splitting it into training and testing sets, fitting a linear regression model, and evaluating the model's performance. Additionally, it provides a manual implementation of linear regression using gradient descent and visualizations of the results.
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 ratings0% found this document useful (0 votes)
2 views4 pages
ML LAB Manual-1
The document is a lab manual for implementing linear regression using Python with libraries such as NumPy, Matplotlib, and scikit-learn. It includes code for generating synthetic data, splitting it into training and testing sets, fitting a linear regression model, and evaluating the model's performance. Additionally, it provides a manual implementation of linear regression using gradient descent and visualizations of the results.
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/ 4
Machine Learning Lab Manual
Anaconda Website
1) Program to implement linear regression
import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error
# Generate synthetic data
np.random.seed(42) X = 2 * np.random.rand(100, 1) y = 4 + 3 * X + np.random.randn(100, 1) # y = 4 + 3X + noise # Split data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Using sklearn's LinearRegression
model = LinearRegression() model.fit(X_train, y_train) y_pred = model.predict(X_test)