Home Artificial Intelligence Linear Regression: Understanding the Basics Kinds of Linear Regression. Assumptions of Linear Regression. Mathematical Intuition Linear Regression using Sklearn Conclusion

Linear Regression: Understanding the Basics Kinds of Linear Regression. Assumptions of Linear Regression. Mathematical Intuition Linear Regression using Sklearn Conclusion

1
Linear Regression: Understanding the Basics
Kinds of Linear Regression.
Assumptions of Linear Regression.
Mathematical Intuition
Linear Regression using Sklearn
Conclusion

Easy Linear Regression

Multiple Linear Regression

  1. Linearity: The connection between the dependent variable and the independent variables have to be linear. Which means that the changes within the dependent variable are directly proportional to the changes within the independent variables.
  2. Independence: The observations within the dataset ought to be independent of one another. In other words, the worth of the dependent variable for one commentary mustn’t be influenced by the values of the dependent variable for other observations.
  3. Homoscedasticity: The variance of the errors (the differences between the actual and predicted values) ought to be constant across all levels of the independent variables. Which means that the scatter of the residuals ought to be roughly equal across the range of predicted values.
  4. Normality: The residuals ought to be normally distributed. Which means that the distribution of the residuals ought to be symmetric around zero, with most residuals near zero and fewer residuals further away.
  5. No Multicollinearity: The independent variables mustn’t be highly correlated with one another. If two or more independent variables are highly correlated, it becomes difficult to differentiate the effect of every individual independent variable on the dependent variable.
  1. Closed-form solution: The closed-form solution (also often called the ) is a mathematical formula that directly computes the values of the model parameters that minimize the sum of squared errors between the anticipated values and the actual values of the dependent variable.
  2. Non-closed form solution: The non-closed form solution for linear regression refers back to the use of optimization algorithms to estimate the parameters of the model. This is commonly needed when the closed-form solution is either not feasible or not desirable as a consequence of the scale of the dataset or the complexity of the model. One commonly used optimization algorithm is .
A representation of errors between actual and predicted values
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
dataset = pd.read_csv('dataset.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=2)
regressor = LinearRegression()
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
mse = np.mean((y_pred - y_test)**2)
r2_score = regressor.rating(X_test, y_test)

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here