Page 334 - AI_Ver_3.0_class_11
P. 334
Advantage of Linear Regression
Some advantages of linear regression are as follows:
● Linear regression is a simple technique and easy to implement.
● Efficient to train the machine on this model.
Disadvantages of Linear Regression
Some disadvantages of linear regression are as follows:
● Regression analysis is sensitive to outliers as these can have a great impact on the analysis.
● It is quite prone to overfitting. (Overfitting means that the training of the model on data is just too good and the
test sample size is quite small).
Reboot
1. State the two types of Regression.
2. How many variables are used in linear regression?
3. State the equation of the line of best fit.
4. Why is it called the line of best fit?
5. State two applications of regression.
For Advanced Learners
Program 1: To demonstrate the use of simple linear regression in Python
import numpy as np
import matplotlib.pyplot as plt
# Updated sample data with more values
data_x = np.array([2, 4, 8, 6, 8, 10, 14, 12, 16, 20])
data_y = np.array([3, 5, 7, 8, 9, 6, 7, 5, 9, 8])
# Calculate mean and standard deviation
mean_x = np.mean(data_x)
mean_y = np.mean(data_y)
std_x = np.std(data_x)
std_y = np.std(data_y)
# Calculate covariance and slope
cov = np.sum((data_x - mean_x) * (data_y - mean_y)) / (len(data_x) - 1)
slope = cov / (std_x**2)
# Calculate y-intercept (b)
intercept = mean_y - slope * mean_x
332 Touchpad Artificial Intelligence (Ver. 3.0)-XI

