0% found this document useful (0 votes)
12 views6 pages

Dav 2,3

The document outlines the implementation of Simple and Multiple Linear Regression models in Python, detailing their theories, equations, assumptions, and steps for execution. It emphasizes the importance of understanding the relationship between dependent and independent variables and provides a structured approach to data analysis and model training. The conclusion highlights the effectiveness of these regression techniques in predicting outcomes based on linear relationships.

Uploaded by

dory34547
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)
12 views6 pages

Dav 2,3

The document outlines the implementation of Simple and Multiple Linear Regression models in Python, detailing their theories, equations, assumptions, and steps for execution. It emphasizes the importance of understanding the relationship between dependent and independent variables and provides a structured approach to data analysis and model training. The conclusion highlights the effectiveness of these regression techniques in predicting outcomes based on linear relationships.

Uploaded by

dory34547
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/ 6

‭EXPERIMENT No.

2‬

‭Date of Performance:‬
‭Date of Submission:‬
‭Aim‬‭:‬‭To implement the Simple Linear regression model in machine learning using Python.‬
‭Theory:‬

‭Simple‬ ‭Linear‬ ‭Regression‬‭:‬ ‭Simple‬ ‭Linear‬ ‭Regression‬ ‭is‬ ‭a‬ ‭type‬ ‭of‬ ‭Regression‬ ‭algorithm‬ ‭that‬
‭models‬ ‭the‬ ‭relationship‬ ‭between‬‭a‬‭dependent‬‭variable‬‭and‬‭a‬‭single‬‭independent‬‭variable‬‭.‬‭The‬
‭relationship‬ ‭shown‬‭by‬‭a‬‭Simple‬‭Linear‬‭Regression‬‭model‬‭is‬‭linear‬‭or‬‭a‬‭sloped‬‭straight‬‭line,‬‭hence‬
‭it is called Simple Linear Regression.‬
‭Simple Linear regression algorithm has mainly two objectives:‬
o‬‭Model
‭ the relationship between the two variables.‬
o‬‭Forecasting
‭ new observations.‬

‭The Simple Linear Regression model can be represented using the below‬
‭equation:‬‭
y= a‬
0‬
‭ +a‬
‭ 1‬
‭ x+ ε‬

‭Where,‬
‭a‬‭0‬‭= It is the intercept of the Regression line.‬
‭a‬‭1‬‭= It is the slope of the regression line, which tells whether the line is increasing or‬
‭decreasing. ε = The error term.‬

‭Assumptions of simple linear regression :‬

‭Simple linear regression is a‬‭parametric test‬‭, meaning that it makes certain assumptions about the‬
‭data. These assumptions are:‬

‭•‬‭Homogeneity of variance (homoscedasticity)‬‭: the size of the error in our prediction‬


‭doesn’t change significantly across the values of the independent variable.‬
‭•‬ ‭Independence‬ ‭of‬ ‭observations‬‭:‬ ‭the‬ ‭observations‬ ‭in‬ ‭the‬ ‭dataset‬ ‭were‬ ‭collected‬ ‭using‬
‭statistically‬ ‭valid‬ ‭sampling‬ ‭methods,‬ ‭and‬ ‭there‬ ‭are‬ ‭no‬ ‭hidden‬ ‭relationships‬ ‭among‬
‭observations.‬
‭•‬‭Normality‬‭: The data follows a normal distribution.‬
‭Steps for Implementation:‬
‭Step 1: Import the required python packages.‬
‭•‬‭Pandas for data manipulation‬
‭•‬‭Numpy for mathematical calculations‬
‭•‬‭MatplotLib and‬‭Seaborn‬‭for visualizations.‬
‭•‬‭Sklearn‬‭libraries are used for machine learning operations.‬
‭ tep 2: Load the dataset.‬
S
‭Download the dataset and upload it to your notebook and read it into the pandas dataframe.‬‭Step‬

‭Step 3: Data Analysis.‬

‭Step 4: Split dataset into dependent/independent variables.‬


‭(X)‬‭is the independent variable‬
(‭ y)‬‭is dependent on experience‬
‭Step 5: Split data into Train/Test sets.‬
‭Split data into training (80%) and test (20%) sets using‬‭train_test_split‬
‭Step 6: Applying the Model.‬
‭Pass the‬‭X_train‬‭and‬‭y_train‬‭data into the regressor model by‬‭regressor.fit‬‭to train the model‬
‭with our training data.‬
‭Step 7: Predict the result.‬
‭To predict any value of‬‭y‬‭(Salary)‬‭dependent on‬‭X‬‭(Experience)‬‭with the trained model using‬
‭regressor.predict‬
‭Step 8: Plot the training and test results.‬
‭•‬‭Plot training set data vs predictions‬
‭ irst we plot the result of training sets‬‭(X_train, y_train)‬‭with‬‭X_train‬‭and predicted value of‬
F
‭y_train (regressor.predict(X_train))‬
‭•‬‭Plot test set data vs predictions‬
‭ econdly, we plot the result of test sets‬‭(X_test, y_test)‬‭with‬‭X_train‬‭and predicted value‬
S
‭of‬‭y_train (regressor.predict(X_train))‬
‭The linear equation‬‭y = mx + c‬‭, we can also get the‬‭c‬‭(y-intercept)‬‭and‬‭m‬‭(slope/coefficient)‬‭from‬
‭the regressor model.‬

