ML Exp1 C36
ML Exp1 C36
TUS3F202128 C36
PART A
(PART A: TO BE REFFERED BY STUDENTS)
Experiment No. 1
A.1 Aim:
To implement Linear Regression.
A.2 Prerequisite:
Python Basic Concepts
A.3 Outcome:
Students will be able to implement Linear Regression.
A.4 Theory:
Machine Learning, being a subset of Artificial Intelligence (AI), has been playing a dominant role in
our daily lives. Data science engineers and developers working in various domains are widely using
machine learning algorithms to make their tasks simpler and life easier.
Majority of the machine learning algorithms fall under the supervised learning
category. It is the process where an algorithm is used to predict a result based on the
previously entered values and the results generated from them. Suppose we have an
input variable ‘x’ and an output variable ‘y’ where y is a function of x (y=f{x}).
Supervised learning reads the value of entered variable ‘x’ and the resulting
variable ‘y’ so that it can use those results to later predict a highly accurate output
data of ‘y’ from the entered value of ‘x’. A regression problem is when the resulting
variable contains a real or a continuous value. It tries to draw the line of best fit
from the data gathered from a number of points.
Prathmesh Gaikwad
TUS3F202128 C36
Linear Regression
Linear regression is a quiet and simple statistical regression method used for
predictive analysis and shows the relationship between the continuous variables.
Linear regression shows the linear relationship between the independent variable (X-
axis) and the dependent variable (Y-axis), consequently called linear regression. If
there is a single input variable (x), such linear regression is called simple linear
regression. And if there is more than one input variable, such linear regression is
called multiple linear regression. The linear regression model gives a sloped straight
line describing the relationship within the variables.
y= Dependent Variable.
x= Independent Variable.
a0= intercept of the line.
a1 = Linear regression coefficient.
Let’s say we want to estimate the salary of an employee based on year of experience.
You have the recent company data, which indicates that the relationship between
Prathmesh Gaikwad
TUS3F202128 C36
experience and salary. Here year of experience is an independent variable, and the
salary of an employee is a dependent variable, as the salary of an employee is
dependent on the experience of an employee. Using this insight, we can predict the
future salary of the employee based on current & past information.
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
def main():
# observations / data
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# estimating coefficients
b = estimate_coef(x, y)
print("Estimated coefficients:\nb_0 = {} \
\nb_1 = {}".format(b[0], b[1]))
B.4 Conclusion:
Hence, we successfully studied & implemented Linear Regression.
B.5 Question of Curiosity (Handwritten any 3)
1. Explain in detail Multivariate Linear Regression.
2. Explain the concepts behind linear regression.
3. Write a short note on linear regression.
Prathmesh Gaikwad
TUS3F202128 C36
Prathmesh Gaikwad
TUS3F202128 C36
Prathmesh Gaikwad
TUS3F202128 C36
Prathmesh Gaikwad
TUS3F202128 C36
4. What is the difference between simple linear regression and multiple linear regression?
Ans:
Simple linear regression:
Simple linear regression has only one x and one y variable.
One independent variable.
Multi collinearity problem cannot exist.
The coefficient of determination is the square of the correlation coefficient between x and y
Financial analysis
Financial analysts use linear models to evaluate a company's operational performance and forecast
returns on investment. They also use it in the capital asset pricing model, which studies the
relationship between the expected investment returns and the associated market risks. It shows
companies if an investment has a fair price and contributes to decisions on whether or not to invest
in the asset.
Sports analysis
This involves sports analysts using statistics to determine a team's or player's performance in a
game. They can use this information to compare teams and players and provide essential
information to their followers. They can also use this data to predict game attendance based on the
status of the teams playing and the market size, so they can advise team managers on game venues
and ticket prices that can maximise profits.
Environmental health
Specialists in this field use this regression model to evaluate the relationship between natural
elements, such as soil, water and air. An example is the relationship between the amount of water
and plant growth. This can help environmentalists predict the effects of air or water pollution on
environmental health.
Medicine
Medical researchers can use this regression model to determine the relationship between
independent characteristics, such as age and body weight, and dependent ones, such as blood
pressure. This can help reveal the risk factors associated with diseases. They can use this
information to identify high-risk patients and promote healthy lifestyles.
Marks scored by students based on number of hours studied (ideally)- Here marks scored in
exams are independent and the number of hours studied is independent.
Predicting crop yields based on the amount of rainfall- Yield is a dependent variable while the
measure of precipitation is an independent variable.
Predicting the Salary of a person based on years of experience- Therefore, Experience becomes
the independent while Salary turns into the dependent variable.