Numeric Data
Numeric Data
Numeric Data
57
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
1. Numeric data
Numeric data consists of values that represent quantities. These values can be used for
performing mathematical operations such as addition, subtraction, averaging, correlation,
regression, etc.
Examples: height (170 cm), weight (55 kg), marks (82), income (Rs. 50,000), temperature
(24.5°C).
Multivariate Data
Multivariate data is data involving multiple variables (two or more) recorded for each
observation or individual.
Examples:
A student's record: (height, weight, marks, attendance)
A company’s sales data: (sales, profit, number of customers)
A country’s development indicators: (GDP, literacy rate, life expectancy, inflation)
Each observation has multiple measurements.
58
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
S1 80 75 70
S2 85 78 75
Where:
n = number of observations
p = number of variables
Each row = one observation
Each column = one variable
59
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
60
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
It helps answer: How does Y change when several predictors change at the same time?
Examples:
1. Prediction
E.g., predicting house price using size, location, age.
2. Modeling relationships
Understand how hours studied, IQ, and sleep affect exam score.
3. Feature importance
Identify which variables have strongest influence.
4. Control for multiple factors
Example: UNICEF MICS data — predicting child nutrition controlling for income,
mother’s education, sanitation.
5. Forecasting
Useful for time-series + cross-sectional data.
Model Representation
The multivariate linear regression model with p predictors is:
Y = β0 + β1X1 + β2X2 + ⋯ + βpXp + ε
Where:
Y = dependent variable
X1,X2,…,Xp = predictors
β0 = intercept
β1,…,βp = regression coefficients
ε = error term
61
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
62
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Example:
Given dataset, represent this into matrix form to model: Y = β0 + β1X1 + β2X2 + ε
Obs X1 X2 Y
1 2 1 5
2 4 2 9
3 3 5 12
Solution:
Always include:
A column of 1s for the intercept
Columns for each predictor
63
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Example:
Obs X1 X2 Y
1 2 1 5
2 4 2 9
3 3 5 12
1. Form the design matrix X (include intercept column of 1s) and response vector Y
64
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
3. OLS formula
So we need:
Now,
Assignment:
A real estate analyst wants to predict house prices (in $1000s) based on:
X1 = Size of the house in hundreds of sq. ft.
X2 = Number of bedrooms
The dataset collected is:
1 2 1 150
2 3 2 200
3 4 3 250
4 5 3 300
5 6 4 350
Task: Find the estimated regression equation, using matrix formulation and OLS
estimation.
65
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
How well does the model explain the variation in the dependent variable (y)?
Where:
Numerator is sum of squares of the residuals (the difference between the
observed and predicted values).
and Denominator is the total sum of squares (the variance of the observed data).
66
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
R-squared = 0.0: The predicted points are randomly scattered, indicating the
model has no predictive power. The independent variable (x) does not explain any
variation in the dependent variable (y).
R-squared = 0.5: The predicted points show a moderate relationship with the
actual data. The model explains some variation in y, but a lot remains unexplained.
R-squared = 1.0: The predicted points perfectly align with the actual data,
indicating a perfect fit. The independent variable explains all the variation in y.
Where:
n = number of data points (observations)
k = number of predictors (features)
A higher Adjusted R-squared indicates that the model fits the data well without
including unnecessary predictors, suggesting that the chosen features are
67
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
meaningful and contribute to explaining the variability in the dependent variable.
On the other hand, a lower or negative Adjusted R-squared suggests that adding
more predictors does not improve the model’s performance and may even harm
it. This occurs when extra predictors add noise rather than value.
Both models have the same adjusted R-squared value of 0.94 explaining significant
variation in the dependent variable:
Well-Fitted Model: The predicted line aligns well with the data, capturing the
true relationship between X and y.
Overfitted Model: Though it has a high Adjusted R-squared (0.94), the line is too
wiggly, indicating the model is overfitting by learning noise instead of the true
pattern.
68
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Numerical:
A researcher is studying how study hours (X₁) and attendance rate (X₂) influence exam score
(Y) of 5 students. The dataset is:
1 2 70 50
2 3 80 60
3 4 75 65
4 5 85 80
5 6 90 85
Solution:
̂ = 5 + 6X1 + 0.3X2
Y
Student X₁ X₂ Y ̂
𝐘
1 2 70 50 (5 + 12 + 21 = 38)
2 3 80 60 (5 + 18 + 24 = 47)
3 4 75 65 (5 + 24 + 22.5 = 51.5)
4 5 85 80 (5 + 30 + 25.5 = 60.5)
(5 + 36 + 27 =
5 6 90 85
68)
69
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
The sum of squares total (SST) or the total sum of squares (TSS) is the sum of
squared differences between the observed dependent variables and the overall mean.
̅:
First find 𝐘
Now compute:
Y ̅
Y−𝐘 ̅)2
(Y−𝐘
50 -18 324
60 -8 64
65 -3 9
80 12 144
85 17 289
SST=324+64+9+144+289= 830
The sum of squares due to regression (SSR) or explained sum of squares (ESS) is the
sum of the differences between the predicted value and the mean of the dependent
variable. In other words, it describes how well our line fits the data.
Compute deviations:
𝐘̂ ̂−68
𝐘 ̂−68)2
(𝐘
38 –30 900
47 –21 441
51.5 –16.5 272.25
60.5 –7.5 56.25
68 0 0
70
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
4. Calculate SSE
The sum of squares error (SSE) or residual sum of squares (RSS, where residual means
remaining or unexplained) is the difference between the observed and predicted values.
Y ̂
𝐘 ̂
Residual e=Y−𝐘 e2
50 38 12 144
60 47 13 169
85 68 17 289
6. Calculate Adjusted R²
71
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Final Results
Assignment:
A researcher wants to predict exam score (Y) using study hours (X₁) and attendance
(%) (X₂). The sample (n = 6) is:
1 2 50 37.0
2 3 60 47.0
3 4 65 54.5
4 5 70 60.0
5 6 80 68.0
6 7 90 79.0
Python Implementation:
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from [Link] import r2_score
model = LinearRegression()
72
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
[Link](X, y)
# Evaluation - R-squared:
r2 = r2_score(y, y_pred)
print(f"R-squared: {r2:.4f}")
73
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Multi-collinearity
Multicollinearity is a statistical phenomenon that occurs when two or more independent
variables in a regression model are highly correlated, indicating a strong linear relationship
among the predictor variables.
Multicollinearity occurs in a multiple regression model when two or more predictor
variables are highly correlated with each other.
Mathematically, if
and this linear relationship is strong, then variable Xj is nearly a linear combination of other
predictors → multicollinearity.
For example, in a regression model, variables such as height and weight or household
income and water consumption often show high correlation.
If the correlation between two variables is +/- 1.0, then the variables are said to
be perfectly collinear.
Problems Caused:
74
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Variance-inflation factors
The VIF is a common and effective way to detect multicollinearity. It measures how much
the variance of an estimated regression coefficient is increased due to the correlation among
the predictors. Here’s how to interpret VIF values:
o VIF = 1: Indicates no correlation.
o 1 < VIF < 5: Suggests moderate correlation.
75
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
o VIF > 5: Indicates high correlation, problematic; needs attention
o VIF > 10: This signals serious multicollinearity
Where:
Numerical:
Given the following R2 values, compute VIF of each predictor. Identify which
predictor suffers from multicollinearity.
X₁ 0.80
X₂ 0.55
X₃ 0.92
Solution:
We have:
Given:
Now:
76
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
77
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Yesterday at 12 PM
Last week at 12 PM
Other nearby times
Imagine you want to estimate the temperature at noon in the city center, but you only
have temperature readings from nearby weather stations.
Stations close to the city center → more reliable for your estimate → higher
weight.
Stations far away → less reliable → lower weight.
You compute a weighted average of all station temperatures.
It’s like averaging nearby points — but smarter, because closer points count
more.
Non-parametric → No assumption of a straight line or specific curve.
Bandwidth matters → It decides how “wide” your neighborhood is:
o Wide → smooth, general trend
o Narrow → follows every tiny fluctuation
78
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Imagine you want to estimate the temperature at noon in the city center, but you only
have temperature readings from nearby weather stations.
Stations close to the city center → more reliable for your estimate → higher
weight.
Stations far away → less reliable → lower weight.
1 25 0.5
3 24 0.3
5 22 0.2
Weighted average:
79
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Derivation:
80
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
81
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
One common method for selecting the bandwidth is the rule of thumb, which is
based on minimizing the Mean Squared Error (MSE).
A typical heuristic for bandwidth selection is:
where:
σ = standard deviation of X
n = number of samples
5. Cross-validation:
In practice, a heuristic selection process might be used based on trial and error.
For example:- If the data is highly variable, a larger bandwidth is chosen to smooth
out fluctuations.
If the data is relatively smooth, a smaller bandwidth might be used to capture finer
details of the relationship between the variables
82
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
83
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
This ensures variables are on the same scale, especially important when variables
are in different units (marks, height, age, etc.)
84
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
85
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
86
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Numerical Example:
Compute PC1 for below dataset:
Solution:
Step 1: Start with data
1 126 78
2 128 80
3 128 82
4 130 82
5 132 86
87
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
Similarly,
88
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
So,
Eigen values
λ1= 1.9455 and λ2 = 0.0545
We solve:
89
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
V2 = 0.9997 V1
V1 = V2 / 0.9997
So the Eigen vector is:
𝑥1 1
V1 = [ ]=[ ]
𝑥2 0.9997
Normalizing this to unit vector, we get:
1 1
V1= [
√12 +𝑜.99972
0.9997
1.414
] = [0.9997]= [0.707]
0.706
√12 +0.99972 1.414
= 0.707(−1.2280)+0.706(−1.2131)
1 –1.2280 –1.2131 = −0.8678−0.8554
= −1.7232
= 0.707(−0.3507)+0.706(−0.5390)
2 –0.3507 –0.5390 = −0.2476−0.3807
= −0.6283
90
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
= 0.707(−0.3507)+0.706(0.1349)
3 –0.3507 0.1349 = −0.2476+0.0952
= −0.1524
= 0.707(0.5261)+0.706(0.1349)
4 0.5261 0.1349 = 0.3720+0.0952
= 0.4672
= 0.707(1.4033)+0.706(1.4832)
1.4033
5 1.4832 = 0.9921+1.0460
= 2.0381
They tell us how much each original variable contributes to that PC.
91
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026
3. Numeric Data
o Same sign → variables increase together along this PC.
o Opposite signs → one increases while the other decreases.
In our example, Systolic and Diastolic have similar positive loadings → both
increase together.
Understanding PC Scores
Once we have PCs, we can calculate a score for each observation.
Example: For a person with high Systolic and Diastolic BP, the PC1 score will be
high.
This tells us where each person lies along the “main pattern” captured by the
PC.
***
92
Compiled by: Er. Shiva Ram Dam | Data Science and Analytics | BE | PU | 2026