Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

A

Industrial Training Report


On
ARTIFICIAL
INTELLIGENCE AND
MACHINE LEARNING
USING PYTHON
Submitted in partial fulfilment
for the award of the Degree Of

Bachelor of Technology
In Computer Engineering

Submitted To: Submitted By:


…………….. VISHAL KUMAR
HOD CSE
V Sem CSE
21EAYCS145

Department of Computer Science & Engineering


Arya Institute of Engineering & Technology, Jaipur
Rajasthan Technical University, Kota (2023-24)
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
SP-40, RIICO Industrial Area, Jaipur (Raj)-302028

Department of Computer Science & Engineering

Certificate

This is to certify that the work, which is being presented in the

Practical training seminar report for practical training taken at


“UPFLAIRS, JAIPUR” entitled

“ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING”


submitted by Mr. / Ms. VISHAL KUMAR , a student of third
year (V Sem) B.Tech. in Computer Engineering as a partial fulfilment
for the award of degree of bachelor of technology is a record of
student’s work carried out and found satisfactory for submission.

Mr. ………… ………………….

Training Coordinator Head Of Department

i
Training Certificate

ii
Candidate’s Declaration

I hereby declare that the work, which is being presented in the Industrial Training report, entitled
“ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING USING PYTHON” in partial fulfilment for
the award of
Degree of “Bachelor of Technology” in Department of Computer Science &
Engineering with Specialization in Computer Engineering and submitted to the

Department of Computer Science & Engineering, Arya Institute of Engineering & Technology, is a record
of my own investigations carried under the Guidance of Mr. …………., Assistant Professor, Department of
Computer Science & Engineering.

(Signature of Candidate)

Candidate Name

VISHAL KUMAR

Roll No.: 21EAYCS145

i
Abstract

Artificial Intelligence (AI) and Machine Learning (ML) have revolutionized various industries by enabling
computers to mimic human intelligence and learn from data. Python, with its rich ecosystem of libraries and
frameworks, has emerged as a dominant language for AI and ML development. This abstract provides an
overview of the key concepts and applications of AI and ML using Python.
Supervised learning, unsupervised learning, and reinforcement learning are three fundamental paradigms of
ML. Python's Scikit-Learn and TensorFlow libraries provide a plethora of algorithms for tasks such as
regression, classification, clustering, and neural network development. These libraries simplify model
creation, training, and evaluation, making it accessible for both beginners and experts
Deep Learning, a subset of ML, has gained immense popularity, primarily due to its remarkable performance
in tasks like image recognition, natural language processing, and autonomous driving. Python's TensorFlow
and PyTorch libraries have emerged as the go-to frameworks for deep learning, offering customizable neural
network architectures and pre-trained models for rapid development.

ii
Acknowledgement

On the completion of the industrial training on ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING.
I would like to thanks the Department of Computer Science & Engineering, Arya Institute Of Engineering &
Technology, Head Of Department ……… for providing us the opportunity to have such a training where we
could get the exposure of competing and performing with students from other colleges and universities.

I would also like to express my heartful gratitude to Mr. ……… under whose guidance I have been able to
complete this training successfully and gain experience and knowledge about the various topics of the subject.

I would also like to thank all the teaching assistants at Arya Institute of Engineering, Jaipur, they have be
very helpful throughout the process both in solving our doubts and motivating us to complete our tasks and
assignments and helping us learn.

I would also like to express my deepest appreciation for Mr. ……..for guiding me throughout the training and
all the people who have directly or indirectly helped me to successfully complete the training.

…………
VISHAL KUMAR
21EAYCS145

iii
Learning/Internship Objectives

• Internships are generally thought of to be reserved for college students looking to gain
experience in a particular field. However, a wide array of people can benefit from Training
Internships in order to receive real world experience and develop their skills.
• An objective for this position should emphasize the skills you already possess in the area and
your interest in learning more.
• Internships are utilized in a number of different career fields, including architecture,
engineering, healthcare, economics, advertising and many more.
• Some internships are used to allow individuals to perform scientific research while others are
specifically designed to allow people to gain first-hand experience working.
• Utilizing internships is a great way to build your resume and develop skills that can be
emphasized in your resume for future jobs. When you are applying for a Training Internship,
make sure to highlight any special skills or talents that can make you stand apart from the rest
of the applicants so that you have an improved chance of landing the position.

iv
TABLE OF CONTENTS

S. NO. TITLE PAGE NO.


Cover Page
Certificate i
Candidate’s Declaration i
Abstract ii
Acknowledgement iii
Learning/Internship Objectives iv

List of Tables vii-viii

1 Chapter 1: Introduction 1
2 Chapter 2: History 2
3 Chapter 3: Definition 3
4 Chapter 4: Architecture of IOT 4
5 Chapter 5: Applications 5

6-8
6 Chapter 6: Components Used
6.1 Arduino UNO 6
6.2 ESP8266 (Wi-Fi Module) 6-7
6.3 Breadboard & Jump Wires 7
6.4 Power Supply Board 7
6.5 2 Channel Relay 8

7 Chapter 7: Blynk app 9


8 Chapter 8: Configuring Blynk 10
9 Chapter 9: Advantages & Disadvantages 11-12

13
10 Chapter 10: Requirements
10.1. Software Requirements 13
10.2 Hardware Requirements 13
11 Chapter 11: Project Implementation 14
12 Chapter 12: Source Code 15-17
13 Chapter 13: Circuit Connections 18

v
14 Chapter 14: Output 19
15 Chapter 15: Conclusion 20
16 Chapter 16: Bibliography 21
17 References 22

vi
Chapter 1
INTRODCTION

In the realm of modern technology, Artificial Intelligence (AI) and Machine Learning (ML) have emerged as
driving forces that are reshaping the way we interact with computers, analyse data, and solve complex
problems. Python, a versatile and powerful programming language, has established itself as the go-to choose
for developers and data scientists looking to harness the capabilities of AI and ML. This introduction provides
an insight into the world of AI and ML, emphasizing Python's pivotal role in this transformative journey.
Artificial Intelligence refers to the development of computer systems that can perform tasks typically requiring
human intelligence, such as understanding natural language, recognizing patterns, and making decisions.
Machine Learning, a subset of AI, empowers computers to learn from data and improve their performance over
time without being explicitly programmed. Together, AI and ML have unlocked unprecedented opportunities
across a wide array of industries, from healthcare and finance to autonomous vehicles and entertainment.
Python's ascent as the de facto language for AI and ML is driven by its simplicity, readability, and a vast
ecosystem of libraries and frameworks specifically tailored for data analysis, machine learning, and deep
learning. Its elegant syntax and ease of use make it accessible to both beginners and experienced developers.
Python's adaptability to diverse tasks, coupled with its strong community support, has made it the top choice
for professionals and researchers worldwide.
In this exploration of AI and ML using Python, we will delve into the fundamental concepts of data-driven
decision-making, the various paradigms of machine learning, and the burgeoning field of deep learning. We
will also explore real-world applications across industries, highlighting Python's role in designing and
deploying intelligent systems. Furthermore, we will examine the importance of continuous improvement and
monitoring in AI and ML, emphasizing Python's tools and frameworks that facilitate model management and
performance evaluation. As we navigate through this dynamic landscape, we will discover how Python
empowers us to leverage AI and ML effectively, contributing to the ongoing technological revolution.

1
Chapter 2
HISTORY

Early Beginnings: The roots of Artificial Intelligence (AI) can be traced back to ancient mythology and
early philosophy, where the concept of intelligent machines and automatons was often explored. However,
AI as a formal field of study began in the mid-20th century.
The Dartmouth Workshop (1956): AI's birth is often associated with the Dartmouth Workshop, held in the
summer of 1956. It was organized by John McCarthy, Marvin Minsky, Nathaniel Rochester, and Claude
Shannon. This workshop marked the official birth of AI as an interdisciplinary field.
Symbolic AI and Early Challenges: In the 1950s and 1960s, AI researchers primarily focused on symbolic
AI, which involved representing knowledge in a structured form and using logic-based reasoning to solve
problems. Early successes included the development of expert systems like Dendral and General Problem
Solver (GPS).
The AI Winter: Despite initial enthusiasm, AI research faced challenges in the 1970s and 1980s due to
unrealistic expectations, limited computing power, and difficulties in representing knowledge. This period
became known as the "AI winter," characterized by reduced funding and interest.
Resurgence with Machine Learning: The late 20th century saw a resurgence in AI research, driven by
advances in machine learning. Machine learning, a subset of AI, focuses on developing algorithms that
enable computers to learn from data. Key breakthroughs included the development of neural networks and
the backpropagation algorithm.
Deep Learning and Neural Networks: In the 21st century, deep learning, powered by neural networks with
many layers, revolutionized AI and ML. This approach led to significant advancements in image
recognition, natural language processing, and robotics. Notable achievements include the rise of deep
learning frameworks like TensorFlow and PyTorch.
AI in Everyday Life: Today, AI and ML are integral parts of our daily lives. They power virtual assistants
like Siri and Alexa, recommendation systems on platforms like Netflix and Amazon, self-driving cars,
healthcare diagnostic tools, and more.
Ethical and Societal Concerns: As AI and ML applications proliferate, concerns about ethics, bias, privacy,
and job displacement have come to the forefront. Researchers and policymakers are actively addressing
these issues.
Future Prospects: The history of AI and ML has been marked by periods of optimism and skepticism.
However, the field continues to advance rapidly, with ongoing research into explainable AI, reinforcement
learning, and AI ethics. The future promises further integration of AI into various industries and deeper
understanding of its capabilities and limitations.

2
Chapter 3
DEFINITION

Artificial Intelligence (AI):


Artificial Intelligence, often abbreviated as AI, refers to the field of computer science and technology focused
on creating systems, software, or machines that can perform tasks typically requiring human intelligence. These
tasks include reasoning, problem-solving, understanding natural language, recognizing patterns, learning from
experience, and making decisions. AI encompasses a wide range of techniques and approaches, from rule-
based expert systems to advanced neural networks, and it aims to simulate or replicate human-like cognitive
processes in computers or machines.
Machine Learning (ML):
Machine Learning, or ML, is a subset of Artificial Intelligence that focuses on the development of algorithms
and statistical models that enable computer systems to automatically improve their performance on a specific
task through learning from data. In ML, instead of explicitly programming a computer to perform a task, the
system learns patterns and relationships from data, allowing it to make predictions or decisions based on new,
previously unseen data. ML techniques include supervised learning, unsupervised learning, reinforcement
learning, and deep learning, among others, making it a fundamental component of many AI applications.

3
Chapter 4
APPLICATIONS

When discussing applications in the context of Artificial Intelligence and Machine Learning, we're referring to
the practical uses and implementations of these technologies across various industries and domains. Here are
some notable AI and ML applications:
1. Healthcare:
• Medical Diagnosis: AI is used for diagnosing diseases, such as cancer, diabetes, and heart
conditions, by analysing medical images and patient data.
• Drug Discovery: ML models help identify potential drug candidates and predict their efficacy,
accelerating the drug development process.
• Personalized Medicine: AI assists in tailoring treatment plans and medications based on an
individual's genetic makeup and health history.
2. Finance:
• Algorithmic Trading: ML algorithms analyse financial data to make real-time trading decisions,
optimizing investment portfolios.
• Credit Scoring: AI assesses creditworthiness by analysing an applicant's financial history and
behaviour.
• Fraud Detection: ML models detect fraudulent transactions and activities by identifying unusual
patterns and anomalies.
3. Autonomous Vehicles:
• Self-Driving Cars: AI and ML enable vehicles to perceive their environment, make decisions,
and navigate without human intervention.
• Drones and UAVs: Unmanned aerial vehicles use AI for navigation, surveillance, and delivery
tasks.
4. Natural Language Processing (NLP):
• Chatbots: NLP-powered chatbots provide customer support, answer queries, and automate
interactions in various industries.
• Language Translation: AI translates text and speech across languages, enabling global
communication.
• Sentiment Analysis: NLP algorithms analyse social media and customer reviews to gauge public
sentiment about products and services.

4
Chapter 5
Python Overview
1. Command Line & Script based Python Programming:
• Running Python code interactively in the command line or by creating and executing Python script
files.
2. Python Quicker: Keywords, Data Types, Operators:
• Learning essential Python keywords, data types (e.g., numbers, strings), and operators (e.g., + for
addition).
3. Conditional/Looping/Error Handling in Python:
• Using if-else for decisions, loops (e.g., for and while) for repetition, and try-except for handling
errors.
4. Comprehensions:
• Creating compact code for lists and dictionaries using list comprehensions and dictionary
comprehensions.
5. Python User Defined Functions:
• Writing your own functions to encapsulate and reuse code for specific tasks.
6. Python Generators:
• Using generator functions to efficiently work with large datasets without loading everything into
memory at once.
7. Lambda Expressions:
• Defining small, anonymous functions (lambda functions) for concise, one-line operations.
8. Python Modules: Usage and Installation:
• Utilizing external Python modules (libraries) for added functionality and installing them using tools
like pip.
9. Understanding the OOP of Python:
• Grasping the principles of Object-Oriented Programming in Python, including classes, objects, and
inheritance.
10. GUI Development with Python:
• Creating graphical user interfaces (GUIs) for interactive desktop applications using Python libraries
like Tkinter or PyQt.

5
Chapter 6
Libraries in Python
Python has a rich ecosystem of libraries for data science, analysis, machine learning, and artificial intelligence
(AI). Here's a list of popular libraries in each of these categories:
6.1 Pandas
Pandas is a popular Python library for data manipulation and analysis. It provides data structures and functions
for working with structured data, such as spreadsheets or SQL tables, making it a fundamental tool for data
scientists and analysts. Below, I'll explain some of the key functions and concepts in Pandas:
1. Data Structures:
• Series: A one-dimensional array-like object containing data and associated labels or indexes. It is
similar to a column in a spreadsheet or a single column of a database table.
• DataFrame: A two-dimensional, tabular data structure with rows and columns. It is similar to a
spreadsheet or a SQL table. DataFrames are the most commonly used Pandas data structure.
2. Data Import and Export:
• pd.read_csv(): Reads data from a CSV file into a DataFrame.
• pd.read_excel(): Reads data from an Excel file into a DataFrame.
• df.to_csv(): Writes data from a DataFrame to a CSV file.
• df.to_excel(): Writes data from a DataFrame to an Excel file.
3. Data Explossration:
• df.head(): Returns the first n rows of a DataFrame.
• df.tail(): Returns the last n rows of a DataFrame.
• df.info(): Provides information about the DataFrame, including data types and missing values.
• df.describe(): Generates summary statistics of numeric columns.
• df.shape: Returns the dimensions (number of rows and columns) of the DataFrame.
• df.columns: Returns the column names of the DataFrame.
4. Data Selection and Indexing:
• df['column_name'] or df.column_name: Selects a single column from the DataFrame.
• df[['column1', 'column2']]: Selects multiple columns.
• df.loc[row_label]: Selects rows by label.
• df.iloc[row_index]: Selects rows by integer index.
• df.query('condition'): Filters rows based on a condition.
5. Data Manipulation and Transformation:
• df.drop(): Removes specified rows or columns from the DataFrame.
• df.rename(): Renames columns or indexes.
• df.sort_values(): Sorts the DataFrame by one or more columns.
6
• df.groupby(): Groups data based on a column or multiple columns.
• df.pivot_table(): Creates pivot tables to summarize data.
• df.apply(): Applies a function to each element or row in the DataFrame.
6. Data Cleaning:
• df.isnull(): Checks for missing values.
• df.dropna(): Removes rows or columns with missing values.
• df.fillna(): Fills missing values with specified values.
7. Data Aggregation:
• df.sum(), df.mean(), df.median(): Compute various summary statistics.
• df.max(), df.min(): Find the maximum and minimum values.
• df.count(): Counts the number of non-null elements.
8. Data Visualization Integration:
• Pandas integrates with data visualization libraries like Matplotlib and Seaborn to create plots and
charts directly from DataFrames.
9. Merging and Joining Data:
• pd.concat(): Concatenates DataFrames along rows or columns.
• pd.merge(): Performs database-style joins on DataFrames.

7
6.2 NumPy
NumPy (Numerical Python) is a fundamental library in the Python ecosystem, particularly in the context of data
analysis and machine learning (ML). It provides support for working with numerical data efficiently, making it
an essential tool for data scientists and ML practitioners. Here's how NumPy is used in data analysis and ML,
along with some key functions:
Data Representation:
• ndarray: NumPy's core data structure is the ndarray (N-dimensional array). It allows for efficient storage
and manipulation of multi-dimensional data, such as matrices and tensors. This is crucial in data analysis
and ML where datasets are often multi-dimensional.
Data Cleaning and Preprocessing:
• Handling Missing Data: NumPy provides functions like np.isnan() and np.nan_to_num() for identifying
and handling missing data, a common preprocessing step in data analysis.
• Data Transformation: NumPy allows you to reshape and transform data using functions like np.reshape(),
np.transpose(), and np.concatenate(). This is useful for preparing data for various analysis and modeling
tasks.
Data Exploration:
• Descriptive Statistics: NumPy offers functions for computing basic statistics, such as np.mean(),
np.median(), np.std(), and np.var(), which are essential for exploring and summarizing data.
Mathematical and Statistical Analysis:
• Statistical Functions: NumPy provides various statistical functions for hypothesis testing, correlation
analysis, and random sampling, such as np.corrcoef(), np.histogram(), and np.random.choice().
• Linear Algebra: NumPy offers functions for linear algebra operations, including matrix multiplication
(np.dot()), eigenvalue and eigenvector computation (np.linalg.eig()), and solving linear systems
(np.linalg.solve()). These are essential in ML, especially for algorithms like regression and dimensionality
reduction.
Machine Learning:
• Data Representation: In ML, datasets are often represented as NumPy arrays. Many ML libraries,
including Scikit-Learn, expect data in this format.
• Feature Engineering: NumPy is used to create new features and transform existing ones, a critical aspect
of feature engineering in ML.
• Performance Optimization: NumPy's efficient array operations are crucial for optimizing ML algorithms,
particularly when working with large datasets.
Random Number Generation:
• Random Sampling: NumPy's random number generation functions (np.random) are used for tasks like
creating synthetic datasets, performing simulations, and generating random samples. This is important for
techniques like bootstrapping and Monte Carlo simulations in data analysis and ML.

8
Integration with Data Visualization:
• Data Visualization: NumPy integrates seamlessly with data visualization libraries like Matplotlib and
Seaborn, enabling data scientists and ML practitioners to create visualizations based on numerical data.
Handling Missing Data:
• Missing Data: NumPy provides tools to identify and manage missing data, which is a common issue in
data analysis and ML tasks.

9
6.3 Matplotlib
Matplotlib is a powerful Python library for creating data visualizations and plots. It provides various functions
and modules that enable users to customize, create, and display a wide range of visualizations. Here are some key
functions and concepts associated with Matplotlib in the context of data analysis and visualization:
Basic Plotting Functions:
• plt.plot(): Creates line plots and can be used for visualizing trends over continuous data points.
• plt.scatter(): Generates scatter plots for visualizing relationships between two variables.
• plt.bar(), plt.barh(): Creates bar charts for displaying categorical data.
• plt.hist(): Generates histograms for visualizing the distribution of data.
• plt.boxplot(), plt.violinplot(): Used to create box plots and violin plots for displaying the distribution of
data and identifying outliers.
• plt.pie(): Generates pie charts for displaying parts of a whole.
Customization and Styling:
• plt.xlabel(), plt.ylabel(): Adds labels to the x and y-axes, respectively.
• plt.title(): Sets the title of the plot.
• plt.legend(): Adds a legend to the plot.
• plt.grid(): Displays a grid on the plot.
• plt.xlim(), plt.ylim(): Sets the limits for the x and y-axes.
• plt.xticks(), plt.yticks(): Sets the tick positions and labels for the x and y-axes.
• plt.axhline(), plt.axvline(): Adds horizontal and vertical lines to the plot.
• plt.annotate(): Adds text annotations to specific data points.
Subplots and Multiple Axes:
• plt.subplots(): Creates a grid of subplots within a single figure.
• ax = fig.add_subplot(): Adds individual subplots to a figure.
• ax.twinx(), ax.twiny(): Adds a secondary y-axis or x-axis to a subplot.
Annotations and Text:
• plt.text(): Adds text to arbitrary positions on the plot.
• plt.annotate(): Annotates specific data points with arrows and labels.

10
6.4 Seaborn
Seaborn is a Python data visualization library based on Matplotlib that provides a high-level interface for
creating informative and aesthetically pleasing statistical graphics. It is particularly well-suited for data
analysis and exploration, as it simplifies the process of creating complex visualizations with concise code.
Here's an explanation of Seaborn in the context of data analysis and visualization, along with its key functions:
Advantages of Seaborn:
1. High-Level Interface: Seaborn is designed to work seamlessly with Pandas DataFrames, making it
easier to visualize data directly from data structures commonly used in data analysis.
2. Beautiful Aesthetics: Seaborn provides attractive default styles and color palettes that enhance the
visual appeal of plots.
3. Statistical Plotting: Seaborn specializes in creating statistical plots that help users understand data
distributions, relationships, and patterns.
Basic Plotting Functions:
• sns.histplot(): Creates histograms for visualizing the distribution of data.
• sns.kdeplot(): Generates kernel density estimate (KDE) plots to visualize the distribution of data.
• sns.scatterplot(): Creates scatter plots for visualizing relationships between two variables.
• sns.boxplot(), sns.violinplot(): Used to create box plots and violin plots to show the distribution of data
and identify outliers.
• sns.barplot(), sns.countplot(): Creates bar charts for displaying categorical data.
• sns.lineplot(): Generates line plots for visualizing trends over continuous data points.
• sns.pairplot(): Creates a matrix of scatter plots for examining relationships between multiple variables
in a dataset.
Statistical Enhancements:
• sns.regplot(): Combines a scatter plot with a linear regression fit line.
• sns.lmplot(): Creates regression plots for visualizing relationships between variables.
Subplots and Multiple Axes:
• sns.FacetGrid(): Provides a grid of subplots for visualizing relationships between variables using
different facets.
Pairwise Relationships:
• sns.pairplot(): Generates a grid of scatter plots for examining pairwise relationships between numerical
columns in a dataset, with histograms along the diagonal.
Heatmaps:
• sns.heatmap(): Generates heatmaps to visualize the correlation matrix or other 2D data structures.
Saving and Exporting Plots:
• Plots created with Seaborn can be saved using Matplotlib functions like plt.savefig().