‭Code And Output:‬


‭Conclusion:‬

‭Simple linear regression is a potent supervised machine learning approach that enables us to‬
‭predict linear correlations between two variables.‬

‭Marks & Signature:‬


‭R1‬ ‭R2‬ ‭R3‬ ‭R4‬ ‭Total‬ ‭Signature‬
‭(15 Marks)‬
‭(4 Marks)‬ ‭(4 Marks)‬ ‭(4 Marks)‬ ‭(3 Marks)‬
‭EXPERIMENT No. 3‬

‭Date of Performance:‬
‭Date of Submission:‬
‭Aim‬‭:‬‭To implement the Multiple Linear regression model in machine learning using Python.‬
‭Theory:‬
‭Multiple‬‭Linear‬‭Regression‬‭is‬‭one‬‭of‬‭the‬‭important‬‭regression‬‭algorithms‬‭which‬‭models‬
‭the‬ ‭linear‬ ‭relationship‬ ‭between‬ ‭a‬ ‭single‬ ‭dependent‬ ‭continuous‬ ‭variable‬ ‭and‬ ‭more‬ ‭than‬ ‭one‬
‭independent variable.‬
‭Some key points about MLR:‬

‭•‬ ‭For‬ ‭MLR,‬ ‭the‬ ‭dependent‬ ‭or‬ ‭target‬ ‭variable(Y)‬ ‭must‬ ‭be‬ ‭the‬ ‭continuous/real,‬ ‭but‬ ‭the‬
‭predictor or independent variable may be of continuous or categorical form.‬
‭•‬‭Each‬‭feature‬‭variable‬‭must‬‭model‬‭the‬‭linear‬‭relationship‬‭with‬‭the‬‭dependent‬‭variable.‬‭•‬
‭MLR tries to fit a regression line through a multidimensional space of data-points.‬
‭The Simple Linear Regression model can be represented using the below‬

‭equation:‬‭y = β‬‭0‬‭+ β‬‭1‬‭X‬‭1‭+


‬ ‬‭……‬‭+ β‬‭n‬‭X‭n
‬ ‬‭+‬‭Є‬

‭Where,‬

‭•‬‭y‬‭= the predicted value of the dependent variable‬


‭•‬‭β‬‭0‬‭= the y-intercept (value of y when all other parameters are set to 0)‬
‭•‬‭β‬‭1‬‭X‭1‬ ‬‭= the regression coefficient (‬‭β‬‭1‬‭) of the first independent variable (‬‭X‬‭1‬‭)‬‭•‬
‭β‬‭n‬‭X‭n‬ ‬‭= the regression coefficient of the last independent variable‬
‭•‬‭Є‬‭= model error (a.k.a. how much variation there is in our estimate of ‘y’‬

‭Assumptions of Multiple linear regression :‬

‭Simple linear regression is a‬‭parametric test‬‭, meaning that it makes certain assumptions about the‬
‭data. These assumptions are:‬

‭•‬‭A‬‭linear relationship‬‭should exist between the Target and predictor variables.‬‭•‬


‭The regression residuals must be‬‭normally distributed‬‭.‬
‭•‬‭MLR assumes little or‬‭no multicollinearity‬‭(correlation between the independent variable)‬
‭in data.‬

‭Steps for Implementation:‬


‭Step 1: Import the required python packages.‬
‭•‬‭Pandas for data manipulation‬
‭•‬‭Numpy for mathematical calculations‬
‭•‬‭MatplotLib and‬‭Seaborn‬‭for visualizations.‬
‭•‬‭Sklearn‬‭libraries are used for machine learning operations.‬
‭Step 2: Load the dataset.‬
‭ ownload the dataset and upload it to your notebook and read it into the pandas dataframe.‬
D
‭ tep 3: Handling Categorical Variables‬
S
‭•‬‭handle categorical variable‬
‭•‬‭dropping extra column‬
•‭ ‬‭concatation of independent variables and new categorical variable.‬
‭ tep 4: Extracting dependent and independent Variables.‬
S
‭(X) is the independent variable‬
(‭ y) is dependent on experience‬
‭Step 5: Split data into Train/Test sets.‬
‭ plit data into training (80%) and test (20%) sets using‬‭train_test_split.‬
S
‭Step 6: Applying the Model‬
‭Pass the‬‭X_train‬‭and‬‭y_train‬‭data into the regressor model by‬‭regressor.fit‬‭to train the model‬
‭with our training data.‬
‭Step 7: Predict the result‬
‭The last step for our model is checking the performance of the model.‬
‭#Predicting the Test set result;‬
‭y_pred= regressor.predict(x_test)‬
‭Code And Output:‬
‭Conclusion:‬

‭The basics of linear regression in Python, including the best-fit line, the coefficient of x, and how to‬
‭build multiple linear regression models using sklearn.‬

‭Marks & Signature:‬


‭R1‬ ‭R2‬ ‭R3‬ ‭R4‬ ‭Total‬ ‭Signature‬
‭(15 Marks)‬
‭(4 Marks)‬ ‭(4 Marks)‬ ‭(4 Marks)‬ ‭(3 Marks)‬

You might also like