Unit 6
Unit 6
with Python
Machine Learning
Boot camp
Presented by
R Sreenivas
M Tech
RGUKT RK Valley
Agenda
01 Introduction to ML
02 Types of Learning
03 Steps to build ML
AI
Artificial Intelligence
Natural
Computer Language
Vision & Processing & Machine
Deep Speech Learning &
Robotics Sensors Data Science
Learning Technology
Supervised
Learning
Supervised Learning
Classification Regression
A classification problem is when A regression problem is when the
the output variable is a categorical output variable is a real or
Algorithms : Logistic regression, Decision tree,
continuous value.
KNN .. etc
Algorithms : Linear regression, Polynomial
regression .. etc
Unsupervised Learning
Unsupervised learning is a type of machine learning in which models are
trained using unlabeled dataset . The goal of unsupervised learning is to find
the underlying structure of dataset, group that data according to similarities
Unsupervised
Learning
Unsupervised Learning
Clustering Association
Clustering is the method of grouping Association is the learning method
the objects into clusters such that object
which is used for finding the relationship
with most similarities remains into a same
between the variables .
group and has less or no similarities with the
object of another group .
Algorithms : K-Means clustering , SVD ..etc
Reinforcement Learning
Reinforcement learning is a feed back based machine learning technique
in which an agent learns to behave in an environment by performing actions ,
on seeing the result of actions.
Reinforcement
Learning
1 Data Collection
Data Preparation 2
3 Choose a model
Training 4
5 Evaluation
Parameter tuning 6
7 Prediction
Data Collection
Data collection means pooling data by scraping, capturing, and
loading it from multiple sources, including offline and online
sources.
Models
Logistic Regression
Decision Tree
KNN
Support Vector Machine
Linear Regression
Choose a
K – Means ...etc Model
Training
The process of training an ML model involves providing training data
to ML algorithm (that is, the learning algorithm) , then model learn
from it.
Sepal Length Cm Sepal Width Cm Petal Length Cm Petal Width Cm
Training
Evaluation
Model Evaluation is the process through which we quantify the
quality of a system’s predictions. It means that check the model
accuracy.
Evaluation
Parameter tuning
After evaluating your model, we should test the originally set
parameters to improve the AI. Increasing the number of training
cycles can lead to more accurate results.
Parameter
tuning
Prediction
Once we have gone through the process of collecting data,
preparing the data, selecting the model, training and evaluating the
model and tuning the parameters , our model is ready to predict real
time data.
Prediction
NumPY Pandas Scikit-learn Matplotlib
ML ML ML ML
ML ML ML
TensorFlow Keras
ML ML
NumPY
ML
NumPy stands for Numerical Python
NumPy is a popular Python library for multi-dimensional
array and matrix processing because it can be used to ML
perform a great variety of mathematical operations.
Its capability to handle linear algebra, Fourier transform, and
ML
more, makes NumPy ideal for machine learning and artificial
intelligence (AI)
Pandas
ML
Pandas is the Python data manipulation and analysis library.
Pandas is responsible for preparing data sets and points for
machine training. ML
Pandas uses two types of data structures, one-dimensional
(series) and two-dimensional (DataFrame), which, together,
ML
allow Pandas to be used in a variety of sectors, from science
and statistics to finance and engineering.
Scikit-learn
ML
Scikit-learn is a very popular machine learning library that is
built on NumPy and SciPy.
It supports most of the classic supervised and unsupervised ML
learning algorithms, and it can also be used for data mining,
modeling, and analysis.
ML
Scikit-learn offers a user-friendly library for those new to
machine learning.
Matplotlib
ML
Matplotlib is a Python library focused on data visualization
and primarily used for creating beautiful graphs, plots,
histograms, and bar charts. ML
t is compatible for plotting data from SciPy, NumPy, and
Pandas.
ML
Matplotlib is intuitive and easy to use, making it a great
choice for beginners.
Scipy
ML
SciPy is a free and open-source library that’s used to perform
scientific and technical computing on large sets of data.
SciPy comes with embedded modules for array optimization ML
and linear algebra.
SciPy is ideal for image manipulation and provides basic
ML
processing features of non-scientific high-level mathematical
functions.
Seaborn
ML
Seaborn is an open-source data visualization and plotting
Python library. It’s based on the plotting library Matplotlib
and includes the extensive data structures of Pandas ML
Seaborn produces the most visually appealing and attractive
graphs and plots, making it perfect for use in publications and
ML
marketing.
Theano
ML
Theano is a numerical computation Python library made
specifically for machine learning.
It is able to optimize and evaluate mathematical models and ML
matrix calculations that use multi-dimensional arrays to
create ML models.
ML
TensorFlow
ML
TensorFlow is a free and open-source Python library that
specializes in differentiable programming.
TensorFlow can be used to implement reinforcement- ML
learning in ML and DL models and allows you to directly
visualize your machine learning models with its built-in tools.
ML
Keras
ML
Keras is an open-source Python library designed for
developing and evaluating neural networks within deep
learning and machine learning models. ML
Keras is flexible, portable, and user-friendly, and easily
integrated with multiple functions.
ML
Importing necessary packages
Data preparation and preprocessing
Segregation of Data (Independent and Dependents)
Splitting the dataset into train data and test data
Choosing the model
Training the model
Testing model
Evaluation of the model
Prediction
Importing necessary packages
import numpy as np ML
import pandas as pd
import matplotlib.pyplot as plt ML
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression ML
years_of_exp = [2,4,6,8,10,12,14,16,18,20] ML
salary=[600000,800000,1000000,1200000,1400000,1600000,
1800000,2000000,2200000,2400000] ML
dataset = pd.DataFrame({"Year of Experice":years_of_exp,
"Salary":salary})
print(dataset) ML
sns.pairplot(dataset)
Data preparation and preprocessing(Contd.)
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.2)
Year of Salary
Experience ML
2 600000
4 800000
6 1000000
8 1200000
10 Year of 1400000 ML
Salary
12 Experience 1600000
18 1800000 2200000
14
20 2000000 2400000
16
model = LinearRegression()
ML
Linear
Regression
ML
Training the model
ML
model.fit(X_train,Y_train)
Year of
Experience
Salary ML
2 600000
4 800000
6 1000000 Linear
8 1200000 Regression
10 1400000 ML
12 1600000
14 1800000
16 2000000
X_train Y_train
Testing the model
predictions = model.predict(X_test) ML
print(predictions)
ML
Year of Salary
Experience Linear 2200000
18
20
Regression 2400000
ML
X_test Predictions
Evaluation of the model
print(metrics.mean_squared_error(Y_test,predictions))
print(metrics.mean_absolute_error(Y_test,predictions))
ML
print(np.sqrt(metrics.mean_squared_error(Y_test,predictions)))
Salary Salary
2200000 2200000 ML
2400000 2400000
Y_test Predictions
Predictions
experience = np.array([[int(input("Enter your years of experince :"))]]) ML
salary = model.predict(experience.reshape((-1,1)))
print(salary)
ML
Year of Salary
experience Linear 10400000
100 Regression
ML
new data
Predictive
model
Model Development
ML
Regression line ML
Data point
Types of Linear Regression
ML
Simple Linear Regression Multiple Linear Regression
∑Y = N a + b1 ∑X1 + b2 ∑X2
Attended Marks (Y)
ML
∑YX1 = a ∑X1 + b1 ∑X1^2 + b2 ∑X1X2 class (X)
3 8
∑YX2 = a ∑X2 + b1 ∑X1X2 + b2 ∑X2^2 4 9
a = 2.52 3 7
5 10 ML
b1 = 0.833 , b2 = 0.667
y = a + b1x1 + b2x2 2 6
y = 2.52 + 0.833 x1 + 0.667 x2
Multiple Linear Regression
Evaluation of model ML
1) Mean Squared Error ( MSE ) = 1/N * ∑ ( y – ŷ )^2
2) Mean Absolute Error ( MAE ) = 1/N * ∑ | y – ŷ |
3) R - Squared Error ( RSE ) = 1 – ( ∑ ( y – ŷ )^2 / ∑ ( y – y )^2 )
Attended Marks ML
class (X) (Y)
ŷ Y–ŷ ( y – ŷ )^2 |y–ŷ| ( y – y )^2
3 8
4 9
3 7 ML
5 10
2 6
∑Y ∑( y – ŷ )^2 ∑| y – ŷ | ∑ ( y – y )^2