Standard Curves and Regression Analysis
Standard Curves and Regression Analysis
Standard Curves
1. Straight line
y=mx+c ;
y=a0x+a1 ;
y=ax+b
2 Quadratic Curve or Parabola Curve
ax2 + bx + c = 0
3. Nth degree polynomial curve
Example:- y=(x+3)(x−2)2(x+1)3
.
4. Exponential curve
y=axb
Lagrange Interpolation
Lagrange Interpolation is a way of finding the value of any function at any given
point when the function is not given.
Other points on the function to get the value of the function at any required point.
It is used in AI modeling.
This method is very sensitive to outliers. In fact, this can skew the results of the
least-squares analysis.
Curve fitting by method of least squares
Given points of data are (x1, y1), (x2, y2), (x3, y3), …, (xn, yn) in which all x’s are
independent variables, while all y’s are dependent ones.
Suppose that f(x) is the fitting curve and d represents error or deviation from each
given point.
d1 = y1 − f(x1)
d2 = y2 − f(x2)
…..
dn = yn – f(xn)
The least-squares explain that the curve that best fits is represented by the
property that the sum of squares of all the deviations from given values must be
minimum, i.e:
Least square straight line curve fitting
Quadratic Curve or Parabola Curve
ax2 + bx + c = 0
Numericals
Linear Weighted Least Squares Approximation
Curve fitting is the process of approximating a function 𝑓(𝑥) that best represents a
given set of data points.
However, these observations may not be equally reliable. To account for this, we
introduce a weight 𝑤𝑖 for each data point, leading to the weighted sum of squared
residuals:
Linear Weighted Least Squares for Discrete Data
For a linear function:
To minimize 𝑆𝑤Sw , take partial derivatives with respect to 𝑎0 and 𝑎1 and set
them to zero:
Normal Equations for Continuous Case
To find 𝑎0 and 𝑎1, set the derivatives with respect to 𝑎0 and 𝑎1 to zero:
Key Differences Between Discrete and Continuous Cases
Gauss-Newton Method
Discrete Data Case
Continuous Function Case
For a continuous function 𝑦(𝑥), we minimize the weighted error integral:
How strong the relationship is between two or more independent variables and
one dependent variable (e.g. how rainfall, temperature, and amount of fertilizer
added affect crop growth).
Interpretation of Coefficients
Model Evaluation Metrics
● R-Squared (R^2): Measures the proportion of variance in explained by the
independent variables.
● Adjusted R-Squared: Adjusts for the number of predictors to prevent
overfitting.
● F-Test: Tests the overall significance of the model.
● t-Tests: Tests the significance of individual regression coefficients.
● Residual Analysis: Checks the validity of regression assumptions.
Numericals on multiple linear regression
Q. Fit a regression equation to estimate to the following data of a
transport company on the weights of 6 shipments, the distances they were moved
and the damage of the goods that was incurred. Estimate the damage when a
shipment of 3700 kg is moved to a distance of 260 km.
X1 3 5 6 8 12 14
X2 16 10 7 4 3 2
Y 90 72 54 42 30 12
Multivariate Linear Regression
Multivariate regression shows the linear relationship between more than one
predictor or independent variable and more than one output or dependent
variable.
1. Buyer wants to estimate the price of a house. He will collect details such as
the location, number of bedrooms, size of square feet, amenities available,
etc. Based on these details, he can predict the price of the house and how
each variable is interrelated.
2. An agriculture scientist wants to predict the total crop yield expected for the summer.
He collected details of the expected amount of rainfall, fertilizers to use, and soil
[Link] building a Multivariate regression model, scientists can predict crop yield.
With the crop yield, the scientist also tries to understand the relationship among the
variables.
3. Suppose an organization wants to know how much it has to pay a new hire. In that
case, it will consider details such as education level, years of experience, job location,
and whether the employee has niche skills. Based on this information, you can predict an
employee’s salary, and these variables help estimate the salary.
4. Economists can use Multivariate regression to predict the GDP growth of a state or a
country based on parameters such as the total amount spent by consumers, import
expenditures, total gains from exports, and total savings.
5. A company wants to predict an apartment’s electricity bill. The details needed here are
the number of flats, the number of appliances used, the number of people at home, etc.
These variables can help predict the electricity bill.
Steps of Multivariate Regression analysis
● Feature selection-
○ The selection of features is an important step in multivariate regression.
○ Feature selection also known as variable selection.
○ It becomes important for us to pick significant variables for better model building.
● Normalizing Features-
○ We need to scale the features as it maintains general distribution and ratios in data.
This will lead to an efficient analysis.
○ The value of each feature can also be changed.
● Select Loss function and Hypothesis-
○ The loss function predicts whenever there is an error. Meaning, when the hypothesis
prediction deviates from actual values.
○ Here, the hypothesis is the predicted value from the feature/variable.
● Set Hypothesis Parameters-
○ The hypothesis parameter needs to be set in such a way that it reduces the loss
function and predicts well.
● Minimize the Loss Function-
○ The loss function needs to be minimized by using a loss minimization algorithm on
the dataset, which will help in adjusting hypothesis parameters.
○ After the loss is minimized, it can be used for further action.
○ Gradient descent is one of the algorithms commonly used for loss minimization.
● Test the hypothesis function-
○ The hypothesis function needs to be checked on as well, as it is predicting values.
○ Once this is done, it has to be tested on test data.
Advantages of Multivariate Regression
1. Improved Predictive Accuracy: Multivariate regression can provide a more
accurate and nuanced model than simple linear regression by incorporating
multiple predictors.
2. Handles Complex Relationships: It can capture the relationships between
the dependent variable and multiple predictors, including interactions and
combined effects, leading to a better understanding of complex data
structures.
3. Reduces Bias: Including several variables helps reduce bias by accounting
for factors that might influence the dependent variable, leading to more
reliable estimates.
4. Identifies Key Predictors: It helps determine which predictors significantly
impact the outcome, aiding in feature selection and model refinement.
5. Improves Model Fit: Multivariate regression, by considering multiple
variables, can often improve the fit of the model to the data, providing more
detailed insights into the underlying relationships.
Disadvantages of Multivariate Regression
X0 0 1 2 3 4
Y1 1 4 3 8 9
Y2 -1 -1 2 3 2
Solution
Regularized Regression
Regularized regression is an extension of linear regression that adds a penalty
term to the loss function to prevent overfitting.
Overfitting occurs when a model fits the training data too closely and performs
poorly on unseen data.
This constraint helps to reduce the magnitude and fluctuations of the coefficients
and will reduce the variance of our model.
Properties of Regularization
● Reduces overfitting: Regularization techniques such as L1 and L2
regularization add a penalty to the loss function for which the model is
optimized. This penalty term encourages the model to use simpler weights,
which helps avoid overfitting the training data.
● Reduce weights: Regularization techniques reduce model weights toward
zero, reducing the impact of input variables that are less important to model
predictions. This makes the model more interpretable and easier to
understand.
● Improves generalization performance: Regularization helps the model
generalize better to new and invisible data by reducing the model’s
dependence on the training data. This makes the model more robust and
reliable for predictions.
● Requires hyperparameter tuning: Regularization techniques require
hyperparameter tuning as the regularization parameter that controls the
strength of the penalty term. The optimal value of the hyperparameter
depends on the specific problem and the data used and finding the best value
can be a challenging task.
● Works well with high-dimensional data: Regularization techniques work
well with high-dimensional data where the number of input variables is much
larger than the number of observations. In such cases, regularization helps to
avoid the dimensionality curse, where the model becomes too complex and
overfits the data.
Advantages of Regularization
● Regularization reduces overfitting in machine learning models.
● Regularization improves generalization performance and makes models more
reliable.
● Regularization increases the interpretability of the model and makes it easier
to understand.
● Regularization works well with multidimensional data and helps avoid the
dimensionality curse.
● Regularization provides a compromise between bias and variance in the
model.
● Adjusting the normalization parameter can help correct the bias-variance
trade-off for the best results.
Limitations of Regularization
● Regularization can make the model too simple and unsuitable for the data if
the regularization parameter is too large. This can cause the model to miss
important patterns in the data.
● Regularization assumes that all input variables are of equal importance, which
may not be true in some cases. Using domain knowledge to weigh the
importance of input variables can help improve model performance.
● Regularization can be computationally expensive, especially for
multidimensional data. This can make it difficult to use normalization in
real-time applications.
● Regularization assumes that the data is linearly separable, which may not be
true in some cases. Non-linear models, such as neural networks, maybe a
better fit for that data.
● Regularization assumes that the data are independent and identically
distributed (IIDs), which may not be true for some types of data, such as time
series or spatial data.
What Is Regularization in Machine Learning
Regularization restricts a model to prevent overfitting by penalizing large
coefficient values, with some techniques shrinking coefficients to zero.
When a model suffers from overfitting, we should control the model's complexity.
Technically, regularization avoids overfitting by adding a penalty to the model's
loss function:
We add coefficients to the cost function which is the Mean Squared Error (Sum of
Squared Residuals Divided by Degrees of Freedom) of the regression model,
which as a result increases the cost.
The optimizer would try to minimize the coefficient to decrease the cost function.
In regularization, penalizes all the parameters except the intercept.
Types of Regularized Regression
There are three primary types of regularized regression:
Ridge regression is useful when many predictors contribute to the outcome and
need to be regularized without setting coefficients to zero.
The parameter λ controls the degree of shrinkage; higher λ values lead to smaller
coefficients.
Advantages
Reduces multicollinearity among predictors.
Elastic Net is useful when predictors are highly correlated, where Lasso alone may
randomly select one predictor and ignore the rest.
Computation Generally faster as it doesn’t involve feature selection May be slower due to the feature selection process
Use when you have many predictors, all contributing to the Use when you believe only some predictors are truly
outcome (e.g., predicting house prices where all features like important (e.g., genetic studies where only a few genes out of
Example Use Case size, location, etc., matter) thousands are relevant).
Features Lasso Regression Ridge Regression Elastic Net Regression
L1 Penalty: Lasso uses the L2 Penalty: Ridge uses L1 + L2 Penalty: Elastic Net
Penalty Type absolute values of the square of the uses both absolute and
coefficients. coefficients. square penalties together.
Lasso completely removes Ridge makes all
Elastic Net removes some
Effect on unnecessary features by coefficients smaller but
features and reduces others,
Coefficients setting their coefficients to doesn’t set them to
balancing both.
zero. zero.
It is good when all
It is best when you have
features are useful, but It is best for when you have
It is best for many features and want to
you want to reduce many correlated features
remove irrelevant ones
their impact.
Alpha + L1_ratio: Two
Alpha: Controls how much
Alpha: Similar to Lasso, parameters. Alpha controls
Hyperparameters regularization is applied. A
controls the strength of regularization strength, and
involved higher alpha means more
regularization. L1_ratio adjusts the balance
shrinkage.
between Lasso and Ridge.
Features Lasso Regression Ridge Regression Elastic Net Regression
High bias, low variance: Low bias, high variance: Balance of bias and variance:
Bias and Lasso makes the model Ridge keeps all features, Elastic Net tries to find the right
Variance simpler, leading to higher leading to less bias but balance between simplicity and
bias but less overfitting. possibly more overfitting. complexity.
Ridge works well when
Lasso is great for Elastic Net combines Lasso’s
features are related but
Strengths automatically choosing feature selection and Ridge’s
shouldn’t be completely
important features. handling of correlations.
removed.
Ridge keeps all features,
Lasso can sometimes
which may not help in Elastic Net is a bit harder to tune
Weaknesses remove useful features if
high-dimensional data with due to having two parameters.
not tuned properly.
irrelevant features.
Imagine you have 100
If you have 100 features,
features to predict house If you have features like “size”
Ridge will reduce the
prices. Lasso will set the and “rooms” that are similar,
Example impact of every feature but
coefficients of irrelevant Elastic Net will remove one and
won’t completely remove
features (like house color) shrink the other.
any.
Support Vector Machine
Introduction
● Key Idea: Finding the hyperplane that best separates data into classes.
● In this algorithm, we plot each data item as a point in n-dimensional space
(where n is number of features you have) with the value of each feature
being the value of a particular coordinate.
● Then, we perform classification by finding the hyperplane that differentiate
the two classes very well.
Hyperplane in SVM
How SVM works ?
● The main objective is to segregate the given dataset in the best possible
way.
● The distance between the either nearest points is known as the margin.
● The objective is to select a hyperplane with the maximum possible margin
between support vectors in the given dataset. SVM searches for the
maximum marginal hyperplane in the following steps:
– Generate hyperplanes which segregates the classes in the best way.
– Select the right hyperplane with the maximum segregation from the
either nearest data points.
Non-linear and inseparable planes
1. The C parameter in SVM is mainly used for the Penalty parameter of the
error term.
2. You can consider it as the degree of correct classification that the
algorithm has to meet or the degree of optimization the SVM has to meet.
3. Controls the tradeoff between the classification of training points
accurately and a smooth decision boundary or in a simple word, it suggests
the model choose data points as a support vector.
Regularization parameter C
For large C – then model choose For small C – If the value of C is
more data points as a support vector small then the model chooses fewer
and we get the higher variance and data points as a support vector and
lower bias, which may lead to the gets lower variance/high bias.
problem of overfitting
The value of gamma and C should not be very high because it leads to overfitting
or it shouldn’t be very small (underfitting). Thus we need to choose the optimal
value of C.
Gamma Parameter: