0% found this document useful (0 votes)
3 views16 pages

Machine Learning

Machine learning is a subset of Artificial Intelligence that enables computers to learn from data through various types, including supervised, unsupervised, and reinforcement learning. Supervised learning uses labeled data for prediction, while deep learning employs neural networks to identify patterns in large datasets. Key algorithms in supervised learning include linear regression, decision trees, and support vector machines, each serving different applications in data analysis.

Uploaded by

bogala4307
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Machine Learning

Machine learning is a subset of Artificial Intelligence that enables computers to learn from data through various types, including supervised, unsupervised, and reinforcement learning. Supervised learning uses labeled data for prediction, while deep learning employs neural networks to identify patterns in large datasets. Key algorithms in supervised learning include linear regression, decision trees, and support vector machines, each serving different applications in data analysis.

Uploaded by

bogala4307
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Machine Learning

Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let
computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the
systems to think and understand like humans by learning from the data.

Machine Learning is mainly divided into three core types: Supervised, Unsupervised and Reinforcement Learning
along with two additional types, Semi-Supervised and Self-Supervised Learning.

i. Supervised Learning: Trains models on labeled data to predict or classify new, unseen data.
ii. Unsupervised Learning: Finds patterns or groups in unlabeled data, like clustering or dimensionality
reduction.
iii. Reinforcement Learning: Learns through trial and error to maximize rewards, ideal for decision-
making tasks.
Note: The following are not part of the original three core types of ML, but they have become increasingly
important in real-world applications, especially in deep learning.
Additional Types:

I. Self-Supervised Learning: Self-supervised learning is often considered as a subset of unsupervised


learning, but it has grown into its own field due to its success in training large-scale models. It
generates its own labels from the data, without any manual labeling.

II. Semi-Supervised Learning: This approach combines a small amount of labeled data with a large
amount of unlabeled data. It’s useful when labeling data is expensive or time-consuming.

Supervised Machine Learning


Supervised learning is a type of machine learning where a model learns from
labelled data—meaning every input has a corresponding correct output. The
model makes predictions and compares them with the true outputs, adjusting
itself to reduce errors and improve accuracy over time. The goal is to make
accurate predictions on new, unseen data.
Types of Supervised Learning in Machine Learning
 Classification: Where the output is a categorical variable (e.g., spam vs.
non-spam emails, yes vs. no).

 Regression: Where the output is a continuous variable (e.g., predicting


house prices, stock prices).

Supervised Machine Learning Algorithms


Supervised learning can be further divided into several different types, each with
its own unique characteristics and applications. Here are some of the most
common types of supervised learning algorithms:

1. Linear Regression: Linear regression is a type of supervised learning regression


algorithm that is used to predict a continuous output value. It is one of the simplest
and most widely used algorithms in supervised learning.

2. Logistic Regression: Logistic regression is a type of supervised learning classification


algorithm that is used to predict a binary output variable.
3. Decision Trees : Decision tree is a tree-like structure that is used to model decisions
and their possible consequences. Each internal node in the tree represents a decision,
while each leaf node represents a possible outcome.

4. Random Forests: Random forests again are made up of multiple decision trees that
work together to make predictions. Each tree in the forest is trained on a different
subset of the input features and data. The final prediction is made by aggregating the
predictions of all the trees in the forest.

5. Support Vector Machine(SVM): The SVM algorithm creates a hyperplane to


segregate n-dimensional space into classes and identify the correct category of new
data points. The extreme cases that help create the hyperplane are called support
vectors, hence the name Support Vector Machine.

6. K-Nearest Neighbors: KNN works by finding k training examples closest to a given


input and then predicts the class or value based on the majority class or average value
of these neighbors. The performance of KNN can be influenced by the choice of k and
the distance metric used to measure proximity.

7. Gradient Boosting: Gradient Boosting combines weak learners, like decision trees, to
create a strong model. It iteratively builds new models that correct errors made by
previous ones.

8. Naive Bayes Algorithm: The Naive Bayes algorithm is a supervised machine learning
algorithm based on applying Bayes' Theorem with the “naive” assumption that
features are independent of each other given the class label.

