0% found this document useful (0 votes)
2 views

Machine Learning Notes

Uploaded by

preethippalankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Machine Learning Notes

Uploaded by

preethippalankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Machine Learning

Definition:
A computer program is said to learn from experience E with respect to some class of tasks T and
performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.
The study of Machine Learning focuses on designing and analyzing algorithms that improve their
performance at a given task with experience or data.
Importance of Machine Learning :
• Automation and Adaptability in Machine Learning
ML enables automation by performing tasks without human intervention and adaptability by learning
from new data and adjusting to changes. This makes ML systems efficient, self-improving, and
essential in fields like finance, healthcare, and automation.
• Pattern Recognition in Machine Learning
Pattern recognition enables ML systems to identify trends, structures, and regularities in data to make
predictions and decisions. It is widely used in image recognition, finance, natural language processing,
fraud detection, and medical diagnosis.
• Handling Complex Problems with ML
ML solves complex, data-heavy problems by recognizing patterns and making adaptive decisions. It
excels in medical diagnosis, self-driving cars, and financial forecasting, where traditional methods fall
short.
• Scientific Discovery
ML accelerates scientific discovery by analyzing vast data, identifying patterns, and automating
research. It aids in drug discovery, astronomy, genetics, and climate science, making breakthroughs
faster and more efficient.
• Economic and Industrial Impact
ML drives economic growth and industrial innovation by optimizing processes, reducing costs, and
increasing efficiency. It powers automation, predictive maintenance, supply chain optimization, and
personalized marketing, transforming industries like manufacturing, finance, and healthcare.
• Data-Driven Decision Making
ML enhances decision-making by analyzing vast data, identifying patterns, and providing actionable
insights. It improves business strategy, healthcare diagnostics, financial forecasting, and risk
management, enabling smarter, evidence-based choices.
• Uncertainty Handling in Machine Learning
ML manages uncertainty by using probabilistic models, fuzzy logic, and Bayesian networks to make
reliable predictions despite incomplete or noisy data. This is crucial in risk assessment, medical
diagnosis, and financial forecasting, ensuring robust decision-making.
• Interdisciplinary Applications of Machine Learning
ML integrates with various fields like healthcare, finance, physics, and social sciences, solving complex
problems through data analysis, automation, and predictive modeling.
• Foundation for Artificial Intelligence
ML is the core of AI, enabling systems to learn, adapt, and make decisions without explicit
programming. It powers computer vision, natural language processing, robotics, and autonomous
systems, making AI more intelligent and capable.

Relation of Machine Learning to Other Fields


Machine Learning is an interdisciplinary field that integrates concepts from various domains to
develop algorithms for learning from data. According to Machine Learning by Tom Mitchell, ML is
influenced by the following fields:
• Artificial Intelligence → Learning symbolic representations, improving problem-solving.
• Data Mining → Extracting hidden patterns from large datasets.
• Control Theory → Optimizing and predicting system behavior.
• Decision Theory → Making optimal choices under uncertainty.
• Cognitive Science → Understanding human learning and intelligence.
• Psychological Models → Simulating human decision-making and reasoning.
• Neuroscience → Inspiration from brain structures for neural networks.
• Evolutionary Models → Using genetic algorithms to evolve solutions.
• Databases → Efficient data storage and retrieval for large-scale learning.
• Information Theory → Measuring entropy, compression, and optimal learning.
• Statistics → Providing probabilistic foundations for learning algorithms

Machine learning frameworks:


Machine learning frameworks provide tools, libraries, and interfaces to build, train, and deploy ML
models efficiently.
• TensorFlow
• PyTorch
• Keras
• Hugging Face
• Scikit-Learn

Tensorflow:
TensorFlow is an open-source machine learning framework developed by Google Brain. It is widely
used for deep learning, artificial intelligence, and large-scale ML applications. TensorFlow enables
developers to build, train, and deploy models across various platforms, including cloud, mobile, and
edge devices.

2. Key Features
• Scalability → Supports multi-GPU, TPU, and distributed computing for large-scale training
• Flexible Architecture → Works for deep learning, reinforcement learning, and traditional ML.
• Keras Integration → Provides an easy-to-use high-level API for rapid model development.
3. Drawbacks:
• Debugging Challenges → Static computation graph makes debugging harder than PyTorch.
• Performance Overhead → Heavier memory usage compared to some lightweight frameworks.

PyTorch: Definition, Features, and Drawbacks


Definition:
PyTorch is an open-source deep learning framework developed by Meta (Facebook). It is widely
used for research and production, offering a dynamic computation graph and intuitive API for
building and training neural networks.
Key Features:
• Dynamic Computation Graphs → Allows flexible model building and debugging.
• Easy-to-Use API → Pythonic and beginner-friendly compared to TensorFlow.
Drawbacks
• Less Deployment Flexibility → Weaker mobile and cloud support compared to TensorFlow.
• Limited TensorBoard Integration → Requires additional setup for visualization.
• Less Optimized for Production → TensorFlow is preferred for large-scale industry applications.

