> ## Documentation Index
> Fetch the complete documentation index at: https://ai.tharung.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Statistics

## Table of Contents

* [1. Introduction](#1-introduction)
* [2. Population vs Sample](#2-population-vs-sample)
* [3. Types of Data](#3-types-of-data)
* [4. Levels of Measurement](#4-levels-of-measurement)
* [5. Descriptive Statistics](#5-descriptive-statistics)
* [6. Measures of Central Tendency](#6-measures-of-central-tendency)
* [7. Measures of Dispersion](#7-measures-of-dispersion)
* [8. Percentiles and Quartiles](#8-percentiles-and-quartiles)
* [9. Outliers](#9-outliers)
* [10. Skewness](#10-skewness)
* [11. Kurtosis](#11-kurtosis)
* [12. Covariance](#12-covariance)
* [13. Correlation](#13-correlation)
* [14. Sampling](#14-sampling)
* [15. Sampling Distribution](#15-sampling-distribution)
* [16. Central Limit Theorem](#16-central-limit-theorem)
* [17. Confidence Interval](#17-confidence-interval)
* [18. Statistical Inference](#18-statistical-inference)
* [19. Hypothesis Testing](#19-hypothesis-testing)
* [20. P-value](#20-p-value)
* [21. Type I & Type II Errors](#21-type-i--type-ii-errors)
* [22. Statistical Tests](#22-statistical-tests)
* [23. Feature Scaling](#23-feature-scaling)
* [24. Standardization](#24-standardization)
* [25. Normalization](#25-normalization)
* [26. Z-Score](#26-z-score)
* [27. Missing Data](#27-missing-data)
* [28. Cheat Sheet](#28-cheat-sheet)

***

# 1. Introduction

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

In AI and Machine Learning, statistics helps to:

* Understand datasets
* Discover patterns
* Build predictive models
* Evaluate model performance
* Make data-driven decisions

***

# 2. Population vs Sample

| Population         | Sample               |
| ------------------ | -------------------- |
| Entire dataset     | Subset of population |
| Parameter (μ, σ)   | Statistic (x̄, s)    |
| Large              | Smaller              |
| Expensive to study | Easier to analyze    |

### Example

**Population**

```text theme={null}
All students in India
```

**Sample**

```text theme={null}
1000 randomly selected students
```

***

# 3. Types of Data

## Numerical Data

Numeric values used for calculations.

Examples

* Age
* Height
* Weight
* Salary

### Continuous Data

Can take any value.

Example

```text theme={null}
Height = 170.35 cm
```

### Discrete Data

Countable values.

Example

```text theme={null}
Cars = 5
```

***

## Categorical Data

Represents categories.

Examples

* Gender
* Department
* Blood Group
* Country

***

# 4. Levels of Measurement

| Level    | Description                    | Example          |
| -------- | ------------------------------ | ---------------- |
| Nominal  | Categories only                | Gender           |
| Ordinal  | Ordered categories             | Rank             |
| Interval | Equal intervals, no true zero  | Temperature (°C) |
| Ratio    | Equal intervals with true zero | Height           |

***

# 5. Descriptive Statistics

Descriptive statistics summarize a dataset.

Common measures include:

* Mean
* Median
* Mode
* Variance
* Standard Deviation
* Range
* Quartiles

***

# 6. Measures of Central Tendency

## Mean

Average of all observations.

### Formula

$$
\bar{x}=\frac{\sum x_i}{n}
$$

### Python

```python theme={null}
import numpy as np

data = [10,20,30,40]

np.mean(data)
```

***

## Median

Middle value after sorting.

Python

```python theme={null}
np.median(data)
```

***

## Mode

Most frequently occurring value.

Python

```python theme={null}
from scipy import stats

stats.mode([1,2,2,3,3,3])
```

***

# 7. Measures of Dispersion

Shows how spread out the data is.

## Range

Formula

$$
Range = Maximum - Minimum
$$

Python

```python theme={null}
max(data) - min(data)
```

***

## Variance

Average squared deviation from the mean.

Population Variance

$$
\sigma^2=\frac{\sum(x-\mu)^2}{N}
$$

Sample Variance

$$
s^2=\frac{\sum(x-\bar{x})^2}{n-1}
$$

Python

```python theme={null}
np.var(data)
```

***

## Standard Deviation

Square root of variance.

Formula

$$
\sigma=\sqrt{\sigma^2}
$$

Python

```python theme={null}
np.std(data)
```

Interpretation

* High SD → More variation
* Low SD → Less variation

***

# 8. Percentiles and Quartiles

## Percentile

Indicates the percentage of observations below a value.

Example

```text theme={null}
90th percentile
```

means

```text theme={null}
90% of observations lie below this value.
```

Python

```python theme={null}
np.percentile(data, 90)
```

***

## Quartiles

| Quartile | Percentage   |
| -------- | ------------ |
| Q1       | 25%          |
| Q2       | 50% (Median) |
| Q3       | 75%          |

### Interquartile Range (IQR)

$$
IQR = Q3 - Q1
$$

Python

```python theme={null}
np.percentile(data, [25,50,75])
```

***

# 9. Outliers

Outliers are observations that are significantly different from the rest.

### IQR Rule

Lower Bound

$$
Q1-1.5(IQR)
$$

Upper Bound

$$
Q3+1.5(IQR)
$$

Values outside these limits are considered outliers.

***

# 10. Skewness

Measures asymmetry of data.

| Type       | Relationship   |
| ---------- | -------------- |
| Symmetric  | Mean = Median  |
| Right Skew | Mean > Median  |
| Left Skew  | Mean \< Median |

Python

```python theme={null}
from scipy.stats import skew

skew(data)
```

***

# 11. Kurtosis

Measures tail heaviness.

* High Kurtosis → More Outliers
* Low Kurtosis → Fewer Outliers

Python

```python theme={null}
from scipy.stats import kurtosis

kurtosis(data)
```

***

# 12. Covariance

Measures whether two variables move together.

Positive Covariance

```text theme={null}
↑ ↑
```

Negative Covariance

```text theme={null}
↑ ↓
```

Formula

$$
Cov(X,Y)
$$

Python

```python theme={null}
np.cov(x, y)
```

***

# 13. Correlation

Measures strength and direction of a relationship.

Range

$$
-1 \le r \le 1
$$

| Correlation | Meaning          |
| ----------- | ---------------- |
| +1          | Perfect Positive |
| 0           | No Relationship  |
| -1          | Perfect Negative |

Python

```python theme={null}
np.corrcoef(x, y)
```

***

# 14. Sampling

Sampling is selecting a subset from a population.

Methods

* Simple Random Sampling
* Stratified Sampling
* Cluster Sampling
* Systematic Sampling

***

# 15. Sampling Distribution

Distribution of a sample statistic.

Used in

* Confidence Interval
* Hypothesis Testing

***

# 16. Central Limit Theorem

If sample size is sufficiently large,

$$
n \ge 30
$$

then the sampling distribution of the mean becomes approximately normal.

Why important?

* Enables hypothesis testing
* Basis for confidence intervals
* Foundation of statistical inference

***

# 17. Confidence Interval

Range likely to contain the population parameter.

95% Confidence Interval

$$
\bar{x}\pm z\frac{\sigma}{\sqrt n}
$$

Interpretation

```text theme={null}
We are 95% confident that the population mean lies within this interval.
```

***

# 18. Statistical Inference

Drawing conclusions about a population using sample data.

Includes

* Confidence Interval
* Hypothesis Testing

***

# 19. Hypothesis Testing

### Null Hypothesis

```text theme={null}
H₀
```

### Alternative Hypothesis

```text theme={null}
H₁
```

Example

```text theme={null}
H₀ : New model is not better

H₁ : New model performs better
```

***

# 20. P-value

Probability of obtaining the observed result assuming H₀ is true.

Decision Rule

| P-value | Decision          |
| ------- | ----------------- |
| \< 0.05 | Reject H₀         |
| ≥ 0.05  | Fail to Reject H₀ |

***

# 21. Type I & Type II Errors

## Type I Error

False Positive

Reject a true null hypothesis.

***

## Type II Error

False Negative

Fail to reject a false null hypothesis.

***

# 22. Statistical Tests

| Test            | Purpose                 |
| --------------- | ----------------------- |
| Z-Test          | Large samples           |
| T-Test          | Small samples           |
| Chi-Square Test | Categorical data        |
| ANOVA           | Compare multiple groups |

***

# 23. Feature Scaling

Scaling ensures features have comparable ranges.

Example

| Feature | Range            |
| ------- | ---------------- |
| Age     | 20–60            |
| Salary  | 10,000–1,000,000 |

Benefits

* Faster convergence
* Better optimization
* Improved ML accuracy

***

# 24. Standardization

Transforms data to

* Mean = 0
* Standard Deviation = 1

Formula

$$
z=\frac{x-\mu}{\sigma}
$$

Python

```python theme={null}
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()

scaled = scaler.fit_transform(X)
```

***

# 25. Normalization

Scales values between 0 and 1.

Formula

$$
x'=\frac{x-min}{max-min}
$$

Python

```python theme={null}
from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()

scaled = scaler.fit_transform(X)
```

***

# 26. Z-Score

Measures distance from the mean.

Formula

$$
z=\frac{x-\mu}{\sigma}
$$

Interpretation

| Z-score | Meaning    |
| ------- | ---------- |
| 0       | Mean       |
| +2      | Above Mean |
| -2      | Below Mean |

Python

```python theme={null}
from scipy.stats import zscore

zscore(data)
```

***

# 27. Missing Data

Common approaches

* Remove Rows
* Remove Columns
* Mean Imputation
* Median Imputation
* Mode Imputation

Python

```python theme={null}
import pandas as pd

df.fillna(df.mean())
```

***

# Statistics Libraries

```python theme={null}
import numpy as np
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
import sklearn
```

***

# 28. Cheat Sheet

| Concept             | Purpose                       |
| ------------------- | ----------------------------- |
| Mean                | Average                       |
| Median              | Middle Value                  |
| Mode                | Most Frequent Value           |
| Variance            | Spread                        |
| Standard Deviation  | Dispersion                    |
| Quartiles           | Divide Dataset                |
| IQR                 | Detect Outliers               |
| Skewness            | Asymmetry                     |
| Kurtosis            | Tail Heaviness                |
| Covariance          | Direction of Relationship     |
| Correlation         | Strength of Relationship      |
| CLT                 | Sampling Theory               |
| Confidence Interval | Estimate Population Parameter |
| Hypothesis Test     | Statistical Decision          |
| P-value             | Evidence Against H₀           |
| Z-score             | Distance from Mean            |
| Standardization     | Mean = 0, SD = 1              |
| Normalization       | Scale Between 0 and 1         |

***
