Curve Fitting & Approximation
Curve Fitting & Approximation
Approximation
Applications:
• Data modeling
• Forecasting
• Trend analysis
Application : Forecasting
• The goal is to find the best-fitting line that minimizes the difference
(error) between the actual data points and the predicted values.
Key Concepts of Linear Regression:
• Equation of a Line:
The general form of a linear regression model is:
Objective of Linear regression
Questions:
(1) Write a linear equation that best fits the data in the table above.
(2) Find predicted value for x = 4.2
(3) Find sum of squared errors (SSE)
We know,
𝑛 σ 𝑥𝑦 − σ 𝑥 σ 𝑦
Slope, 𝑎1 =
𝑛 σ 𝑥 2 − ( σ 𝑥 )2
σ 𝑦 − 𝑎1 σ 𝑥
Intercept, 𝑎0 =
𝑛
Predicted value, 𝑦ො = 𝑎0 + 𝑎1 𝑥
𝑛
Sum of squared errors, SSE = 𝑖=1 𝑦𝑖 − 𝑦ො𝑖 2
Soln:
x y xy 𝑥2
1 205
2.5 213
3.9 220
4.2 226
6.1 229
7.3 234
8.2 238
σ 𝑥 = 33.2 σ 𝑦 = 1565
𝑛 σ 𝑥𝑖 𝑦𝑖 − σ 𝑥𝑖 σ 𝑦𝑖 7×7601⋅ 4 −33.2×1565
Slope, 𝑎1 = = = 4.428955562
𝑛 σ 𝑥𝑖2 − ( σ 𝑥𝑖 )2 7×197. 84 − (33.2)2
σ 𝑦𝑖 −𝑎1 σ 𝑥𝑖 1565−4.429×33.2
Intercept, 𝑎0 = = = 202.5653143
𝑛 7
• Predicted value for x = 4.2 is
𝑦ො = 𝑎0 + 𝑎1 𝑥 = 202.5653143 + 4.428955562 × 4.2 = 221.1669277
𝒏
• Sum of squared errors, SSE = 𝒊=𝟏 ෝ𝒊
𝒚𝒊 − 𝒚 𝟐
𝑦ො
𝑦 − 𝑦ො 2
Polynomial Regression
• Some engineering data, is poorly represented by a straight line.
For these cases, a curve would be better suited to fit these data.
We know polynomials expressions show curve. Therefore, to fit
polynomials to the data we use polynomial regression.
• 𝐹𝑜𝑟 𝑚 𝑑𝑎𝑡𝑎 𝑝𝑜𝑖𝑛𝑡𝑠 𝑥1 , 𝑦1 , 𝑥2 , 𝑦2 , 𝑥3 , 𝑦3 , …., 𝑥𝑚 , 𝑦𝑚
constructing a system of equations that minimizes the sum of the
squared residuals using the least squares method. The resulting
matrix equation has the form:
Matrix multiplication using a calculator:
y 2 3 5 7 11
a) Find the line of best fit for the given data of heights and weights of students
of a school using the Least Square method.
b) If a student has height of 165 cm, what is his predicted weight ?
2. Suppose you are working in the field of finance, and you are analyzing the relationship between the years of
experience (in years) an employee has and their corresponding salary (in thousand taka). You suspect that the
relationship might not be linear and that higher degrees of the polynomial might better capture the salary
progression over time.
Years of 1 2 3 4 5 6
experience, x