11
6.5 Scikit-Learn
Scikit-Learn, often referred to as sklearn, is a Python library for machine learning that provides a wide range
of functions and tools for various aspects of machine learning tasks. Below, I'll explain Scikit-Learn in the
context of machine learning, along with some key functions and concepts:
Data Preparation:
• Data Splitting: train_test_split(): Splits a dataset into training and testing sets for model evaluation.
• Data Preprocessing: Functions like StandardScaler() and MinMaxScaler() are used to scale and
normalize features. LabelEncoder() and OneHotEncoder() are used for encoding categorical variables.
Supervised Learning:
• Classification: Scikit-Learn includes classifiers like LogisticRegression, DecisionTreeClassifier,
RandomForestClassifier, and more. Key functions include fit(), predict(), and score().
• Regression: Regression models like LinearRegression, Ridge, and Lasso are available for predictive
modeling. Similar functions as in classification are used for regression tasks.
Unsupervised Learning:
• Clustering: Scikit-Learn provides clustering algorithms such as KMeans, DBSCAN, and
AgglomerativeClustering. Key functions include fit() and predict().
• Dimensionality Reduction: Techniques like PCA (Principal Component Analysis) and TSNE (t-
distributed Stochastic Neighbor Embedding) are used for dimensionality reduction and visualization.
Model Evaluation:
• Cross-Validation: cross_val_score() and KFold() are used for k-fold cross-validation to estimate a
model's performance on unseen data.
• Metrics: Scikit-Learn provides metrics like accuracy_score, precision_score, recall_score, f1_score,
and mean_squared_error for evaluating model performance.
Hyperparameter Tuning:
• Grid Search: GridSearchCV() allows you to perform hyperparameter tuning by specifying a grid of
hyperparameters to search over.
• Randomized Search: RandomizedSearchCV() performs hyperparameter tuning using randomized
search, which is often faster than grid search.

12
6.6 TensorFlow
TensorFlow is an open-source machine learning framework developed by Google. It's designed for creating,
training, and deploying machine learning models, particularly deep learning models. TensorFlow allows you
to build and train neural networks for a wide range of machine learning tasks. Here's an explanation of
TensorFlow in the context of machine learning, along with some key functions and concepts:
TensorFlow Core:
• Tensors: TensorFlow is named after its core concept, tensors, which are multi-dimensional arrays. Tensors
can be constants, variables, or placeholders.
• Computational Graph: TensorFlow builds a computational graph that represents the operations to be
performed on tensors. This allows for efficient execution and optimization.
Building Models:
• Sequential API (Keras): TensorFlow's Keras API is the preferred high-level interface for building deep
learning models. It simplifies the process of creating and training neural networks.
• Functional API: TensorFlow allows you to create models with more complex architectures, including
multiple inputs and outputs.
Layers and Activation Functions:
• TensorFlow provides a variety of layers like Dense, Conv2D, LSTM, and activation functions like relu,
sigmoid, and tanh to build neural network architectures.
Loss Functions and Optimizers:
• tf.losses: TensorFlow includes various loss functions (e.g., mean_squared_error,
categorical_crossentropy) to measure the model's error.
• tf.optimizers: It offers optimization algorithms such as SGD, Adam, and RMSprop to minimize the loss
during training.
Model Training:
• model.compile(): Configures the model with the chosen loss function, optimizer, and metrics.
• model.fit(): Trains the model on labeled training data, specifying the number of epochs and batch size.
Model Evaluation:
• model.evaluate(): Evaluates the trained model on a test dataset to assess its performance using metrics
like accuracy, loss, etc.
Saving and Loading Models:
• model.save() and tf.keras.models.load_model(): You can save a trained model to disk and load it later
for inference or further training.

13
6.7 Keras
Keras is an open-source deep learning library that serves as a high-level neural network API. It is designed to
be user-friendly, modular, and easy to understand, making it a great choice for both beginners and
experienced deep learning practitioners. Keras abstracts away many of the complexities of building and
training neural networks, allowing users to focus on model design and experimentation.
1. Ease of Use:
• High-Level API: Keras provides a simple and intuitive high-level API for building neural
networks. This high-level interface is user-friendly and abstracts many low-level details, making
it easy to get started with deep learning.
• Modular: Keras allows you to build models by stacking layers in a sequential manner, which is
intuitive and modular. You can add, remove, or modify layers with ease.
• Readability: Keras code tends to be concise and easy to read, which is especially beneficial for
those new to deep learning.
2. Compatibility:
• Multiple Backends: Keras can run on top of multiple deep learning backends, including
TensorFlow, Theano, and CNTK. This means you can use the same Keras code with different
backends, allowing you to leverage the strengths of each backend.
3. Community and Documentation:
• Active Community: Keras has a large and active user community, resulting in abundant tutorials,
examples, and support resources.
• Comprehensive Documentation: Keras provides comprehensive documentation with clear
explanations and examples for various use cases.