Types of Machine Learning :


Supervised Learning:
The model learns from labeled data, where each input has a known correct output.
Example:
• Spam Detection → Classifies emails as spam or not spam.
• Disease Diagnosis → Predicts diseases based on patient data.
Types:
Classification:
Regression:
Algorithms: Decision Trees, Neural Networks, SVM

Unsupervised Learning:
The model finds patterns in unlabeled data without predefined outputs.
Example:
Customer Segmentation → Groups customers based on purchasing behavior.
Anomaly Detection → Detects fraud in financial transactions.
Types:
Clustering: Groups similar data points (e.g., customer segmentation).
Dimensionality Reduction: Reduces data complexity while preserving important features (e.g., PCA for
image compression).
Algorithms: K-Means Clustering, PCA
Reinforcement Learning:
The model interacts with an environment, receiving rewards or penalties to learn optimal actions.
Example:
Game AI: AlphaGo and Chess-playing AI.
Robotics: Learning navigation in complex environments.
Types:
Model-Free RL: Learns directly from experience (e.g., Q-learning).
Model-Based RL: Builds a model of the environment before making decisions (e.g., Dynamic
Programming).
Algorithms: Q-Learning, Deep Q Networks (DQN)

Examples of Machine Learning Applications:


• Speech Recognition → The SPHINX system learns speaker-specific strategies to recognize spoken
words.
• Autonomous Vehicles → The ALVINN system drove unassisted at 70 mph for 90 miles on public
highways.
• Astronomical Object Classification → NASA used decision trees to classify celestial objects from
the Palomar Observatory Sky Survey.
• Game AI → TD-GAMMON trained by playing over 1 million backgammon games and reached
world-class performance.
• Fraud Detection → ML algorithms detect fraudulent credit card transactions by analyzing spending
patterns.
• Medical Diagnosis → ML predicts pneumonia recovery rates from patient medical records.
• Handwriting Recognition → Used in postal mail sorting and bank check processing.
• Data Mining → ML helps extract valuable knowledge from large financial, medical, and business
databases.
• Personalized Assistants → AI-powered assistants adapt to user preferences for better
recommendations.
• Industrial Process Control → ML optimizes manufacturing processes by adjusting to supply chain
variations.

Designing a Learning System


A learning system is designed to improve its performance by learning from data. The process involves
multiple steps, including selecting training data, defining the target function, choosing a
representation, selecting a learning algorithm, and evaluating the model.
1. Choosing the Training Experience
The type of training data determines how well the system generalizes. The system can learn from:
• Direct Training Examples : Board states labeled with the best possible move.
• Indirect Training Examples : Entire game sequences labeled as wins or losses.
• Self-Play : The program plays against itself to generate training data.
Challenge: The credit assignment problem—determining which moves contributed to winning or
losing a game.

2. Choosing the Target Function


The system must define what it is learning. Instead of memorizing moves, it learns a target function to
evaluate board positions.
Example:
• Instead of storing all possible board positions, the system learns a function V(board) that assigns
a score to each board position.
• Higher scores indicate better positions for winning.
Mathematical Representation:
V(s)=w0+w1f1(s)+w2f2(s)+...+wnfn(s)
where fi(s) represents board features (e.g., number of kings, number of pieces).

3. Choosing the Representation of the Target Function


The target function can be represented in multiple ways:
• Linear Combination of Features → Assigns weights to board features.
• Decision Trees → Uses a tree structure to evaluate moves.
• Neural Networks → More complex, but can capture non-linear relationships.
Example Features:
f1(s) = Number of kings on the board.
f2(s) = Number of opponent’s pieces.
f3(s) = Number of safe moves available.

4. Choosing the Learning Algorithm


The learning algorithm updates the model parameters based on training data.
Example Algorithms:
Least Mean Squares (LMS) Algorithm → Adjusts function weights to minimize prediction error.
Gradient Descent → Iteratively updates weights to reduce loss.
Reinforcement Learning → Updates weights based on game rewards.
Mathematical Update Rule for LMS:
wi=wi+η×(Vtarget−V(s))×fi(s)
where η is the learning rate
5. Evaluating and Refining the Model
After training, the model must be evaluated to measure its effectiveness.
• Testing Against Human Players → Check if the program improves over time.
• Self-Play → The program competes with itself to refine strategies.
• Exploration vs. Exploitation → Balancing trying new moves vs. using known best moves.
Example Evaluation Metrics:
Win percentage against opponents.
Average game length (faster wins indicate better strategies).
6. Final Design of the Learning System

The checkers-playing program consists of four modules:


Performance System : Plays the game using the learned evaluation function.
Critic : Evaluates moves and provides feedback.
Generalizer :Updates the model based on past games.
Experiment Generator : Creates new board positions to improve learning.

Issues in Machine Learning


Machine learning (ML) has made significant progress in various fields, but several challenges limit its
effectiveness. These issues arise due to limitations in data, computational power, algorithm efficiency,
and ethical concerns.
1. Algorithm Selection and Convergence
• Choosing the right learning algorithm and ensuring it converges to the best solution.
• Different algorithms perform better for different tasks.
• Some ML models get stuck in local minima, failing to find the best solution.
• Hyperparameter tuning requires expertise and experimentation.
• Example: A neural network trained for image recognition may not converge properly without
optimal learning rates.
2. Data Requirements and Quality
• ML models require large and high-quality datasets for accurate predictions.
• Insufficient or biased data leads to inaccurate models.
• Handling missing, noisy, or inconsistent data is complex.
• Example: In medical AI, if a model is trained mostly on male patient data, it may perform poorly
on female patients.
3. Generalization to Unseen Data
• Ensuring models perform well on new, unseen data, not just training data.
• Overfitting → The model memorizes the training data but fails on new data.
• Underfitting → The model is too simple to capture key patterns.
• Example: A spam detection system trained only on old email patterns may fail to detect new
types of spam.
4. Computational Complexity
• Some ML models require high computational power and storage.
• Training deep learning models takes days or weeks on large datasets.
• Running ML models on low-power devices is difficult.
• Example: Self-driving car AI needs powerful GPUs to process real-time sensor data efficiently.
5. Interpretability and Explainability
• Many ML models, especially deep learning, act as black boxes (hard to interpret).
• Users and regulators need transparency in AI decision-making.
• In critical areas (healthcare, finance), explainability is required for trust.
• Example: If an AI system denies a loan, users should understand why it made that decision.
6. Handling Uncertainty in Learning
• ML models often deal with uncertain, incomplete, or noisy data.
• Probabilistic approaches like Bayesian Learning help but require more computation.
• AI systems must adapt to unexpected situations (e.g., medical anomalies).
• Example: In autonomous driving, ML must handle unpredictable road conditions like fog or
sudden obstacles.
7. Ethical and Bias Concerns
• ML models can inherit biases from training data.
• Bias in hiring, criminal justice, and loan approvals leads to unfair decisions.
• Ensuring fair AI models while maintaining accuracy is difficult.
• Example: A facial recognition model trained mostly on light-skinned faces may perform poorly
on darker skin tones.
8. Data Privacy and Security Risks
• ML models require large amounts of personal data, raising privacy concerns.
• Risk of data breaches and misuse.
• Secure ML techniques like federated learning aim to reduce privacy risks.
• Example: AI-powered health monitoring apps collect sensitive user data, requiring strong
security.
9. Scalability Issues
• As data grows, ML models must scale efficiently.
• Training models on big data requires distributed computing.
• Updating models with new data without retraining from scratch is a challenge.
• Example: Google Search AI constantly updates its ranking algorithms based on billions of web
pages.
10. Security Threats in Machine Learning
• ML models are vulnerable to adversarial attacks.
• Attackers can manipulate AI by modifying input data (e.g., tricking a model into misclassifying an
object).
• Model poisoning occurs when attackers inject bad data into training sets.
• Example: Hackers can fool self-driving cars by placing altered road signs that mislead the AI.

Steps to solve Machine Learning Problem

1. Define the Learning Problem


• Clearly specify what the system should learn.
• Identify the input (features) and output (target variable).
• Decide whether it is a classification, regression, clustering, or reinforcement learning problem.
2. Gather and Preprocess Data
• Collect a dataset relevant to the problem.
• Clean the data (handle missing values, remove duplicates, normalize/standardize).
• Split the data into training, validation, and test sets.
3. Choose the Model Representation
• Select an appropriate learning algorithm (e.g., Decision Trees, Neural Networks, SVM, etc.).
• Define the hypothesis space (set of all possible models the algorithm can choose from).
4. Select a Training Algorithm
• Choose an optimization technique (e.g., gradient descent, genetic algorithms).
• Define the cost function (e.g., Mean Squared Error for regression, Cross-Entropy for
classification).
• Tune hyperparameters (e.g., learning rate, number of layers in neural networks).
5. Train the Model
• Feed training data into the algorithm.
• Optimize the model parameters by minimizing the error.
• Validate the model using cross-validation techniques.
6. Evaluate the Model
• Test the model on unseen data (test set).
• Use evaluation metrics like accuracy, precision, recall, F1-score (for classification), or RMSE (for
regression).
• Check for overfitting or underfitting.
7. Refine and Improve the Model
• If the model underperforms, fine-tune hyperparameters, get more data, or try a different
algorithm.
• Use techniques like regularization, dropout (for neural networks), or feature selection to
improve performance.
8. Deploy and Monitor the Model
• Integrate the trained model into a production system.
• Continuously monitor its performance in real-world scenarios.
• Retrain the model periodically with new data to maintain accuracy.

