1.
Statistical Inference:
Statistical inference is about making decisions or predictions about a population
based on a sample
Using data analysis and statistics to make conclusions about a population is
called statistical inference.
The main types of statistical inference are:
• Estimation
• Hypothesis testing
Estimation
Statistics from a sample are used to estimate population parameters.
The most likely value is called a point estimate.
There is always uncertainty when estimating.
The uncertainty is often expressed as confidence intervals defined by a likely
lowest and highest value for the parameter.
➔ An example could be a confidence interval for the number of bicycles a
Dutch person owns:
"The average number of bikes a Dutch person owns is between 3.5 and 6."
Hypothesis Testing
Hypothesis testing is a method to check if a claim about a population is true.
More precisely, it checks how likely it is that a hypothesis is true is based on the
sample data.
There are different types of hypothesis testing.
The steps of the test depends on:
• Type of data (categorical or numerical):
If you are looking at:
o A single group
o Comparing one group to another
o Comparing the same group before and after a change
Some examples of claims or questions that can be checked with hypothesis
testing:
• 90% of Australians are left-handed
• Is the average weight of dogs more than 40kg?
• Do doctors make more money than lawyers?
Probability Distributions
Statistical inference methods rely on probability calculation and probability
distributions.
2. Classification of Machine Learning
At a broad level, machine learning can be classified into three types:
1. Supervised learning
2. Unsupervised learning
3. Reinforcement learning
1) Supervised Learning
In supervised learning, sample labeled data are provided to the machine
learning system for training, and the system then predicts the output based on
the training data.
The system uses labeled data to build a model that understands the datasets
and learns about each one. After the training and processing are done, we test
the model with sample data to see if it can accurately predict the output.
The mapping of the input data to the output data is the objective of supervised
learning. The managed learning depends on oversight, and it is equivalent to
when an understudy learns things in the management of the educator. Spam
filtering is an example of supervised learning.
Supervised learning can be grouped further in two categories of algorithms:
o Classification
o Regression
2) Unsupervised Learning
Unsupervised learning is a learning method in which a machine learns without
any supervision.
The training is provided to the machine with the set of data that has not been
labeled, classified, or categorized, and the algorithm needs to act on that data
without any supervision. The goal of unsupervised learning is to restructure the
input data into new features or a group of objects with similar patterns.
In unsupervised learning, we don't have a predetermined result. The machine
tries to find useful insights from the huge amount of data. It can be further
classifieds into two categories of algorithms:
o Clustering
o Association
3) Reinforcement Learning
Reinforcement learning is a feedback-based learning method, in which a
learning agent gets a reward for each right action and gets a penalty for each
wrong action. The agent learns automatically with these feedbacks and
improves its performance. In reinforcement learning, the agent interacts with the
environment and explores it. The goal of an agent is to get the most reward
points, and hence, it improves its performance.
The robotic dog, which automatically learns the movement of his arms, is an
example of Reinforcement learning.
3. I/O Functions
In machine learning, I/O functions refer to the input/output operations that handle the
data flow into and out of the system. These functions are crucial for feeding data into
machine learning models for training and then extracting predictions or results.
1. Input Functions (I/O for Data Loading and Preprocessing):
Input functions handle the reading and loading of data into the machine learning
pipeline. This involves bringing data from various sources such as CSV files, databases,
images, or even real-time streams into memory.
• Reading Data:
Pandas: Functions like `pandas.read_csv()`, `pandas.read_excel()`,
`pandas.read_sql()`, etc., are widely used to load tabular data from CSV, Excel,
or SQL databases.
NumPy: For numerical data, `[Link]()` or `[Link]()` are
often used.
Image Data: Libraries like OpenCV (`[Link]()`) or PIL (`[Link]()`)
handle image inputs.
TensorFlow / PyTorch: Provide functions like
`[Link].from_tensor_slices()` or `[Link]()` to
read, preprocess, and load datasets in batches for training.
• Preprocessing Data:
After loading, the data is often preprocessed (e.g., scaling, normalization,
encoding). Scikit-learn offers functions like `StandardScaler().fit_transform()`
for normalization and `LabelEncoder()` for encoding categorical variables.
For text data, tokenization functions are used to convert text into numerical
inputs, such as `Tokenizer` in Keras or `CountVectorizer` in Scikit-learn.
2. Output Functions (I/O for Saving and Outputting Results):
After training a machine learning model, the results, predictions, or models
themselves are often saved or output to be used later.
• Saving Models:
Scikit-learn: The model is saved using functions like `[Link]()` or
`[Link]()` to serialize the model object for later use.
TensorFlow/Keras: Models are saved using `[Link]()` to store the
architecture and weights, or `save_weights()` to only save the weights.
PyTorch: You save models using `[Link]()`.
Outputting Predictions:
- Predictions from a model can be written back to CSV files, databases, or displayed
directly.
- Pandas: Use `to_csv()` to save predictions in CSV format.
- Logging and Visualizing: Many frameworks have built-in functions for logging and
visualizing outputs, such as `TensorBoard` for TensorFlow or `Matplotlib` for
visualizing model performance.
4. Parametric and Non-Parametric Methods in Machine Learning
In machine learning, parametric and non-parametric methods refer to two different
types of models that make assumptions about the underlying data distribution or the
form of the function being modeled.
• Parametric Methods:
Parametric models assume a specific form for the function that maps inputs to
outputs, and they have a fixed number of parameters. The goal is to estimate these
parameters from the training data.
Key Features:
• Fixed Parameters: The model is summarized by a fixed number of parameters,
which do not grow with the size of the dataset.
• Assumptions about Data: Parametric models often make strong assumptions
about the data (e.g., linearity, normality).
• Efficient: These models are computationally efficient and require less data to
train compared to non-parametric models.
• Simple Models: Parametric methods often result in simpler models that are
easier to interpret but may not capture complex relationships well.
Examples of Parametric Models:
• Linear Regression: Assumes a linear relationship between inputs and output.
Parameters are the coefficients of the features.
• Logistic Regression: Assumes a linear relationship in the log-odds of the
outcome.
• Naive Bayes: Assumes conditional independence between features, with fixed
parameters based on class probabilities.
• Neural Networks: These can be considered parametric if the architecture
(number of layers, neurons) is fixed. The parameters are the weights between
neurons.
Pros:
• Fast to train and predict.
• Works well when the data fits the model assumptions.
Cons:
• Limited flexibility (may underfit if the assumptions about the data are incorrect).
• Poor performance with complex data that doesn't fit predefined assumptions.
• Non-Parametric Methods:
Non-parametric models do not assume a fixed form for the underlying data distribution.
Instead, the model structure is determined from the data itself, and the number of
parameters can grow with the size of the dataset.
Key Features:
• Flexible: Non-parametric models can capture more complex patterns in data
since they do not assume a fixed functional form.
• Data-Driven: These models are more flexible and can adapt to different shapes
of data distributions as they are not constrained by predefined parameters.
• Larger Data: Non-parametric methods typically require more data and are
computationally more intensive as the dataset grows.
Examples of Non-Parametric Models:
• K-Nearest Neighbors (KNN): No assumptions about data; predictions are
based on the nearest neighbors of the input.
• Decision Trees: Splits the data based on features and values, creating a model
based on observed data patterns.
• Random Forests: An ensemble of decision trees, making no strict assumptions
about the data structure.
• Kernel Density Estimation (KDE): Estimates the probability distribution of a
random variable without assuming any specific parametric distribution.
• Support Vector Machines (with non-linear kernels): Can model complex
relationships in the data by transforming it using kernels.
Pros:
• High flexibility and can model complex relationships.
• No need to assume any particular data distribution.
Cons:
• Computationally expensive, especially with large datasets.
• Can overfit if not regularized properly (too flexible).
5. Boolean Functions in Machine Learning
Boolean functions perform logical operations and return binary outcomes (0/1 or
True/False). They are crucial in several machine learning applications:
• Logical Operations: Functions like AND, OR, NOT, and XOR combine or
manipulate binary features in models.
• Decision Trees: Boolean logic is used at decision nodes to split data, making
binary decisions like if (feature >= threshold).
• Perceptrons: Simple neural networks (perceptrons) can model Boolean logic
gates (e.g., AND, OR).
• Feature Engineering: Combine binary features using Boolean functions to
create new, more informative features.
• Rule-Based Systems: Use Boolean logic in if-then rules for decision-making in
systems like expert systems.
• Binary Classifiers: Learn a Boolean-like function to separate two classes (e.g.,
classify an input as 0 or 1).
6. Sensitivity and ROC Curve in Machine Learning
Both sensitivity and the ROC curve are performance metrics used to evaluate the
effectiveness of classification models, especially binary classifiers.
1. Sensitivity (Recall or True Positive Rate):
Sensitivity, also known as recall or true positive rate (TPR), measures the model's
ability to correctly identify positive instances. It tells us how many of the actual positive
cases were correctly classified by the model.
• True Positives (TP): Correctly predicted positive instances.
• False Negatives (FN): Positive instances incorrectly predicted as negative.
A high sensitivity means the model is good at identifying all relevant instances (few false
negatives), which is crucial in tasks like disease detection, where missing a positive
case can be costly.
2. ROC Curve (Receiver Operating Characteristic Curve):
The ROC curve is a graphical representation of a classifier's performance across all
classification thresholds. It plots the true positive rate (Sensitivity) against the false
positive rate (FPR):
• True Positive Rate (TPR): Same as sensitivity.
• False Positive Rate (FPR): Measures how often the model incorrectly predicts a
negative instance as positive.
Key Points:
• The ROC curve shows how well the model distinguishes between positive and
negative classes as the decision threshold changes.
• Area Under the Curve (AUC): The AUC-ROC score summarizes the overall
performance. A perfect classifier has an AUC of 1, while a random classifier has
an AUC of 0.5.
Summary:
• Sensitivity: Measures how well a model identifies actual positives (high recall
means fewer false negatives).
• ROC Curve: Evaluates a model’s performance across various thresholds, with
AUC providing an overall performance measure.
7. Cross-Validation in Machine Learning
Cross-validation is a technique to assess how a machine learning model will
generalize to an independent dataset. It helps in selecting models and tuning
hyperparameters by testing how well the model performs on unseen data.
1. K-Fold Cross-Validation:
In K-Fold Cross-Validation, the dataset is split into K subsets (folds). The model is
trained on K-1 folds and tested on the remaining fold. This process is repeated K times,
with each fold used as the test set once. The results are averaged to get an overall
performance score.
• Steps:
a. Split the dataset into K equal parts.
b. Train the model on K-1 parts and test on the 1 remaining part.
c. Rotate the test set through all K parts and average the performance
metrics.
• Common Values: 5-fold or 10-fold cross-validation is most common.
Advantages:
• Reduces overfitting by testing on unseen data.
• More reliable performance estimates compared to a single train-test split.
2. Leave-One-Out Cross-Validation (LOO-CV):
Leave-One-Out Cross-Validation (LOO-CV) is an extreme case of K-Fold CV where K
equals the number of data points in the dataset. Essentially, the model is trained on n-1
instances and tested on the single remaining instance. This is repeated for every data
point.
• Steps:
o For each instance in the dataset, leave it out as a test set.
o Train the model on the remaining n-1 data points.
o Repeat for each data point and calculate the average performance.
Advantages:
• Makes full use of the data, as each point is used for both training and testing.
• No randomness in the test set (perfect for small datasets).
Disadvantages:
• Computationally expensive, especially for large datasets, as the model needs to
be trained n times.
• Can have high variance in performance estimates, as a small change in the
dataset can drastically affect the outcome.
Summary:
• K-Fold Cross-Validation: Efficient and commonly used. Split data into K folds,
train on K-1, and test on 1. Repeats K times.
• Leave-One-Out Cross-Validation (LOO-CV): Special case of K-fold where K
equals the dataset size. Each instance is tested once while the model trains on
the rest. Ideal for small datasets but computationally expensive.
8. Regression:
Regression is a key supervised learning technique in machine learning used to predict
continuous outcomes based on input features. It helps model relationships between a
dependent variable (target) and one or more independent variables (features).
Key Types of Regression:
• Linear Regression: Establishes a linear relationship between inputs and
outputs. It assumes the output is a linear combination of the input features.
• Polynomial Regression: Models non-linear relationships by fitting a polynomial
equation to the data.
• Ridge and Lasso Regression: Both add regularization to the basic linear model:
o Ridge (L2 regularization) helps reduce overfitting.
o Lasso (L1 regularization) performs feature selection by shrinking some
coefficients to zero.
• Logistic Regression: Used for binary classification (e.g., 0/1), predicting the
probability of a binary outcome using the sigmoid function.
Application: Regression is used in areas like predicting prices, forecasting sales, and
estimating continuous quantities, making it fundamental for real-world problem-
solving.
9. Classification:
Classification is a supervised learning technique in machine learning where the goal is
to assign input data to one of the predefined categories or classes. Unlike regression,
which predicts continuous values, classification outputs discrete labels.
Key Types of Classification:
• Binary Classification: Involves two classes (e.g., spam vs. not spam).
Algorithms like Logistic Regression and Support Vector Machines (SVM) are
commonly used for binary classification tasks.
• Multi-class Classification: Involves more than two classes (e.g., digit
recognition with 10 classes for digits 0-9). Algorithms like Decision Trees,
Random Forests, and K-Nearest Neighbors (KNN) can handle multiple
classes.
• Multi-label Classification: Each instance can belong to multiple classes
simultaneously (e.g., tagging images with multiple categories).
Common Classification Algorithms:
• Logistic Regression: Despite its name, it's used for binary classification.
• Decision Trees: Splits data based on feature values to make decisions.
• Random Forest: An ensemble method that combines multiple decision trees for
better accuracy.
• Support Vector Machine (SVM): Finds the hyperplane that best separates
different classes.
• K-Nearest Neighbors (KNN): Classifies data points based on the majority class
of their neighbors.
Applications:
Classification is widely used in spam detection, medical diagnosis, fraud detection,
and image recognition. It's a fundamental approach to solving problems where we need
to categorize data into distinct groups.
10. Pattern Recognition:
Pattern Recognition is a branch of machine learning that focuses on the classification
and interpretation of data patterns. It involves recognizing structures and regularities in
data, making it essential for tasks involving classification, regression, and clustering.
Key Concepts in Pattern Recognition:
• Feature Extraction: Identifying and selecting relevant features from the raw
data that can effectively represent the patterns. This step is crucial for improving
the accuracy and efficiency of models.
• Classification: Assigning labels to input data based on learned patterns.
Various algorithms can be employed, including:
o Decision Trees: Use a tree-like structure for decision-making.
o Support Vector Machines (SVM): Aim to find the optimal hyperplane for
separating classes.
o Neural Networks: Model complex patterns through interconnected
layers of neurons.
• Clustering: Grouping similar data points together without predefined labels.
Common clustering algorithms include:
o K-Means: Partitions data into K clusters by minimizing variance within
each cluster.
o Hierarchical Clustering: Creates a tree of clusters based on data
similarity.
• Dimensionality Reduction: Techniques like Principal Component Analysis
(PCA) and t-SNE help simplify datasets by reducing the number of features while
preserving essential patterns. This is particularly useful for visualization and
reducing computational load.
Applications:
Pattern recognition is applied in various fields such as:
• Image and Speech Recognition: Identifying objects in images or transcribing
spoken words.
• Medical Diagnosis: Analyzing medical images or patient data to detect
diseases.
• Fraud Detection: Recognizing unusual patterns in transaction data to identify
fraudulent activity.
11. Feature Selection
Feature Selection is a crucial process in machine learning that involves selecting a
subset of relevant features (variables, predictors) for use in model construction. The
main goal is to improve model performance by eliminating irrelevant or redundant data,
thereby reducing overfitting and enhancing interpretability.
Importance of Feature Selection:
• Improved Model Performance: By removing irrelevant or noisy features,
models can achieve higher accuracy and generalize better to unseen data.
• Reduced Overfitting: Simplifying the model by using fewer features can prevent
it from learning noise in the training data.
• Decreased Training Time: Fewer features lead to reduced computational cost,
allowing for faster training and evaluation.
• Enhanced Interpretability: A simpler model with fewer features is easier to
understand and explain.
Methods of Feature Selection:
• Filter Methods: Evaluate features based on their intrinsic properties, typically
using statistical tests. Common techniques include:
o Correlation Coefficient: Measures the strength of the relationship
between each feature and the target variable.
o Chi-Squared Test: Evaluates the independence between categorical
features and the target variable.
• Wrapper Methods: Use a specific machine learning algorithm to evaluate
combinations of features. These methods are more computationally intensive
but often yield better results. Examples include:
o Recursive Feature Elimination (RFE): Recursively removes the least
significant features based on model performance.
o Forward Selection: Starts with no features and adds them one at a time
based on their contribution to model accuracy.
• Embedded Methods: Perform feature selection as part of the model training
process. These methods combine the qualities of filter and wrapper methods.
Examples include:
o Lasso Regression: Uses L1 regularization to shrink some coefficients to
zero, effectively selecting important features.
o Decision Trees: Implicitly perform feature selection by choosing splits
based on the most informative features.
Applications:
Feature selection is widely used in various fields, including:
• Healthcare: Identifying key indicators for disease prediction.
• Finance: Selecting relevant financial metrics for risk assessment.
• Natural Language Processing: Reducing the dimensionality of text data in
sentiment analysis or topic modeling.
12. Clustering:
Clustering is an unsupervised learning technique in machine learning used to group a
set of data points into clusters based on their similarities. The objective is to organize
the data in such a way that points in the same cluster are more similar to each other
than to those in other clusters. Clustering is widely used in exploratory data analysis,
pattern recognition, and image processing.
Key Concepts of Clustering:
• Unsupervised Learning: Unlike supervised learning, clustering does not rely on
labeled data. The algorithm learns the structure of the data without prior
knowledge of the groups.
• Distance Metrics: Clustering algorithms often use distance metrics (such as
Euclidean, Manhattan, or Cosine similarity) to measure how similar or different
data points are.
Common Clustering Algorithms:
• K-Means Clustering:
o Divides the dataset into K predefined clusters.
o Iteratively assigns data points to the nearest cluster center and updates
the cluster centers based on the assigned points.
o Simple and efficient, but requires specifying the number of clusters in
advance.
• Hierarchical Clustering:
o Creates a tree of clusters (dendrogram) by either agglomerative (bottom-
up) or divisive (top-down) approaches.
o Does not require specifying the number of clusters upfront, and you can
choose the level of clustering by cutting the tree.
• DBSCAN (Density-Based Spatial Clustering of Applications with Noise):
o Groups together points that are closely packed (based on distance) and
marks points that lie alone in low-density regions as outliers.
o Does not require the number of clusters to be specified and can identify
clusters of varying shapes.
Applications of Clustering:
• Customer Segmentation: Identifying distinct groups within a customer base to
tailor marketing strategies.
• Image Segmentation: Grouping pixels with similar colors or intensities for
object recognition.
• Anomaly Detection: Identifying unusual patterns or outliers in data (e.g., fraud
detection).
• Document Clustering: Grouping similar documents for information retrieval or
summarization.
13. Problem of Induction:
The Problem of Induction refers to the philosophical question of how we can
generalize knowledge from specific instances to broader rules or principles. In the
context of machine learning, it pertains to the challenge of making predictions or
inferences about unseen data based on observed data.
Key Concepts:
• Inductive Reasoning: This form of reasoning involves drawing general
conclusions from specific observations. For instance, if we observe that a
particular model performs well on a set of training data, we might induce that it
will perform well on unseen data. However, this assumption can be flawed.
• Overfitting and Underfitting:
o Overfitting occurs when a model learns noise or random fluctuations in
the training data rather than the underlying patterns. This leads to poor
generalization to new data.
o Underfitting happens when a model is too simple to capture the
underlying structure of the data, resulting in low accuracy on both
training and testing datasets.
• Generalization: The primary goal of machine learning is to develop models that
generalize well to unseen data. Achieving effective induction is crucial for this
purpose, as it determines how well the model can make predictions beyond the
training set.
• Hypothesis Space: The set of all possible models or functions that can be
learned from the training data. The problem of induction is closely related to
selecting the appropriate hypothesis that best captures the underlying pattern in
the data without being too complex.
Strategies to Address the Problem of Induction:
• Cross-Validation: A technique that helps assess the model's performance by
partitioning the data into subsets, allowing for more reliable evaluation of
generalization capabilities.
• Regularization: Techniques such as Lasso and Ridge regression introduce
penalties to the model's complexity, helping prevent overfitting and encouraging
simpler models that generalize better.
• Ensemble Methods: Combining multiple models (e.g., Random Forests,
Boosting) can lead to improved generalization by leveraging the strengths of
different approaches.
• Model Selection: Using techniques like grid search and Bayesian optimization
to identify the best-performing model and hyperparameters based on validation
data.