14
Chapter 7
Image Processing
1. About Digital Images & Processing:
• In AI/ML, digital images are essential data sources for computer vision tasks. They consist of a grid of
pixels, with each pixel representing a color or intensity value. Image processing involves manipulating
and analysing these images to extract valuable information. AI and ML algorithms are often applied to
process and understand digital images, enabling tasks like object detection, image classification, and facial
recognition.
2. Concept of Computer Vision in AI:
• Computer vision is a subfield of AI that focuses on teaching machines to interpret visual information from
the world, just like humans do with their eyes. Computer vision algorithms use image processing
techniques to analyze and understand the content of images or videos. This enables AI systems to
recognize objects, detect patterns, and make decisions based on visual input.
3. Working on Digital Images (skimage, OpenCV, Pillow, imutils):
• Various Python libraries like scikit-image (skimage), OpenCV, Pillow, and imutils provide tools and
functions for working with digital images. These libraries are crucial for loading, manipulating,
enhancing, and saving images. OpenCV, in particular, is widely used for computer vision tasks and offers
a comprehensive set of functions for image processing and analysis.
4. Use of Matplotlib library for Images & Graphs:
• Matplotlib is a Python library commonly used for data visualization, including the display of images and
plots. In AI/ML, Matplotlib is often used to visualize processed images, display results, and plot graphs
that help analyze image-related data, such as histograms or performance metrics of AI models.
5. Changing Color-spaces, Geometric Transformations:
• Color-spaces are representations of colors in images. In AI/ML, converting between color-spaces (e.g.,
RGB, grayscale, HSV) is essential for various image analysis tasks. Geometric transformations involve
operations like resizing, rotating, or cropping images, which are often needed for data preprocessing and
augmentation in AI/ML pipelines.
6. Image Thresholding, Filtering, Morphology:
• Image thresholding is the process of segmenting an image into regions based on intensity levels. Filtering
involves applying convolutional operations to images for tasks like noise reduction and feature
enhancement. Morphological operations are used to manipulate the shape and structure of objects in an
image, which is valuable for tasks like object segmentation.

15
Chapter 8
Machine Learning Algorithms
8.1 Logitic Regresssion
Logistic regression is a supervised machine learning algorithm mainly used for classification tasks where the goal
is to predict the probability that an instance of belonging to a given class. It is used for classification algorithms
its name is logistic regression. it’s referred to as regression because it takes the output of the linear
regression function as input and uses a sigmoid function to estimate the probability for the given class. Logistic
regression is used for solving the classification problems.
• In Logistic regression, instead of fitting a regression line, we fit an “S” shaped logistic function, which
predicts two maximum values (0 or 1).
Logistic Function (Sigmoid Function):
• The sigmoid function is a mathematical function used to map the predicted values to probabilities.
• It maps any real value into another value within a range of 0 and 1. o The value of the logistic regression
must be between 0 and 1, which cannot go beyond this limit, so it forms a curve like the “S” form.
• The S-form curve is called the Sigmoid function or the logistic function.
• In logistic regression, we use the concept of the threshold value, which defines the probability of either 0
or 1. Such as values above the threshold value tends to 1, and a value below the threshold values tends to
0.
Type of Logistic Regression:
On the basis of the categories, Logistic Regression can be classified into three types:
1. Binomial: In binomial Logistic regression, there can be only two possible types of the dependent
variables, such as 0 or 1, Pass or Fail, etc.
2. Multinomial: In multinomial Logistic regression, there can be 3 or more possible unordered types of the
dependent variable, such as “cat”, “dogs”, or “sheep”
3. Ordinal: In ordinal Logistic regression, there can be 3 or more possible ordered types of dependent
variables, such as “low”, “Medium”, or “High”.

Import statements
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import train_test_split
16
8.2 Linear Regression
Linear regression is a type of supervised machine learning algorithm that computes the linear relationship
between a dependent variable and one or more independent features. When the number of the independent feature,
is 1 then it is known as Univariate Linear regression, and in the case of more than one feature, it is known as
multivariate linear regression. The goal of the algorithm is to find the best linear equation that can predict the
value of the dependent variable based on the independent variables.

fig. Linear Regression

Types of Linear Regression


Linear regression can be further divided into two types of the algorithm:
o SimpleLinearRegression:
If a single independent variable is used to predict the value of a numerical dependent variable, then such
a Linear Regression algorithm is called Simple Linear Regression.
o MultipleLinearregression:
If more than one independent variable is used to predict the value of a numerical dependent variable, then
such a Linear Regression algorithm is called Multiple Linear Regression.

Cost function-
o The different values for weights or coefficient of lines (a0, a1) gives the different line of regression, and
the cost function is used to estimate the values of the coefficient for the best fit line.
o Cost function optimizes the regression coefficients or weights. It measures how a linear regression model
is performing.
o We can use the cost function to find the accuracy of the mapping function, which maps the input variable
to the output variable. This mapping function is also known as Hypothesis function.
For Linear Regression, we use the Mean Squared Error (MSE) cost function, which is the average of
squared error occurred between the predicted values and actual values.

17
Gradient Descent:
o Gradient descent is used to minimize the MSE by calculating the gradient of the cost function.
o A regression model uses gradient descent to update the coefficients of the line by reducing the cost
function.
o It is done by a random selection of values of coefficient and then iteratively update the values to reach
the minimum cost function.

R-squared method:

o R-squared is a statistical method that determines the goodness of fit.

o It measures the strength of the relationship between the dependent and independent variables

on a scale of 0-100%.

o The high value of R-square determines the less difference between the predicted values and

actual values and hence represents a good model.

o It is also called a coefficient of determination, or coefficient of multiple determination for

multiple regression.

o It can be calculated from the below formula:

18
8.3 Decision Tree
A decision tree is a type of supervised learning algorithm that is commonly used in machine learning to model
and predict outcomes based on input data. It is a tree-like structure where each internal nodetests on attribute,
each branch corresponds to attribute value and each leaf node represents the final decision or prediction.

Important Concept related to Decision Tree

