Table of Contents

    Statistics Fundamentals

    Mathematics for Machine Learning

    Statistics Fundamentals

    Learn the essential statistical concepts required for Machine Learning, including data types, central tendency, dispersion, probability, correlation, sampling, hypothesis testing, and real-world ML usage.

    Introduction

    Statistics is one of the most important foundations of Machine Learning. Machine Learning models learn from data, and statistics helps us understand that data properly before building any model. It gives us techniques to collect, organize, summarize, analyze, interpret, and present data in a meaningful way.

    In Machine Learning, we do not directly feed raw data into a model without understanding it. First, we study the data using statistical methods. We check the average value, spread of data, missing values, outliers, relationships between variables, and uncertainty. This process helps us make better decisions during data preprocessing, feature engineering, model selection, and model evaluation.

    Simple Meaning: Statistics helps us understand what the data is saying before we ask a Machine Learning model to learn from it.

    Why Statistics is Important in Machine Learning?

    Machine Learning is data-driven. If we do not understand the data, we cannot build reliable models. Statistics helps us discover patterns, detect unusual values, understand relationships, and measure uncertainty. These ideas are directly connected to almost every step of the Machine Learning workflow.

    Data Understanding

    • Helps summarize large datasets
    • Shows average, spread, and distribution
    • Helps detect missing values and outliers
    • Makes Exploratory Data Analysis easier

    Data Preprocessing

    • Helps in normalization and standardization
    • Supports outlier detection
    • Improves feature scaling decisions
    • Helps prepare clean data for modeling

    Model Building

    • Helps select useful features
    • Supports probability-based algorithms
    • Improves model interpretation
    • Helps understand prediction uncertainty

    Model Evaluation

    • Helps interpret error metrics
    • Supports confidence in model results
    • Helps compare models fairly
    • Useful in validation and testing

    Prerequisites to Learn Statistics Fundamentals

    Before learning statistics for Machine Learning, students should have basic knowledge of the following topics:

    Required Knowledge

    • Basic Mathematics: Addition, subtraction, multiplication, division, percentages, and ratios.
    • Algebra Basics: Understanding variables, equations, and simple formulas.
    • Data Understanding: Basic idea of rows, columns, datasets, and features.
    • Python Basics: Helpful for calculating statistics using code.
    • NumPy and Pandas: Useful for working with numerical and tabular data.
    • Graph Reading: Basic ability to understand bar charts, histograms, and line charts.

    What is Statistics?

    Definition
    Statistics is the study of collecting, organizing, analyzing, interpreting, and presenting data.

    Statistics converts raw data into useful information. For example, if we have marks of 100 students, statistics helps us find the average marks, highest marks, lowest marks, how much marks vary, and whether the performance is consistent or not.

    Simple Classroom Analogy

    If a teacher has marks of all students, statistics helps the teacher understand overall class performance, identify weak areas, detect top performers, and decide where improvement is needed.

    Types of Statistics

    Statistics is mainly divided into two major types: Descriptive Statistics and Inferential Statistics.

    1

    Descriptive Statistics

    Descriptive statistics summarizes and describes the main features of a dataset.

    It tells us what is present in the data. It does not make predictions about future data. It only explains the current dataset using measures such as mean, median, mode, range, variance, standard deviation, and charts.

    2

    Inferential Statistics

    Inferential statistics uses sample data to make conclusions or predictions about a larger population.

    It helps us generalize results from a small group to a larger group. It includes concepts such as sampling, confidence intervals, hypothesis testing, p-values, and statistical significance.

    Type Purpose Example
    Descriptive Statistics Summarizes existing data Average salary of employees in a dataset
    Inferential Statistics Makes conclusions about a larger population Predicting average salary of all employees using a sample

    Data in Statistics

    In statistics, data means collected facts, values, observations, or measurements. In Machine Learning, data is usually arranged in rows and columns. Each row represents an observation, and each column represents a feature or variable.

    Example Dataset

    Student ID Study Hours Attendance Marks
    101 5 90% 82
    102 3 75% 68
    103 6 95% 88
    104 2 60% 55

    In this dataset, Study Hours, Attendance, and Marks are numerical values that can be analyzed statistically.

    Types of Data

    Understanding the type of data is important because different statistical methods are used for different data types.

    1

    Qualitative Data

    Qualitative data describes categories or labels.

    Examples include gender, city name, product category, blood group, department, and customer feedback type. This type of data is also called categorical data.

    2

    Quantitative Data

    Quantitative data represents numerical values.

    Examples include age, salary, marks, temperature, weight, height, product price, and number of purchases.

    Subtypes of Quantitative Data

    Type Meaning Example
    Discrete Data Countable numerical data Number of students, number of orders
    Continuous Data Measurable data that can take decimal values Height, weight, temperature, salary

    Population and Sample

    Two important terms in statistics are population and sample. These terms are especially important in inferential statistics.

    1

    Population

    Population means the complete group that we want to study.

    For example, if we want to study the marks of all students in a university, then all students of that university are the population.

    2

    Sample

    Sample means a smaller part selected from the population.

    For example, if we select 200 students from the university and study their marks, then those 200 students form a sample.

    Important: In Machine Learning, we often work with sample data and try to build a model that performs well on unseen data from the larger population.

    Measures of Central Tendency

    Measures of central tendency describe the center or typical value of a dataset. The three most common measures are Mean, Median, and Mode.

    1

    Mean

    Mean is the arithmetic average of all values.

    It is calculated by adding all values and dividing by the total number of values.

    MEAN FORMULA
    \( \bar{x} = \frac{x_1 + x_2 + x_3 + ... + x_n}{n} \)

    Example: Marks = 80, 70, 90, 60, 100

    CALCULATION
    \( \bar{x} = \frac{80 + 70 + 90 + 60 + 100}{5} = \frac{400}{5} = 80 \)

    So, the mean marks are 80.

    2

    Median

    Median is the middle value when data is arranged in ascending or descending order.

    Median is useful when the data contains outliers because it is less affected by extremely large or small values.

    MEDIAN RULE
    If \( n \) is odd: Middle value
    If \( n \) is even: Average of two middle values

    Example: Data = 10, 20, 30, 40, 50

    MEDIAN
    Middle value = 30
    3

    Mode

    Mode is the value that appears most frequently in a dataset.

    Mode is useful for categorical data and repeated values.

    Example: Data = 2, 3, 3, 5, 6, 3, 8

    MODE
    Mode = 3

    Mean vs Median vs Mode

    Measure Meaning Best Used When
    Mean Average value Data has no extreme outliers
    Median Middle value Data contains outliers
    Mode Most frequent value Finding most common category or value
    Important: Mean can be strongly affected by outliers. Median is often better when data has extreme values.

    Measures of Dispersion

    Measures of dispersion tell us how spread out the data values are. Two datasets may have the same mean but different levels of spread. In Machine Learning, spread is important because highly scattered data may affect model performance.

    1

    Range

    Range is the difference between the maximum and minimum value.

    RANGE FORMULA
    \( Range = Maximum\ Value - Minimum\ Value \)
    2

    Variance

    Variance measures how far data values are spread from the mean.

    It calculates the average of squared differences from the mean. Larger variance means data is more spread out.

    POPULATION VARIANCE
    \( \sigma^2 = \frac{\sum (x_i - \mu)^2}{N} \)
    SAMPLE VARIANCE
    \( s^2 = \frac{\sum (x_i - \bar{x})^2}{n - 1} \)
    3

    Standard Deviation

    Standard deviation is the square root of variance.

    It shows how much the values usually differ from the mean. Standard deviation is easier to interpret than variance because it is in the same unit as the original data.

    STANDARD DEVIATION
    \( \sigma = \sqrt{\frac{\sum (x_i - \mu)^2}{N}} \)
    4

    Interquartile Range

    Interquartile Range, or IQR, measures the spread of the middle 50% of data.

    It is useful for detecting outliers and understanding data spread around the median.

    IQR FORMULA
    \( IQR = Q_3 - Q_1 \)

    Dispersion Measures Summary

    Measure Meaning Machine Learning Use
    Range Difference between maximum and minimum values Quick check of data spread
    Variance Average squared distance from mean Understanding variability
    Standard Deviation Typical distance from mean Feature scaling and data interpretation
    IQR Spread of middle 50% values Outlier detection

    Data Distribution

    A distribution describes how data values are spread. It shows whether values are concentrated around the center, spread widely, or skewed toward one side.

    Normal Distribution

    A normal distribution is a bell-shaped distribution where most values are near the mean, and fewer values appear far away from the mean. Many natural and real-world measurements approximately follow normal distribution.

    NORMAL DISTRIBUTION IDEA
    Most values are near the mean, fewer values are far from the mean.

    Skewness

    Skewness shows whether data is symmetric or tilted to one side. If data has a long tail on the right side, it is positively skewed. If data has a long tail on the left side, it is negatively skewed.

    Skewness Type Meaning Example
    Positive Skew Long tail on right side Income data with few very high earners
    Negative Skew Long tail on left side Easy exam where most students score high
    No Skew Data is almost symmetric Ideal bell-shaped distribution

    Kurtosis

    Kurtosis describes the heaviness of tails or peakness of a distribution. It helps us understand whether extreme values are common or rare in the dataset.

    Correlation and Covariance

    In Machine Learning, we often need to understand how two variables are related. Correlation and covariance help us measure relationships between variables.

    1

    Covariance

    Covariance shows whether two variables move together.

    If two variables increase together, covariance is positive. If one increases while the other decreases, covariance is negative. However, covariance does not have a fixed range, so it can be difficult to interpret directly.

    COVARIANCE
    \( Cov(X,Y) = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{n - 1} \)
    2

    Correlation

    Correlation measures the strength and direction of the relationship between two variables.

    Correlation values usually range from -1 to +1. A value near +1 means strong positive relationship, a value near -1 means strong negative relationship, and a value near 0 means weak or no linear relationship.

    CORRELATION RANGE
    \( -1 \le r \le +1 \)
    Correlation Value Meaning Example
    +1 Perfect positive relationship As study hours increase, marks increase perfectly
    0 No linear relationship Student shoe size and exam marks
    -1 Perfect negative relationship As speed increases, travel time decreases perfectly
    Important: Correlation does not always mean causation. If two variables are related, it does not always mean one directly causes the other.

    Probability Basics

    Probability measures the chance of an event happening. It is important in Machine Learning because many models work with uncertainty. Classification models often produce probabilities for different classes.

    PROBABILITY FORMULA
    \( P(Event) = \frac{Number\ of\ Favorable\ Outcomes}{Total\ Number\ of\ Outcomes} \)

    Example: If a coin is tossed, the probability of getting heads is:

    COIN EXAMPLE
    \( P(Heads) = \frac{1}{2} = 0.5 \)

    Common Probability Terms

    Term Meaning
    Experiment An action that gives an outcome, such as tossing a coin
    Outcome Possible result of an experiment
    Event A specific result or group of results
    Probability Chance of an event happening

    Probability Distributions

    A probability distribution shows how probabilities are assigned to different possible outcomes. Many Machine Learning algorithms are based on probability distributions.

    1

    Bernoulli Distribution

    Used when there are only two possible outcomes.

    Example: Pass or fail, yes or no, spam or not spam, disease or no disease.

    2

    Binomial Distribution

    Used for counting successes in repeated independent trials.

    Example: Number of heads in 10 coin tosses.

    3

    Normal Distribution

    Bell-shaped distribution commonly used in statistics and Machine Learning.

    Example: Heights, test scores, measurement errors, and many natural patterns often follow an approximate normal distribution.

    4

    Poisson Distribution

    Used for counting how many times an event occurs in a fixed interval.

    Example: Number of calls received per hour or number of website visits per minute.

    Inferential Statistics Concepts

    Inferential statistics helps us make conclusions about a larger population using sample data. It is useful when studying the entire population is difficult, costly, or impossible.

    1

    Hypothesis Testing

    Hypothesis testing is a method used to test an assumption using sample data.

    For example, a company may test whether a new website design increases customer purchases. Hypothesis testing helps decide whether the observed difference is meaningful or may have happened by chance.

    2

    Null Hypothesis

    The null hypothesis usually states that there is no effect or no difference.

    Example: A new teaching method does not improve student marks.

    3

    Alternative Hypothesis

    The alternative hypothesis states that there is an effect or difference.

    Example: A new teaching method improves student marks.

    4

    P-Value

    P-value helps decide whether the result is statistically significant.

    A smaller p-value usually indicates stronger evidence against the null hypothesis. In many practical cases, a p-value less than 0.05 is commonly treated as statistically significant.

    5

    Confidence Interval

    A confidence interval gives a range in which the true population value is likely to lie.

    Instead of giving only one value, a confidence interval gives a range, which is more informative when working with uncertainty.

    Sampling

    Sampling means selecting a smaller group from a larger population. In Machine Learning, we often train models using available sample data and expect them to work well on unseen data.

    Common Sampling Methods

    • Random Sampling: Every item has an equal chance of selection.
    • Stratified Sampling: Population is divided into groups, and samples are taken from each group.
    • Systematic Sampling: Every kth item is selected from a list.
    • Cluster Sampling: Entire groups or clusters are selected randomly.
    Machine Learning Connection: Train-test split is also related to sampling because we divide available data into training and testing parts.

    Central Limit Theorem

    The Central Limit Theorem is an important idea in statistics. It states that if we take many samples from a population and calculate their means, the distribution of those sample means tends to become approximately normal as the sample size becomes large.

    Simple Explanation
    Many sample averages usually form a bell-shaped distribution.

    This concept is important because it supports many statistical methods, including confidence intervals and hypothesis testing.

    Outliers in Statistics

    An outlier is a data value that is very different from other values in the dataset. Outliers can strongly affect mean, variance, standard deviation, and even Machine Learning model performance.

    Problem Caused by Outliers

    • Can make mean misleading
    • Can increase variance and standard deviation
    • Can affect model training
    • Can reduce prediction accuracy

    How to Handle Outliers

    • Use median instead of mean
    • Use IQR method
    • Use boxplots for detection
    • Apply transformation if suitable

    Python Example: Basic Statistics

    The following Python example shows how to calculate mean, median, mode, variance, standard deviation, minimum, maximum, and correlation using basic libraries.

    
    import pandas as pd
    
    # Sample dataset
    data = {
        "study_hours": [2, 3, 4, 5, 6, 7, 8],
        "marks": [50, 55, 60, 68, 75, 82, 90]
    }
    
    df = pd.DataFrame(data)
    
    # Basic statistics
    print("Mean Marks:", df["marks"].mean())
    print("Median Marks:", df["marks"].median())
    print("Mode Marks:", df["marks"].mode()[0])
    print("Variance:", df["marks"].var())
    print("Standard Deviation:", df["marks"].std())
    print("Minimum Marks:", df["marks"].min())
    print("Maximum Marks:", df["marks"].max())
    
    # Correlation
    print("Correlation:")
    print(df.corr())
    

    Expected Output Type

    
    Mean Marks: 68.57
    Median Marks: 68.0
    Mode Marks: 50
    Variance: ...
    Standard Deviation: ...
    Minimum Marks: 50
    Maximum Marks: 90
    
    Correlation:
                 study_hours     marks
    study_hours     1.000000  0.99...
    marks           0.99...   1.000000
    

    This example shows that as study hours increase, marks also increase. The correlation value will be close to 1, which indicates a strong positive relationship.

    Statistics in Machine Learning Workflow

    Statistics is used throughout the Machine Learning workflow. It is not limited to theory; it directly supports practical model building.

    ML Stage Statistical Concept Used Purpose
    Data Collection Sampling Select representative data
    EDA Mean, median, standard deviation Understand dataset behavior
    Data Cleaning Outlier detection, missing value analysis Improve data quality
    Feature Engineering Correlation, distribution analysis Select and transform useful features
    Model Training Probability and distributions Support learning and prediction
    Model Evaluation Error metrics and uncertainty Measure model performance

    Real-World Example: Statistics in House Price Prediction

    Suppose we are building a Machine Learning model to predict house prices. Statistics helps us understand important questions before model building.

    Statistical Questions

    • What is the average house price?
    • What is the median house price?
    • Are there extremely expensive houses acting as outliers?
    • How much do prices vary across locations?
    • Is house size correlated with price?
    • Are prices normally distributed or skewed?
    • Which features are most related to price?

    By answering these questions, we can clean the data, select better features, handle outliers, and build a more reliable prediction model.

    Advantages of Learning Statistics for Machine Learning

    Benefits

    • Better Data Understanding: Helps identify patterns, trends, and unusual values.
    • Improved Data Preprocessing: Helps choose proper scaling, transformation, and cleaning methods.
    • Better Feature Selection: Correlation and variance help identify useful features.
    • Model Interpretation: Helps explain model results more clearly.
    • Uncertainty Handling: Helps understand probabilities and confidence in predictions.
    • Stronger Evaluation: Helps compare model performance using statistical thinking.

    Common Mistakes Students Make

    Avoid These Mistakes

    • Using mean without checking for outliers.
    • Confusing correlation with causation.
    • Ignoring data distribution before model training.
    • Forgetting the difference between population and sample.
    • Using statistical formulas without understanding their purpose.
    • Assuming all datasets are normally distributed.
    • Not checking variance or standard deviation before scaling features.
    • Using p-value mechanically without understanding the context.

    Quick Revision

    Concept Meaning
    Statistics Study of collecting, analyzing, interpreting, and presenting data
    Descriptive Statistics Summarizes existing data
    Inferential Statistics Uses sample data to make conclusions about population
    Mean Average value
    Median Middle value
    Mode Most frequent value
    Variance Average squared spread from mean
    Standard Deviation Typical spread from mean
    Correlation Strength and direction of relationship between variables
    Probability Chance of an event happening
    Hypothesis Testing Testing assumptions using sample data

    Interview Questions on Statistics Fundamentals

    1

    What is statistics?

    Statistics is the study of collecting, organizing, analyzing, interpreting, and presenting data. It helps convert raw data into meaningful information.

    2

    Why is statistics important in Machine Learning?

    Statistics helps understand data patterns, detect outliers, measure variability, select features, handle uncertainty, and evaluate model performance.

    3

    What is the difference between descriptive and inferential statistics?

    Descriptive statistics summarizes existing data, while inferential statistics uses sample data to make conclusions or predictions about a larger population.

    4

    What is the difference between mean and median?

    Mean is the average of all values, while median is the middle value after sorting the data. Median is more useful when data contains outliers.

    5

    What does standard deviation tell us?

    Standard deviation tells us how much the values usually differ from the mean. A low standard deviation means values are close to the mean, while a high standard deviation means values are spread out.

    6

    What is correlation?

    Correlation measures the strength and direction of the relationship between two variables. Its value usually ranges from -1 to +1.

    7

    Does correlation mean causation?

    No. Correlation only shows that two variables are related. It does not prove that one variable causes the other.

    Conclusion

    Statistics Fundamentals are essential for every Machine Learning learner. Statistics helps us understand data before model building and supports important tasks such as data cleaning, feature scaling, feature selection, model evaluation, and decision-making under uncertainty.

    Concepts such as mean, median, mode, variance, standard deviation, correlation, probability, sampling, and hypothesis testing are not only theoretical ideas. They are practical tools used in real Machine Learning projects. A strong understanding of statistics makes a learner better at analyzing data, building models, interpreting results, and solving real-world problems.

    Final Takeaway

    Statistics is the language of data. If Machine Learning is about teaching computers to learn from data, then statistics is the foundation that helps us understand what the data actually means.