Linear Regression
Linear regression is a type of supervised machine-learning algorithm that learns from the
labelled datasets and maps the data points with most optimized linear functions which can
be used for prediction on new datasets. It assumes that there is a linear relationship
between the input and output, meaning the output changes at a constant rate as the input
changes. This relationship is represented by a straight line.
For example we want to predict a student's exam score based on how many hours they
studied. We observe that as students study more hours, their scores go up. In the example of
predicting exam scores based on hours studied. Here

 Independent variable (input): Hours studied because it's the factor we control or
observe.

 Dependent variable (output): Exam score because it depends on hobw many


hours were studied.

Best Fit Line in Linear Regression


In linear regression, the best-fit line is the straight line that most accurately represents the
relationship between the independent variable (input) and the dependent variable (output).
It is the line that minimizes the difference between the actual data points and the predicted
values from the model.

1. Goal of the Best-Fit Line


The goal of linear regression is to find a straight line that minimizes the error (the
difference) between the observed data points and the predicted values. This line helps
us predict the dependent variable for new, unseen data.
Here Y is called a dependent or target variable and X is called an independent variable
also known as the predictor of Y. There are many types of functions or modules that can
be used for regression. A linear function is the simplest type of function. Here, X may be
a single feature or multiple features representing the problem.
2. Equation of the Best-Fit Line.

For simple linear regression (with one independent variable), the best-fit line is
represented by the equation
y=mx+b
Where:
 y is the predicted value (dependent variable)
 x is the input (independent variable)
 m is the slope of the line (how much y changes when x changes)
 b is the intercept (the value of y when x = 0)
The best-fit line will be the one that optimizes the values of m (slope) and b (intercept)
so that the predicted y values are as close as possible to the actual data points.
3. Minimizing the Error: The Least Squares Method

4. Interpretation of the Best-Fit Line


 Slope (m): The slope of the best-fit line indicates how much the dependent
variable (y) changes with each unit change in the independent variable (x). For
example if the slope is 5, it means that for every 1-unit increase in x, the value
of y increases by 5 units.

 Intercept (b): The intercept represents the predicted value of y when x = 0. It’s
the point where the line crosses the y-axis.

In linear regression some hypothesis are made to ensure reliability of the model's
results.

Limitations

 Assumes Linearity: The method assumes the relationship between the


variables is linear. If the relationship is non-linear, linear regression might not
work well.

 Sensitivity to Outliers: Outliers can significantly affect the slope and


intercept, skewing the best-fit line.

Machine Learning Pipeline


[Link]
Implementation of Linear Regression

# Import the necessary libraries


import numpy as np
import [Link] as plt
from sklearn.linear_model import LinearRegression
#Generating Random Dataset
[Link](42)
X = [Link](50, 1) * 100
Y = 3.5 * X + [Link](50, 1) * 20
#Creating and Training Linear Regression Model
model = LinearRegression()
[Link](X, Y)
#Predicting Y Values
Y_pred = [Link](X)
#Visualizing the Regression Line

[Link](figsize=(8,6))
[Link](X, Y, color='blue', label='Data Points')
[Link](X, Y_pred, color='red', linewidth=2, label='Regression Line')
[Link]('Linear Regression on Random Dataset')
[Link]('X')
[Link]('Y')
[Link]()
[Link](True)
[Link]()

#Slope and Intercept


print("Slope (Coefficient):", model.coef_[0][0])
print("Intercept:", model.intercept_[0])
Output:
Slope (Coefficient): 3.4553132007706204
Intercept: 1.9337854893777546
--------------------------------------------------------------------------------------------------------------------------

Classification
[Link]

[Link]