As you can see from the above image the Decision Tree works on the Sum of Product form which is also known
as Disjunctive Normal Form. In the above image, we are predicting the use of computer in the daily life of people.
In the Decision Tree, the major challenge is the identification of the attribute for the root node at each level. This
process is known as attribute selection. We have two popular attribute selection measures:
1. Information Gain
o Information gain is the measurement of changes in entropy after the segmentation of a dataset based on
an attribute.
o It calculates how much information a feature provides us about a class.
o According to the value of information gain, we split the node and build the decision tree.
o A decision tree algorithm always tries to maximize the value of information gain, and a node/attribute
having the highest information gain is split first. It can be calculated using the below formula:
1. Information Gain= Entropy(S)- [(Weighted Avg) *Entropy(each feature)

19
2.Gini Index
o Gini index is a measure of impurity or purity used while creating a decision tree in the
CART(Classification and Regression Tree) algorithm.
o An attribute with the low Gini index should be preferred as compared to the high Gini index.
o It only creates binary splits, and the CART algorithm uses the Gini index to create binary splits.
o Gini index can be calculated using the below formula:
Gini Index= 1- ∑jPj2

20
8.4 Random Forest
Random Forest is a popular machine learning algorithm that belongs to the supervised learning technique. It can
be used for both Classification and Regression problems in ML. It is based on the concept of ensemble
learning, which is a process of combining multiple classifiers to solve a complex problem and to improve the
performance of the model.
As the name suggests, "Random Forest is a classifier that contains a number of decision trees on various subsets
of the given dataset and takes the average to improve the predictive accuracy of that dataset." Instead of relying
on one decision tree, the random forest takes the prediction from each tree and based on the majority votes of
predictions, and it predicts the final output.
The greater number of trees in the forest leads to higher accuracy and prevents the problem of overfitting.

Why use Random Forest?


Below are some points that explain why we should use the Random Forest algorithm:
o It takes less training time as compared to other algorithms.
o It predicts output with high accuracy, even for the large dataset it runs efficiently.
o It can also maintain accuracy when a large proportion of data is missing.
How does Random Forest algorithm work?
Random Forest works in two-phase first is to create the random forest by combining N decision tree, and
second is to make predictions for each tree created in the first phase.
The Working process can be explained in the below steps and diagram:
Step-1: Select random K data points from the training set.
Step-2: Build the decision trees associated with the selected data points (Subsets).
Step-3: Choose the number N for decision trees that you want to build.
Step-4: Repeat Step 1 & 2.
Step-5: For new data points, find the predictions of each decision tree, and assign the new data points to the
category that wins the majority votes.

21
Applications of Random Forest
There are mainly four sectors where Random forest mostly used:
1. Banking: Banking sector mostly uses this algorithm for the identification of loan risk.
2. Medicine: With the help of this algorithm, disease trends and risks of the disease can be identified.
3. Land Use: We can identify the areas of similar land use by this algorithm.
4. Marketing: Marketing trends can be identified using this algorithm.
Advantages of Random Forest
o Random Forest is capable of performing both Classification and Regression tasks.
o It is capable of handling large datasets with high dimensionality.
o It enhances the accuracy of the model and prevents the overfitting issue.

Fitting the Random Forest algorithm to the training set:


Now we will fit the Random Forest algorithm to the training set. To fit it, we will import
the RandomForestClassifier class from the sklearn.ensemble library. The code is given below:
1. #Fitting Decision Tree classifier to the training set
2. from sklearn.ensemble import RandomForestClassifier
3. classifier= RandomForestClassifier(n_estimators= 10, criterion="entropy")
4. classifier.fit(x_train, y_train)
In the above code, the classifier object takes below parameters:
o n_estimators= The required number of trees in the Random Forest. The default value is 10. We can
choose any number but need to take care of the overfitting issue.
o criterion= It is a function to analyze the accuracy of the split. Here we have taken "entropy" for the
information gain.

22
8.5 Support Vector Machine Algorithm
Support Vector Machine or SVM is one of the most popular Supervised Learning algorithms, which is used for
Classification as well as Regression problems. However, primarily, it is used for Classification problems in
Machine Learning.
The goal of the SVM algorithm is to create the best line or decision boundary that can segregate n-dimensional
space into classes so that we can easily put the new data point in the correct category in the future. This best
decision boundary is called a hyperplane.
SVM chooses the extreme points/vectors that help in creating the hyperplane. These extreme cases are called as
support vectors, and hence algorithm is termed as Support Vector Machine. Consider the below diagram in which
there are two different categories that are classified using a decision boundary or hyperplane:

SVM algorithm can be used for Face detection, image classification, text categorization, etc
Types of SVM
SVM can be of two types:
o Linear SVM: Linear SVM is used for linearly separable data, which means if a dataset can be classified
into two classes by using a single straight line, then such data is termed as linearly separable data, and
classifier is used called as Linear SVM classifier.
o Non-linear SVM: Non-Linear SVM is used for non-linearly separated data, which means if a dataset
cannot be classified by using a straight line, then such data is termed as non-linear data and classifier used
is called as Non-linear SVM classifier.

23
8.6 Naïve Bayes Classifier Algorithm

o Naïve Bayes algorithm is a supervised learning algorithm, which is based on Bayes theorem and used for
solving classification problems.
o It is mainly used in text classification that includes a high-dimensional training dataset.
o Naïve Bayes Classifier is one of the simple and most effective Classification algorithms which helps in
building the fast machine learning models that can make quick predictions.
o It is a probabilistic classifier, which means it predicts on the basis of the probability of an object.
o Some popular examples of Naïve Bayes Algorithm are spam filtration, Sentimental analysis, and
classifying articles.

Bayes' Theorem:
o Bayes' theorem is also known as Bayes' Rule or Bayes' law, which is used to determine the probability
of a hypothesis with prior knowledge. It depends on the conditional probability.
o The formula for Bayes' theorem is given as:

Where,
P(A|B) is Posterior probability: Probability of hypothesis A on the observed event B.
P(B|A) is Likelihood probability: Probability of the evidence given that the probability of a hypothesis is
true.
P(A) is Prior Probability: Probability of hypothesis before observing the evidence.
P(B) is Marginal Probability: Probability of Evidence.

24
Chapter 9
Deep Learning Algorithms
9.1 Artificial Neural Network
Artificial Neural Network Tutorial provides basic and advanced concepts of ANNs. Our Artificial Neural
Network tutorial is developed for beginners as well as professions.
The term "Artificial neural network" refers to a biologically inspired sub-field of artificial intelligence
modelled after the brain. An Artificial neural network is usually a computational network based on biological
neural networks that construct the structure of the human brain. Similar to a human brain has neurons
interconnected to each other, artificial neural networks also have neurons that are linked to each other in various
layers of the networks. These neurons are known as nodes.
Artificial neural network tutorial covers all the aspects related to the artificial neural network. In this tutorial,
we will discuss ANNs, Adaptive resonance theory, Kohonen self-organizing map, Building blocks,
unsupervised learning, Genetic algorithm, etc.
What is Artificial Neural Network?
The term "Artificial Neural Network" is derived from Biological neural networks that develop the structure
of a human brain. Similar to the human brain that has neurons interconnected to one another, artificial neural
networks also have neurons that are interconnected to one another in various layers of the networks. These
neurons are known as nodes.

The given figure illustrates the typical diagram of Biological Neural Network.
The typical Artificial Neural Network looks something like the given figure.

25
Dendrites from Biological Neural Network represent inputs in Artificial Neural Networks, cell nucleus
represents Nodes, synapse represents Weights, and Axon represents Output.
The architecture of an artificial neural network:
To understand the concept of the architecture of an artificial neural network, we have to understand what a
neural network consists of. In order to define a neural network that consists of a large number of artificial
neurons, which are termed units arranged in a sequence of layers. Lets us look at various types of layers
available in an artificial neural network.
Artificial Neural Network primarily consists of three layers:

Input Layer:
As the name suggests, it accepts inputs in several different formats provided by the programmer.
Hidden Layer:
The hidden layer presents in-between input and output layers. It performs all the calculations to find hidden
features and patterns.
Output Layer:
The input goes through a series of transformations using the hidden layer, which finally results in output that
is conveyed using this layer.
The artificial neural network takes input and computes the weighted sum of the inputs and includes a bias. This
computation is represented in the form of a transfer function.
26
It determines weighted total is passed as an input to an activation function to produce the output. Activation
functions choose whether a node should fire or not. Only those who are fired make it to the output layer. There
are distinctive activation functions available that can be applied upon the sort of task we are performing.

27
9.2 Convolution Neural Network
Convolutional Neural Network (CNN) is the extended version of artificial neural networks (ANN) which is
predominantly used to extract the feature from the grid-like matrix dataset. For example, visual datasets like
images or videos where data patterns play an extensive role.
CNN architecture
Convolutional Neural Network consists of multiple layers like the input layer, Convolutional layer, Pooling layer,
and fully connected layers.

Simple CNN architecture


The Convolutional layer applies filters to the input image to extract features, the Pooling layer downsamples the
image to reduce computation, and the fully connected layer makes the final prediction. The network learns the
optimal filters through backpropagation and gradient descent.
Layers used to build ConvNets
A complete Convolution Neural Networks architecture is also known as covnets. A covnets is a sequence of
layers, and every layer transforms one volume to another through a differentiable function.
Types of layers: datasets
Let’s take an example by running a covnets on of image of dimension 32 x 32 x 3.
• Input Layers: It’s the layer in which we give input to our model. In CNN, Generally, the input will be an
image or a sequence of images. This layer holds the raw input of the image with width 32, height 32, and
depth 3.
• Convolutional Layers: This is the layer, which is used to extract the feature from the input dataset. It
applies a set of learnable filters known as the kernels to the input images. The filters/kernels are smaller
matrices usually 2×2, 3×3, or 5×5 shape. it slides over the input image data and computes the dot product
between kernel weight and the corresponding input image patch. The output of this layer is referred ad
feature maps. Suppose we use a total of 12 filters for this layer we’ll get an output volume of dimension
32 x 32 x 12.

28
• Activation Layer: By adding an activation function to the output of the preceding layer, activation layers
add nonlinearity to the network. it will apply an element-wise activation function to the output of the
convolution layer. Some common activation functions are RELU: max(0, x), Tanh, Leaky RELU, etc.
The volume remains unchanged hence output volume will have dimensions 32 x 32 x 12.
• Pooling layer: This layer is periodically inserted in the covnets and its main function is to reduce the size
of volume which makes the computation fast reduces memory and also prevents overfitting. Two common
types of pooling layers are max pooling and average pooling. If we use a max pool with 2 x 2 filters and
stride 2, the resultant volume will be of dimension 16x16x12.

• Flattening: The resulting feature maps are flattened into a one-dimensional vector after the convolution
and pooling layers so they can be passed into a completely linked layer for categorization or regression.
• Fully Connected Layers: It takes the input from the previous layer and computes the final classification
or regression task.

29
• Output Layer: The output from the fully connected layers is then fed into a logistic function for
classification tasks like sigmoid or softmax which converts the output of each class into the probability
score of each class.

30
Chapter 10
CONCLUSION

"In conclusion, the integration of Artificial Intelligence (AI) and Machine Learning (ML) with Python
has opened up a world of possibilities for solving complex problems, automating tasks, and making data-
driven decisions. AIML, which stands for Artificial Intelligence and Machine Learning, leverages
Python's rich ecosystem of libraries and tools to create intelligent systems, predictive models, and data-
driven applications. Whether it's natural language processing, image recognition, recommendation
systems, or predictive analytics, Python's versatility and extensive AI and ML libraries like TensorFlow,
Scikit-Learn, and Keras have made it a leading choice for researchers, data scientists, and developers.
AIML using Python empowers us to harness the power of data and create intelligent solutions that drive
innovation and transform industries."

31
• REFERENCES:

32

33

You might also like