Machine Learning Workflow:

1. Data Collection (Input)


• The process starts with COVID-19 data, which includes patient details, symptoms,

test results, and other relevant features.


2. Data Preprocessing
• The raw data undergoes several preprocessing steps to make it suitable for machine

learning:
o Data Formatting: Standardizing the structure of data.

o Data Cleaning: Removing missing, inconsistent, or incorrect values.

o Data Transformation: Converting data into a suitable format (e.g., scaling,

encoding categorical values).


o Data Reduction: Reducing the dimensionality by selecting important features.

o Data Sampling: Selecting a subset of data for faster processing.

3. Splitting the Data


• The preprocessed data (called Enriched Data) is split into:

o Training Dataset (used to train the model).

o Testing Dataset (used to test the model after training).

4. Machine Learning Training


• The ML Classification Training step involves feeding the training dataset into a
machine learning algorithm to develop a predictive model.
5. Hyperparameter Tuning
• Model performance is optimized by adjusting hyperparameters (e.g., learning rate,

number of layers, etc.).


6. Model Evaluation
• The trained model (Candidate Model) is evaluated using validation data to measure

its accuracy, precision, recall, and other metrics.


7. Model Predictions
• After evaluation, the final model is used to make predictions on new (unseen) data.

8. Predicted Diagnosis (Output)


• The final output is a Predicted Diagnosis, which determines whether a patient is

likely to have COVID-19 based on the input data.


Key Takeaways
• The process follows a structured machine learning pipeline with data preprocessing,

model training, evaluation, and predictions.


• Hyperparameter tuning is done to improve model performance.

• The system helps in automated COVID-19 diagnosis using machine learning.

Decision Tree
A Decision Tree is a popular machine learning algorithm used for both classification and
regression tasks. It is structured like a tree, where each node represents a decision based
on a feature, and the final outcomes (leaf nodes) represent predictions.
1. Decision Tree Basics
A decision tree consists of:
• Nodes: Represent decisions or outcomes.

• Edges (Arrows): Show possible paths from one decision to another.

• Root Node: The first node that represents the starting decision.

• Intermediate (Internal) Nodes: Nodes where decisions are made.

• Leaf Nodes: Final nodes that represent the output (class label or numerical value).

Example:
Root Node
/ \
Decision 1 Decision 2
/ \ / \
Leaf1 Leaf2 Leaf3 Leaf4
Each path from the root to a leaf represents a classification rule.

2. Types of Decision Trees


Decision trees can be categorized based on the type of target variable:
1. Classification Tree (Categorical output)
o Used when the output variable is discrete (e.g., Yes/No, Fit/Unfit).

o Example: Determining whether a patient has a disease (Yes/No).

2. Regression Tree (Continuous output)


o Used when the output variable is continuous (e.g., price, age).

o Example: Predicting house prices based on features like area and number of

rooms.

3. Entropy & Information Gain


Entropy (H)
Entropy measures the uncertainty or randomness in a dataset. If a dataset has only one
class (e.g., all positive or all negative), entropy is 0 (pure dataset). If the dataset is evenly
split between two classes, entropy is high (maximum uncertainty).
Formula:

Where:
• S = dataset

• pi = probability of each class in the dataset

Example:
If we have 10 samples:
• 6 are Yes (Positive)

• 4 are No (Negative)

Entropy is:

Entropy increases as the data becomes more mixed and decreases when it is more
uniform.

Information Gain (IG)


Information gain measures how much entropy decreases after splitting on an attribute. A
higher IG means that splitting on that attribute makes the dataset more organized and
reduces uncertainty.
Formula:

Where:
• IG(S,A) = Information gain when splitting on attribute A

• H(S) = Entropy before splitting

• H(Sv) = Entropy of subset after splitting

• ∣Sv∣/∣S∣ = Proportion of samples in subset

Example:
Let's say we split data based on "Weather" (Sunny, Rainy, Overcast). If splitting reduces
entropy from 0.971 to 0.4, then:
IG=0.971−0.4=0.571
Since information gain is high, "Weather" is a good feature to split on.

ID3 Algorithm (Iterative Dichotomiser 3)


ID3 is a greedy, top-down approach used to build decision trees. It selects the best
feature at each step based on Information Gain.
Steps of ID3 Algorithm
1. Calculate entropy of the current dataset.
2. For each attribute, calculate the entropy and Information Gain.
3. Select the attribute with the highest IG to split the dataset.
4. Create a decision node for that attribute.
5. Repeat the process for each subset until:
o All samples in a subset belong to one class (pure node).

o There are no more attributes to split.

o The tree has reached a specified depth.

You might also like