Deep Learning
Deep Learning is a subset of Artificial Intelligence (AI) that helps machines to learn from large datasets
using multi-layered neural networks. It automatically finds patterns and makes predictions and eliminates
the need for manual feature extraction. Deep Learning tutorial covers the basics to advanced topics making
it perfect for beginners and those with experience.
Neural Networks
Neural Networks are fundamentals of deep learning inspired by human brain. It consists of layers of
interconnected nodes or "neurons" each designed to perform specific calculations. These nodes receive input
data, process it through various mathematical functions and pass the output to subsequent layers.
Neural networks are machine learning models that mimic the complex functions of the human brain. These
models consist of interconnected nodes or neurons that process data, learn patterns and enable tasks such as
pattern recognition and decision-making.
Neural networks are capable of learning and identifying patterns directly from data without pre-defined
rules. These networks are built from several key components:
 Neurons: The basic units that receive inputs, each neuron is governed by a threshold and an
activation function.
 Connections: Links between neurons that carry information, regulated by weights and biases.
 Weights and Biases: These parameters determine the strength and influence of connections.
 Propagation Functions: Mechanisms that help process and transfer data across layers of
neurons.
 Learning Rule: The method that adjusts weights and biases over time to improve accuracy.
Learning in neural networks follows a structured, three-stage process:
1. Input Computation: Data is fed into the network.
2. Output Generation: Based on the current parameters, the network generates an output.
3. Iterative Refinement: The network refines its output by adjusting weights and biases, gradually
improving its performance on diverse tasks.
In an adaptive learning environment:
 The neural network is exposed to a simulated scenario or dataset.
 Parameters such as weights and biases are updated in response to new data or conditions.
 With each adjustment, the network’s response evolves allowing it to adapt effectively to
different tasks or environments.

Importance of Neural Networks


 Identify Complex Patterns: Recognize intricate structures and relationships in data; adapt to
dynamic and changing environments.
 Learn from Data: Handle vast datasets efficiently; improve performance with experience and
retraining.
 Drive Key Technologies: Power natural language processing (NLP); enable self-driving vehicles;
support automated decision-making systems.
 Boost Efficiency: Streamline workflows and processes; enhance productivity across industries.
 Backbone of AI: Serve as the core driver of artificial intelligence progress; continue shaping the
future of technology and innovation.

Layers in Neural Network Architecture


1. Input Layer: This is where the network receives its input data. Each input neuron in the layer
corresponds to a feature in the input data.
2. Hidden Layers: These layers perform most of the computational heavy lifting. A neural network
can have one or multiple hidden layers. Each layer consists of units (neurons) that transform
the inputs into something that the output layer can use.
3. Output Layer: The final layer produces the output of the model. The format of these outputs
varies depending on the specific task like classification, regression.
Layers in Artificial Neural Networks (ANN)
In Artificial Neural Networks (ANNs), data flows from the input layer to the output layer through one or
more hidden layers. Each layer consists of neurons that receive input, process it, and pass the output to the
next layer. The layers work together to extract features, transform data, and make predictions.

An Artificial Neural Networks (ANNs) consists of three primary types of layers:

 Input Layer
 Hidden Layers
 Output Layer
Each layer is composed of nodes (neurons) that are interconnected. The layers work together to process data
through a series of transformations.
Basic Layers in ANN
1. Input Layer
Input layer is the first layer in an ANN and is responsible for receiving the raw input data. This layer's
neurons correspond to the features in the input data. For example, in image processing, each neuron might
represent a pixel value. The input layer doesn't perform any computations but passes the data to the next
layer.
Key Points:
 Role: Receives raw data.
 Function: Passes data to the hidden layers.
 Example: For an image, the input layer would have neurons for each pixel value.
2. Hidden Layers
Hidden Layers are the intermediate layers between the input and output layers. They perform most of
the computations required by the network. Hidden layers can vary in number and size, depending on
the complexity of the task.
Each hidden layer applies a set of weights and biases to the input data, followed by an activation
function to introduce non-linearity.

3. Output Layer
Output Layer is the final layer in an ANN. It produces the output predictions. The number of neurons
in this layer corresponds to the number of classes in a classification problem or the number of outputs
in a regression problem.
The activation function used in the output layer depends on the type of problem:
 Softmax for multi-class classification
 Sigmoid for binary classification
 Linear for regression

You might also like