Part 1: Machine Learning Foundations
Module 1: Machine Learning Basics
- AI vs ML vs Deep Learning: Relationship explained using Venn diagram; AI is the broadest field, ML is a subset, DL is a further subset. For a more detailed exploration, see the Comprehensive Artificial Intelligence Course: AI, ML, Deep Learning & NLP.
- Types of Machine Learning:
- Supervised Learning: Learns from labeled data (e.g., classifying apple vs. mango images)
- Classification: Predict discrete classes (e.g., dog vs. cat)
- Regression: Predict continuous values (e.g., salary, rainfall amount)
- Unsupervised Learning: Learns from unlabeled data; automatically finds patterns and groups
- Clustering: Groups similar data points (e.g., customer segmentation)
- Association: Finds relationships between data points (e.g., market basket analysis)
- Reinforcement Learning: Agent learns through trial and error to maximize rewards (e.g., game-playing AI)
- Supervised Learning: Learns from labeled data (e.g., classifying apple vs. mango images)
- Deep Learning: Subfield using artificial neural networks; excels at automatic feature extraction. Dive deeper into this topic with Understanding Introduction to Deep Learning: Foundations, Techniques, and Applications.
Module 2: Python Basics for Machine Learning
- Google Colab Setup: Cloud-based environment with 12GB RAM, no installation needed
- Data Types: int, float, complex, boolean, string
- Data Structures: list (mutable, allows duplicates), tuple (immutable, allows duplicates), set (mutable, no duplicates, no indexing), dictionary (key-value pairs)
- Operators: Arithmetic, assignment, comparison, logical, identity, membership
- Control Flow: if/else, elif, nested if statements
- Loops: for loop (when iteration count known), while loop (when count uncertain)
- Functions: Reusable code blocks; example with factorial function
Module 3: Essential Python Libraries
- NumPy:
- Arrays vs. lists: 5-10x faster operations
- Creating arrays: 1D, 2D, placeholder arrays (zeros, ones, full, identity)
- Mathematical operations: element-wise addition, subtraction, multiplication, division
- Array manipulation: transpose (
.Tornp.transpose()), reshape (.reshape())
- Pandas:
- DataFrames: Two-dimensional labeled data structures
- Loading data:
pd.read_csv(),pd.read_excel() - Inspecting data:
head(),tail(),shape,info(),describe() - Handling missing values:
isnull().sum() - Statistical measures: mean, median, standard deviation (column-wise)
- Group operations:
groupby(),value_counts() - Correlation matrix:
.corr()
- Matplotlib:
- Line plots, bar charts, pie charts, scatter plots, 3D plots
- Customizing plots: x/y labels, titles, colors, markers
- Seaborn:
- Statistical plots:
relplot(),distplot(),countplot(),barplot() - Heatmaps for correlation visualization
- Statistical plots:
Module 4: Data Collection and Preprocessing
- Data Sources: Kaggle, UCI Machine Learning Repository, Google Dataset Search
- Kaggle API: Directly download large datasets to Colab
- Handling Missing Values:
- Imputation: Replace with mean (normal distribution), median (skewed data), or mode (categorical data)
- Dropping: Remove rows with missing values (only for large datasets)
- Data Standardization: Using
StandardScalerto transform all features to common range (mean=0, std=1) - Label Encoding: Convert categorical labels to numerical values using
LabelEncoder - Train-Test Split: Split data into training (80%) and testing (20%) sets using
train_test_split - Handling Imbalanced Data: Use undersampling to balance class distribution (e.g., reduce majority class to match minority class count)
- Text Feature Extraction: Use
TfidfVectorizerto convert text into numerical feature vectors (Term Frequency-Inverse Document Frequency)
Module 4 Use Cases (Projects)
1. Rock vs. Mine Prediction using Sonar Data
- Objective: Classify sonar signals as rock or mine
- Model: Logistic Regression
- Performance: 83.4% training accuracy, 76.2% test accuracy
- Workflow:
- Load sonar dataset (208 samples, 60 features)
- Split features (X) and labels (Y: R or M)
- Split into training (90%) and testing (10%) with stratification
- Train logistic regression model
- Evaluate and build predictive system
2. Diabetes Prediction using Support Vector Machine
- Objective: Predict diabetes diagnosis from medical parameters
- Model: SVM with linear kernel
- Performance: 78.6% training accuracy, 77.3% test accuracy
- Workflow:
- Load PIMA diabetes dataset (768 samples, 8 features + outcome)
- Standardize features using
StandardScaler - Split into training (80%) and testing (20%) with stratification
- Train SVM model
- Predict diabetes status for new patient data
3. Spam Mail Detection using Logistic Regression
- Objective: Classify emails as spam or ham (non-spam)
- Model: Logistic Regression with TF-IDF features
- Performance: 96.7% training accuracy, 96.5% test accuracy
- Workflow:
- Load mail dataset (5572 samples)
- Replace null values, encode labels (spam=0, ham=1)
- Split into training (80%) and testing (20%)
- Apply
TfidfVectorizer(min_df=1, stop_words='english') - Train logistic regression model
- Predict spam/ham for new emails
Key Takeaways
- Data preprocessing is critical: Standardization, handling missing values, and balancing datasets improve model performance. For a more structured path through these concepts, check out the 100 Days of Machine Learning: Comprehensive Beginner to Intermediate Guide.
- Choose the right model: Logistic Regression for binary classification, SVM for complex decision boundaries
- Evaluate properly: Check both training and test accuracy to detect overfitting
- Text data requires special handling: TF-IDF vectorization converts text to meaningful numerical features
- Real-world applications: Spam detection, medical diagnosis, and object classification are practical ML use cases. Building on Python basics, you can also explore the Comprehensive Python Course: From Basics to Advanced Mega Projects or the Complete Python Guide: From Basics to Real-Time Weather App for further practical projects.
hello everyone i am siddharthan in this youtube channel i teach about artificial intelligence and machine learning
recently i planned to make a complete machine learning course with both conceptual topics and hands-on part in
python this will be a 60 hours long course with five parts and each part will be around
12 hours and there will be several use cases and projects in each of these parts and i have tried to add as much
topics as possible that are like very important so all these videos are already present
in my youtube channel individually and i wanted to combine all these things together so that it is easier for a
person who is just starting to learn about machine learning so i hope you have a great time learning this and all
the best to you so let me just quickly uh tell you what are all the topics that will be present
in this first part so we totally have about 10 modules in this machine learning course and this first
module will be machine learning basics where i explain you about what is the difference between artificial
intelligence machine learning and deep learning then the next topic will be what are all the different types of
machine learning such as supervised learning and surprise learning reinforcement learning and we will
discuss in detail about each of these topics individually and i explain you about what is meant by deep learning and
how it differs from machine learning and what are all the different applications of it so this is more of a theoretical
part where we understand the very basics of eml and the second module is again a very important one on python basics for
machine learning so all the use cases and programming that we do in this uh
you know course will be in python so it is important for us to understand some of the basics of python so there will be
uh you know how to use google collaboratory so google collaboratory is the platform that we use for our coding
again in this course so i have given you the basic understanding of how to use this google collaboratory
and what are all the features then there are topics such as like various data types list dictionary tuple etcetera and
you know how to use loops in python and how to create functions in python so those topics will be covered in the
second module and third module is again an interesting module where we discuss about some of the important libraries
that we need in machine learning such as numpy pandas matplotlib and c bond so numpy is more
of a library that supports this numpy array where we do several mathematical
operations and pandas is more of a data frame which you can consider about like a tables and matplotlib and c1 are
mainly used for data visualization where we build this you know plots and graphs and this is like a very important
library that is like widely used in data science applications where we need to build these plots to understand the data
better and the fourth module will be data collection and pre-processing where i will explain you about where you can
collect this data what are all the reliable sources that we have for this data collection and how to do various
data processing uh like handling the missing values and and you know how to handle
imbalance dataset train test split label encoding and all these topics will be covered here and also i have explained
about how to handle textual data as well so these are all the four modules that we have
and uh once all these modules are completed so there will be three use cases video so the first use case will
be on rock versus mind prediction where we train a machine learning model to predict whether a object is a rock or it
is a mind so that will be the first use case and the second use case will be predicting whether a person will be
having diabetes or not so this will be the second use case and the third one is an interesting one regarding textual
analysis where we try to build a machine learning system that predicts whether a male is a normal male or it is a spam
male so this will be the topics that we will be covering in this first part of this machine learning course so once
this part is completed so i'll upload videos on the upcoming parts where you have like more advanced and complex
topics on machine learning such as uh different machine learning models processes like cross validation hyper
parameter tuning etc okay so again all the very best so i hope you have a great time and
i'll create a github repository and put all the code and jupyter notebook files that is done in all these videos so you
can like refer that as well and most importantly i'll also give you time stamps for all these individual topics
so if you are interested in a specific topic you can like skip to that part okay so let's get started
artificial intelligence machine learning and deep learning so when you start learning about ai or machine learning
this is one of the most basic and inevitable question you need to answer and often interviewers ask this question
to know whether someone really knows about this topic or is just making things up so let's try to understand
what is the relationship between these terms and then we shall try to understand what these three concepts
mean okay first of all so there is a picture which clearly represents the relationship
between these terms so as you can see this image this venn diagram artificial intelligence is a broader field and
machine learning is a subset of artificial intelligence and again deep learning is a further subset of machine
learning okay so this is the relationship between them now let's try to understand about these
topics separately so what happens is people sometimes think that all these three terms mean the same thing but
that's not the case so as i said earlier ml is a subset of ai and deep learning is a subset of ml okay now let's try to
understand these topics separately so what is artificial intelligence artificial intelligence is a branch of
computer science that is concerned with building smart and intelligent machines so what does intelligent machines mean
and what does non-intelligent machines mean let's try to understand this with some examples
so examples of non-intelligent machines can be you know it can be a warts or it can be a bike because these machines
cannot think these machines cannot make decisions or do new things they are given a set work and they just do that
work repeatedly and what are intelligent machines so example for intelligent machines are autonomous cars example you
can consider a test locker and you can also consider google assistant which we you know encounter it in our daily life
so a tesla car is more you know intelligent than a normal car because it you know it doesn't require any input
from the driver and it can drive the car autonomously and google assistance is something that
you know it uses ai for its function so when we you know text google assistant in our phone
we don't feel like it is a computer software if we feel as if it is a human being so these are intelligent machines
because they can think and give you an answer they can do new things they can make the decisions of their own which is
not possible in the case of non-intelligent machines so artificial intelligence is all about
making these intelligent machines okay now let's try to understand about machine learning so what is machine
learning machine learning is a technique to implement artificial intelligence that can learn from the data by
themselves without being explicitly programmed so machine learning is all about the data okay so let's try to
consider an example so i want a system to
detect whether the image is the image of iron man or captain america okay so this is the task i said for the system okay
so we need to make this system so when we take a machine learning approach what we will do is
for the machine learning algorithm we will feed numerous images of both iron man and captain america and we will tell
that algorithm that these images are of iron man and these images are of captain america so now the algorithm
without our input it just finds the pattern between the images and when you give a new image it can predict
correctly whether that images of iron man or captain america so this is all about machine learning okay so what we
do is we just give the algorithm a lot of data to learn from okay it is just similar to a child
seeing something and learning from it so we just give it data and we don't need to do anything else so
it can find the patterns and learn from itself so this is called as machine learning and
this is how we implement ai okay now let's try to understand about deep learning deep learning is again a
subfield of machine learning that uses a special type of algorithms called as artificial neural networks to learn from
the data so this is a pictorial representation of the artificial neural network okay so
these artificial neural networks are modeled from our human brain from the neurons present in our human brains
there are numerous neurons in our brain that are interconnected so each neuron process
the information and sends the output to another neuron so this is the same concept used in the case of artificial
neural networks so they are nothing but a mathematical model that are connected like the neurons in our brain okay so
there are different layers in those artificial neural network so as you can see here the first layer is an input
layer then there are several hidden layers and then there will be outer output layer okay so we can discuss
about this in more detail in the future videos but you know in this video the idea is to give you a short idea about
what these three terms means okay so first we see
what is meant by artificial intelligence so then we saw what is meant by machine learning so machine learning is a
technique to implement artificial intelligence and again deep learning is one of the subset of machine learning
which just uses artificial neural networks okay so that's it about the difference between these three terms
machine learning and deep learning in this video i would like to explain you about the different types of machine
learning okay so first of all i'll explain you what is meant by machine learning with an example then we will
look into all the different types okay so machine learning machine learning is a technique to implement artificial
intelligence that can learn from the data by themselves without being explicitly programmed okay so the
ultimate goal in machine learning is to make intelligent machines right and how we do is by making the machine to learn
from the data okay so we don't do explicit program which means we don't tell the machine exactly what it has to
do so it has to you know find those ways by itself so i will try to explain this with an example okay so
we want a machine to see an image and to recognize whether the image represents a dog or cat okay
so this is the goal for the system we are building now in machine learning what we will do is
we will make the model or the machine learning model to learn from the data here the data will be several images of
docks and catch okay so we will feed this images of dogs and cats to our machine learning model and with the help
of these images it tries to find pattern in these images and when you give a new image it can recognize whether the image
represents a dog or cat okay so this is how machine learning works so it basically learns from the data okay now
let's discuss about the different types of machine learning okay so there are three main types of machine learning one
is supervised learning the next one is unsupervised learning and the third one is reinforcement learning okay so in
supervised learning there is some supervision to the machine learning algorithm by the programmers or by us
and in unsupervised learning there is no supervision for the machine and reinforcement learning is completely a
different type and it is not related to each of this supervised or unsupervised learning okay so let's try to understand
this in more detail first of all surprise learning in supervised learning the machine learning algorithm learns
from labeled data so we already see that you know in machine learning the model learns from the data right
so what is what is meant by label data set let's say that a machine learning model has to see an image and recognize
whether the image represents an apple or a mango okay so now what we will do is we will take several images of apples
and mangoes and we will tell the machine that these images belongs to apples and these are
the images of mangos okay now these apples and mangoes so this name is called as labels and we feed this label
dataset to our machine learning model now our machine learning model or machine learning algorithm tries to find
the patterns between these images okay and once it it has learned from the data
when you give an unknown image it can correctly recognize whether the image represents an apple or a mango so this
is how supervised learning works so we are telling it it is you know known as supervised learning because we are
giving a supervision in terms of labels okay now let's discuss about unsupervised learning so
in unsupervised learning the machine learning algorithm learns from unlabeled data here we won't tell what that data
represents okay so we won't give any labels let's consider a similar example so we will give several images of apple
and mangos to our machine learning model and we won't tell that these images belong to apple or these images belong
to mango so we feed all these images without telling what it is to our machine
learning model and what it does is it tries to again find the pattern and it tries to group
all these images and it will group the images into group one and group two okay so all the apples will be grouped in one
group and all the mangoes will be grouped in another group so when you give a new image of an apple or a main
group it tells you whether it belongs to the group or group so this is called as
unsupervised learning because we are not giving any supervision in terms of labels okay so this is called as
unsupervised running and the third one is reinforcement learning okay so the reinforcement
running is not similar to you know supervised or unsupervised learning it's quite different from both other types
okay so let's try to understand this in more detail so this is the definition of
reinforcement learning reinforcement learning is an area of machine learning concerned with how intelligent agents
take actions in an environment to maximize its rewards okay so it can be a bit difficult to understand but i will
try to break down this you know definition into a simple steps so there are four main aspects in reinforcement
learning they are environment agent action and reward okay so there will be an environment and what we need to do is
we need to build an agent that acts in that environment okay so that agent in that environment he tries to take some
actions and for that action it gains some rewards okay so let's try to understand
this with an example we want to make a computer software or a computer program that can play chess
like a human being okay so here our chess board becomes the environment and our computer become the agent okay
so in the environment of chessboard our agent which is the computer tries to take actions so the actions represents
the move the computer takes okay so in the chess and for each step it gets a reward so
the ultimate reward is winning the chess game okay so for each step it takes closer to winning it will get a positive
reward okay so if it takes a bad step or bad move so it will get a negative reward so by this the machine tries to
learn how to play that game okay so several applications are there for reinforcement learning for example you
know several game playing artificial intelligence are based on reinforcement learning and
all the autonomous systems like cars and automatic drones are based on reinforcement learning okay
so these are the different types of machine learning so first we have discussed about
what is meant by supervised learning where we basically give the machine learning algorithm label data set and in
unsupervised learning we give unlabeled data set and reinforcement learning we will try to make an agent that acts in
an environment to increase its chance of winning okay so this is the three main types of machine learning what are the
different types of supervised learning okay so this is the agenda for today's video
and i want this channel to be more interactive so from now on i will give a link for each video in the description
and in that link you will find a google form containing mcqs for that particular topic for example so in the description
of this video you will find a google form link that contains mcq on the topic supervised learning okay so once you
complete watching these videos you can try to answer those mcqs okay so let's get started
surprise learning so supervised learning is a type of machine learning in which the machine learning algorithm learns
from the labeled dataset okay so here the most important thing to note here is the algorithm
learns from the label data okay so what is this label data so in machine learning generally we feed the machine
learning algorithm a lot of data and we tell the algorithm that that this data represents this label okay and the
algorithm tries to map the labels and the data so that it can recognize it okay let's try to understand this more
deeply with an example so we want our machine learning model to see an image and recognize whether it
represents an apple or a mango okay so this is the task for a machine learning algorithm so in the case of super easy
running what we will do is we will feed the images of apples and mangoes and we will tell the machines that these images
represents apples and these images represents mangoes okay and we feed these images to our ml model and what it
does it tries to find the relationship between these images and it maps it to the label which is apples and mangos
okay now it knows uh you know our apple looks and how a mango looks okay so once it learned from the data when you give
an unknown image it can predict correctly whether it is an apple or a mango so this is how supervised learning
works so the important point to note here is we are training the machine learning model with data which is
labeled okay so in case of unsupervised learning we don't give the machine learning algorithm the labels okay so
that is the difference between surprise and unsupervised money okay now let's discuss about the types of
surprise learning there are two main types of supervised learning one is classification and another one is
regression okay so what is mean by this classification and regression so classification is about predicting a
class or discrete value okay so that is just these class or labels okay so there is
not continuous values like numbers so it will predict whether you know the problem statement we have to predict
whether it's a male or female true or false like that okay so there will only be classes and in regression we try to
predict the continuous values for example like the salary agent price okay say for example um
we need to predict salary of a person from his work experience okay so the salary will be in a continuous number
right so those kinds of problem statements are done using regression models okay in classification we just
predict it's you know whether true or false or male or female say for example the example we have seen before where
our model classifies the images into apples or mangos whereas in regression we find a particular number okay so
let's try to understand this with another example so first of all classification so we
want our machine learning model to see an image and recognize whether the image is
you know a dog or cat so what we will do is we will give the labels and the data to our machine learning model so it maps
with that label and the images now we can tell whether it is a dog or cat so this represents classification because
we are just classifying the image into either dog or cat okay so there is no middle values right so there is not any
decimal values here it is just binary in this case now lets discuss about an example for regression lets say that we
need to predict the rainfall in centimeter value for a given temperature or pressure and different factors on
which the rainfall depends okay so what we will do is we will train our machine learning model with this data like for
example so we will tell the machine learning model that for this temperature there will be this much amount of
rainfall and for you know different cases like this and when the model is learned from the data
when we give a new temperature value it can tell you how much rainfall we can expect so the rainfall in centimeter
will be a continuous value it can be a decimal value right so this is called as regression so in classification we try
to you know predict the class or type but in regression we try to predict or we try
to find a number okay so that is the difference between classification and regression so there are various lot of
different types of application on classification and regression so which we will see in our later videos in our
project videos okay now let's see what are some most important algorithms for classification
and regression decision tree classification random forest classification k nearest neighbor
classification so these are some examples of classification algorithms and regression model algorithms includes
logistic regression polynomial regression and support vector machine recognition so it's okay if you don't
understand what is meant by these algorithms so we will be working on each type of algorithms once we start doing
the hands-on part so i'll be explaining about them in more detail once we start those all the types of unsuppression so
if you haven't watched those videos do check out them now let's discuss about what is mean by unsupervised learning
and what are the different types of unsupervised learning tasks okay so unsupervised learning non-supervised
learning the machine learning algorithms learn from unlabeled data so this is the difference between
supervised and unsupervised learning where in supervised learning we use labeled data so we will tell our machine
learning model that this data represents this item like that and we won't uh say those things in unsupervised learning so
we will train our model with unlabeled data okay so let's try to understand this with an
example so we have several images of apples and mangoes and so once we feed this data to our machine
learning model so what happens is it can group that group the data so group these images
based on uh you know similar patterns so it can group the apples in one group and it can group the mangoes in the second
group okay so what happens here is we are not telling the model that these images represents apples and these
images represents mangoes so we are not giving that label whereas in supervised learning we will tell the machine that
these images represents apple okay so that's the difference between surprise and unsupervised learning so what
happens is it automatically finds the pattern between those images and it groups the similar items in one group
and uh another items in another group okay so this is the idea behind unsupervised learning so now let's try
to see what are the different uh types of unsupervision and actually one more thing so why we are calling uh this as
unsupervised learning is that in super age learning we are giving a supervision to our machine okay so that is like a
supervisor who gives the machine the labels okay but we are not giving any labels or supervision here means this is
called as unsupervised learning so what are the types of function page learning there are two types of
unsupervised learning so first task is clustering and the another task in unsupervised learning is association
okay so what is will be clustering and association then so clustering is an unsupervised learning task which
involves grouping the similar data points so this is the example which we have discussed right now which is uh the
apple and mango example where we group the similar data points and in association super is
learning test we just try to find some important relationship between data points okay so in a big data set we try
to find which data points are associated so which are similar okay so let's try to understand these two tasks in more
detail first of all clustering okay so let's say that we get a project from from a
mobile network company so they want us to suggest some ways on how they can
increase their user base and how they can increase their revenue okay so they are giving us their user data
and what we find is so we are feeding it to a clustering
algorithm so unsupervised learning algorithm and this model is uh clustering the data into
two clusters so okay so this is one possibility where people who are having i call duration
may have very less internet usage and people who are having eye internet usage may have i call duration okay so this is
a possibility and now what we can suggest that network companies that they can give
offers on internet usage for those people who are having any call duration and less internet usage okay
and we can give offers on call durations for people uh who are having less internet uses and vice versa by this you
know people tend to use both these features more okay so this is one way by which they can increase their revenue by
you know where people can opt for both the plans so this is one clustering example where the machine learning
algorithm can cluster the data based on the user experience based on the user data okay
now let's try to understand about association so let's consider there is a supermarket and there are several
customers who are buying these products specifically so customer base bread milk uh you know fruits and wheat so there is
another kind of customers who are buying bread milk rice and butter okay so the important association
between all these customer is that if someone buys bread that customer obviously is buying milk okay so this is
one of the important uh you know relationship we have found and this is this can be used really well and when a
customer buys a bread we can suggest them that they are they can buy milk so the third customer is most most probably
is going to buy milk also okay so this is one of the method where we can use association so i would like to give you
another interesting example in this case so we are all you know uh used to the famous odt platforms like netflix and
amazon prime so those ott platforms use this kind of algorithms to suggest suggesters movies
okay so let's say that i am watching avengers movie okay so now uh the netflix can suggest me uh movies
uh regarding you know the superhero movies because someone who have already watched avengers may have watched other
superhero movies so it associates those user behaviors and it can suggest me movies watched by that user so this is
one of the interesting [Music] applications of unsupervised learning so
these are some interesting examples now let's see what are some uh important unsupervised learning algorithms so
so apart from these five algorithms there are also several unsupervised moving algorithms but these five are
very important algorithms so we have k means clustering hierarchical clustering which are examples of clustering
examples and there is another algorithm called as principal component analysis which is used to reduce the dimensions
of our data let's say for example we have a data set where it contains 1000 rows and 100 columns so we want to
reduce this dimension okay so the columns represent the features so we can use this principle component analysis
algorithm to find which columns or which features are very important for our application okay so that is where
principal component analysis is used and it is a type of an unsupervised learning algorithms where we won't give the
machine learning algorithm any labels okay and there are other two algorithms apriori and eclat so these two
algorithms are example of association task okay so these are some of the important
unsupervised learning algorithms testing what is meant by deep learning what is meant by neural network what are the
important applications of deep learning and also we are going to discuss about some important events that made deep
learning so much popular okay so these are the topics we'll be discussing so let's get started first of all what is
meant by deep learning so deep learning is a subfield of machine learning that uses artificial neural networks to learn
from the data so we have already seen the difference between artificial intelligence machine learning and deep
learning so we know that artificial intelligence is a subfield of machine learning right so in machine learning we
basically use several data and we feed this data to our machine learning algorithm to make predictions right so
in deep learning what we do is we feed it to a specialized algorithms called as artificial neural networks okay so this
is the difference between machine learning and deep running okay so now let's try to understand how this uh you
know artificial neural networks is inspired so this is the diagram of uh neurons
present in our human brain okay so this neuron consists of it and the it consists of a nucleus okay so this is
where the information is processed in our brain okay so once the information is processed it passes through the
neuron body through the axon and from there it is transferred to another neuron and the pathway goes on like this
so this is how the information is processed in our brain and it is transferred to some part of our body
okay so this is the exact principle that inspired artificial neural networks as you can see here this is the
diagrammatic representation of the artificial neural network code so basically what happens is we have
individual neurons connected to each other which forms the neural network okay so each neuron has a mathematical
function assigned to it so this neuron processes the data say for example we want to you know recognize what is the
image represents so we want to basically do an image recognition task so we feed the image to this neural network and
in the input layer this image will be splitted into it its respective pixels so there will be a lot of pixels and
each of these pixels should be given to several neurons and in the input layer this uh
information this pixel value will be processed and it will be transferred to the heater layer and then uh again there
will be some processing happening in the even layer and then it will be transferred to the output layer where
the image is predicted okay so this is how the neural network works so as i told there
are three main layers in the neural networks so first one is the input layer then is the hidden layers and finally we
have output layer okay so there can be any number of hidden layers in a neural network depending on the
task we are doing doing okay so each neuron has a mathematical function so as i have told you and this process
information and each neuron in the input layer is connected to each neuron in the hidden layer okay and this is how the
information is passed and the respective prediction is made okay so this is all about artificial neural networks
now let's try to understand what is the difference main difference between machine learning algorithms and deep
learning okay so rather than defense it is you know deep learning has one main advantage over machine learning so that
you know difference is feature extraction okay so what is meant by this feature extraction let's say that we
want a machine learning model to predict whether a image represents a car okay so when you are giving it to a machine
learning model we need to tell the model that these features are important for a car okay for example if it is a car it
should have four wheels and it should have a shape like this and all that right so we need to give those features
to our machine learning model we have to manually tell them that these features are important but we don't need to do
that in the case of deep running because the neural networks are so much powerful than any machine learning algorithms
they can determine those feature by themselves okay so that is the main advantage of deep learning or machine
learning where we don't need to extract the feature manually okay now let's uh try to understand the
events that made deep learning so much popular okay so there is a famous deep learning
company called as deep mind so it is based in uh united kingdom so it was started around 2010 so deep
learning was there you know from that point of time and even before that so what happened is in 2014 google acquired
this company so deepmind basically made game playing artificial intelligence system okay so
there is this famous game called as go so this go this board game like just but it is so much complicated and so much
you know deeper than just because in just there is limited number of uh moves one can make but the possibilities
in go is so much more so there are several moves one can make based on the configuration of the game okay so
in 2016 they made a machine learning sorry a deep learning system that can play this go game and
they challenged the world champion lee sedol so he is 18 time world champion and they challenged him for a five match
tournament okay so that game playing system was made based on deep learning okay so they have been developing this
uh over you know five or six years and uh they challenged him and what
happened is in the tournament of five games so alphago which is the system deepmind
build has beat lee sedol for forest one okay so it has won four matches and lee sedal won one matches and that is where
people started to look at deep learning and realize that deep learning is so much powerful than any other algorithms
in machine learning okay so after that several researches were made and several modifications have been done to the
neural networks and several different types of neural networks have been uh you know invented after that so this is
the point from which deep learning got so much you know popular and it was used in several kinds of fields after that
okay let's try to understand one such example for this so diabetic retinopathy so diabetic
retinopathy is a condition where a patient may lose his eyesight lose especially due to diabetes meditates
okay so this deep mind developed a system uh based on deep learning that can determine whether a person has
diabetic retinopathy from the eye scans okay so how this is basically made is the deep learning
model will be trained with several normal eye images which does not have any dc's and the model will be again
trained with several images which has diabetic retinopathy okay so once it trained when a new image is fed to this
model it can predict whether the person has diabetic retinopathy or not so the interesting thing that happened here is
it doesn't only predict whether the person has diabetic retinopathy or not it also predicted the gender of the
patient whether you know the image of the is of a male or a female it also predicted whether they have some some
other medical conditions or not so this is one of the fascinating thing that happened where the deep learning also
predicted several other things rather than only the patient has diabetic retinopathy or not
okay so these events led to the boom of deep learning after that it was used in several other fields
now let's discuss about some of the important applications of deep learning first one is healthcare okay so the
example which we have seen now is an example of healthcare applications apart from this
deep learning is used in several diagnostic departments where it is used to predict whether a person has a
specific image specific disease or not based on their scans images and other data so another example where deep
learning used is the field of autonomous cars so autonomous cars like this lab doesn't need much
driver input to drive the car right so they can drive the car by themselves and it is powered by deep learning models
then we have computer vision so computer vision is one of the important application of deep learning so it is
based on image processing techniques where the neural network is trained with several images so one such example is
face recognition system in our phones so it is based on computer vision then there is natural language
processing so natural example of natural language processing is chatbots which we most of us would have
come across and other virtual assistants like google assistant siri and alexa all these technologies are powered by deep
learning or neural networks okay so these are some of the important applications of deep learning videos the
first video in our second module which is python basics for machine learning so in our machine learning course the first
module we have discussed about the machine learning basics and this module is all about python basics for machine
learning and now let's see how we can access google collaboratory so to use google collaboratory you don't
need to install any software so you don't need to install any python software or other applications you just
need to have a good web browser so you know google chrome is better suited for this one so just go to
google and search google collab so here you will see this web page called as research.google.com so go to this
welcome to collaboratory so this is where we are going to do our python programmings in most of our projects in
this channel so here you can give this new notebook so you can also see this you know topics
here so your google drive will be connected to your google collaboratory account so you can access your google
collaboratory files from google drive as well so i create a new notebook from here so if you are starting new with a
project or with a program you can go to this new notebook and this will take you to the site
so this is the interface of google collaboratory so yeah so first of all let's change the name of
this file so you can see here it shows untitled zero so this is where you know this is the name of the file and let me
change this to google collaboratory basics
so we call this in a short form as google collab
so you can see this here i p y n b so p y and b means python notebooks there is
another type of a notebook files for this uh jupyter notebooks you can also download this google collaboratory files
so you can see this download option here so you can download this as either python notebooks or dot py so dot py
means python files so you can open this uh python notebooks in your jupyter notebooks as well so after this we need
to connect our system so you can see this connect option here so google collaboratory is basically a
cloud-based you know application where we can run python programs so what happens is when we connect our system
our you know python environment will be connected to google's backend server and that is you know in that service our
codes will run so this is how it works and you will be allocated a ram and a cpu so you can check the details of your
ram here so it says 12 gb of ram and we have about 100 gb of storage so 12 gb of ram is really good for us so good for
doing several machine learning and the deep learning projects so now let's see what are the different features of this
so you can add text in this google collab so this is called as a cell okay so in
this cell we run our ports so you can also create text here so in this text you can give the description about your
code so here i'll just give the code like now we are going to check the
specifications of the system allocated to us so i'll just mention this as
system specifications okay system specifications and uh in order to run
one cell and go to the next one you can press shift plus enter so
here let's see the system allocated to us for this i'm going to use a system
command which is cat forward slash proc slash cpu info so basically you know google collab runs on
unix so you can run unix commands here and whenever you you are running a system command we need to proceed it
with an exclamatory mark okay if we are running python programs we shouldn't include any explanatory mark
so that is one important thing to note here so when you run this cpu info it will tell us the details of the cpu
allocated for us so you can see you see the processor details here so you know we have this intel xenon processor and
this is our first processor with index 0 and this is the second processor and you can go through all the details here
and then you can also check the ram allocated to you by using this command which is
that proc slash mem info
okay so let's run this so you can press this which is run cell or you can press shift plus
enter to execute the save okay so you can see here 13.3 which is about 13.3 gb of ram allocated to us okay so
this is how you can check the system specifications now
you can go to this files option here so in this files there will be an option called as upload
to session storage so we can upload some files here so this is a example of a data set file which is you know boston
house price data so i'll upload this to my google collaboratory environment so this will upload this file here so
you can use this upload to session storage or you can right click here so there will be this upload option okay so
you can click this to view the file in a preview here so this will give you the preview of the file and this is how you
can upload a file to your google collaboratory so in machine learning we often deal with data sets right so this
is how you can upload a file to your google collab and to start working so there will be another option called as
mount drive so if you give this mount drive your drive will be connected to your google collab and you can access
all the files in your google drive from your google collaboratory so the importance of this is in some cases we
may need to work with data sets that is large so that data sets with size of about 1gb or 2gb or even more than that
so in that cases uploading it to google collaboratory takes a lot of time so in that cases what we do is upload it to
our google drive account and uh we need to mount this drive after that and then we can access the file from google
collaboratory like this so this is how you can access the files from our drive to your google collaborate okay
so the interesting thing and very important thing in google collaborated is that
most of the libraries in python most of the machine learning and data science library in python are already
pre-installed and we don't need to install it separately so you know one or two libraries may be missing and now
i'll show you how you can install libraries in google collab so i'll just make a text here as
installing libraries let's say that we want to you know install pandas library so we know that
pandas library is used in python to make data frames right so if you want to download or if you want to install any
libraries in collab just go to google and search as pandas pypa so pypa means python package installer so you can see
this pandas pypi so this is the command to install the library pandas so you can copy this library
copy this command come to your google collaboratory paste it and you need to precede it with exclamatory mark as this
is a system command so let's run this shift press enter so here you can see your requirement
already satisfied so that means the library is already installed in our google collab environment so some of the
libraries may not be installed so in that cases this is how you can you know install your libraries and
now we can just import our library pandas as import pandas pd so this is how you import your library
and after you have imported it you can load the dataset file to a pandas library so i'll just copy the path so i
just i'm just giving you a demonstration on how you can run python programs so this is an example of you know python
syntax right so i have copied this path now let's load this file to a pandas data frame so i'll name this data frame
as df so df is equal to pd dot read csv
okay so inside this parenthesis in the codes we need to paste the path of our data set file okay
so this pd dot tcs we read csv function will read the csv file and unload it to a pandas data frame here i have uh
imported the pandas library in a short form as pd and now i am using it in a short form so that's why we are
importing it as pd so i'll run this now it will load the data from this csv
file to a data frame so here you can see a data set file is a csv file which means comma separated values now you can
you know print the sample of this data frame using df.get so this dot yet function will print the first five rows
of our data frame so this is how you can run python program so these are all python programs importing pandas and
loading into a data frame etc so let's run some simple uh programs like print we know that print is the key word right
for python so in the coming videos i have explained about several python programs and what are the important data
types and other things that are important for us to know in python for machine learning so let's try to print
something so i'll print machine learning shift plus enter okay so that will print your line so this is how you can use
google collaborating and you know that we have already uploaded this file right let's say that we want to print all the
files that are present in this environment so for that we need to you know type
exclamatory mark ls this will list all the files that are present in our environment so you can see here boston
house dot csv sample data so these are the files and folders we have in our in this files section so
this is how you can print this files so this is a basic introduction on what is google collaborating and how you can run
this in the previous video we have seen how to use google collaboratory for python
programming in this video we are going to discuss about the most basic concepts in python such as constants and
variables data types print function and input functions okay so if you have any doubts on how to use google
collaboratory you can watch the previous video so the index of the that video is 2.1 okay let's get started
so when it comes to machine learning and data science two programming languages are widely used
they are python and our programming language so r is mostly statistical based against python is preferred over r
because python is a general purpose language where we use it in other applications also such as web
development and other cases it also has several ready-made libraries for machine learning and it is also very easy to
understand and easy to use these are the reasons we use python okay now let's try to understand the basic
concepts in python so i have connected my google collaboratory
so first let's discuss about the print function so i'll make a text here
so i will be giving the link for this collab file in the description of this
video so you can download it from there and uh once you complete watching this video
do practice these codes in google collaboratory okay so print function print
so if you are an engineering student in your first year in your c program class you would have came across the function
printf okay so in c program this printf function is used to you know print some text in your screen okay so print some
message on the screen so this print is also similar to that okay so in c program we use the keyword
printf in python we use the keyword print okay so now let's try to print a string
let me print machine learning so now we are going to print the text machine learning okay so as you can note here i
have enclosed this uh two text machine learning in quotes right so you can use either codes
either double quotes or single quotes okay so all the strings in your code should be enclosed in double quotes
strings are nothing but text and sentences okay so either you can use double quotes or
single code but you cannot start with a single quote and end with a double quote like for example you can use single
quote here and a single code here okay so this will print that text in your screen
or you can use double quotes so
this tells our python interpreter that this is a string okay but you cannot use single quote and
endless end it with a double quote this will throw a error as you can see here so we have to use
either single quote or double quote so to run this particular cell you need to press
ctrl plus enter or shift plus enter so shift plus enter will run this cells and automatically goes to the next cell
okay now let's see how we can join two text so print parenthesis
so again we have to put the text in quotes machine learning
plus projects okay so this will concatenate these two terms the case of the machine
learning and projects so concatenates means joining so as you can see here it prints machine learning
projects so this is how you can join several strings in a print function okay so you can note here that i have
given a space here if you just bring this without a space there won't be any space between them okay so that's why i
have made a space here so this is how you can join multiple strings okay now let's try to print some
numbers so i'll just type print parentheses on eight okay so
this will print the number eight so as you can see here i haven't enclosed it in codes because only the
strings need to be enclosed in quotes so this will print that number okay we can also
do some arithmetic operation so if you give print but inside the parenthesis if you give 8 plus 3
so what you will get so as you can see here if we use plus sign between two strings it will
join the two strings but in the case of integers if you put plus so it will add the two numbers okay so it will add the
two numbers and it will uh print the sum of those two numbers okay so these are some basic things we use spring for
apart from this error there will be a lot of places where we need to print something to uh in the screen so
sometimes uh we need to print the entire data in our screen and uh there will be several other cases where
this is very useful okay so these are some basic uses of a print function okay
let me put this in a single section okay so in order to make a section in this text
you just need to precede it with a hash so this will make a section and if you click this down arrow
it will enclose all these cells in this section okay so if you press this again so it will expand it
okay so we have five cells under the text print function
okay now let's discuss about some very basic data types
in python okay basic data types
so the three basic data types in python are integers so we
represent integers as int and floating points so floating points are nothing but
okay floating points are nothing but decimals and we have strings so strings are
represented by str so str represents strings which are nothing but text and sentences okay
so let me clear this cell so now let's try to understand about these
data types so apart from these data types there are also several other data types but these are the most basic ones
so example for integer is you know the numbers like 8 10 or 19 so things the your numbers without any
decimal points okay so let's make a
variable called as okay let's try differently type it okay so here what i have done is
i have used the keyword called as type and i have enclosed the number eight here so what happens is sometimes if you
are not sure about what is the type of the data you can use this type keyword and this will show you what
is the data type so as you can see here it shows int okay now let's try it with a floating point
so as i told you floating point are nothing but decimals so let me put 5.3 here
so it will show float and now let's try with strings so type
so i hope you remember that we need to enclose the strings in double quotes
so let's put english what is this type
so this is called as string okay so these are the most basic data types in python so
apart from this there are also other data types like list sets dictionary etc so we will be uh discussing about that
in a later video so but by now you just need to know about these three basic data types okay
now let's discuss about another topic which are constants and variables
i'll create another section for this data types okay
so we have two sections as print function basic data types now let's discuss about the
constant and variables so as the name suggests variables are something whose values can be changed but we cannot
change the values for constants okay so constant is constants are not much used in python but we have a lot of usages
for variables okay so now let's try to understand more about variables so
let me create a variable name as superhero okay so this is called as a variable and
let's give a name for this superhero variable let me put iron man here
so basically variables are like a container in which we store some value and these values can be changed in case
of variables but we cannot change these values for constants okay so that is the important point to note here as you can
see here here superhero is that container so superhero is that variable and iron1 is the value in that container
okay so now you can try to print this term superhero
so this won't print just superhero in your screen this will print ironman because we have given this value to this
variable okay so this will print ironman so we can use this as our variable name or
you can also use an underscore so if you have multiple words in a variable like you you want to
represent this as let's say marvel superhero marvel
superhero okay so if you run this you will encounter a error because the variables should be a single name or it
should be connected with underscore so let me try to run this
marvel superhero so this will throw a error because it is not a single word right so
if you want to have multiple words consider as a single word you just need to include
underscore between them so marvel underscore so now
you can print this so this will work fine okay so i'll print this
so we got iron man okay so as i told you for variables we can change these values okay now let's try to change that
so marvel superhero so i'm using the same variable name which is equal to now i am
mentioning captain america okay so let me print that print this node so marvel superhero so as you can see
here we can change the value of these variables okay so but in the case of constant we cannot change that
so these are about constants and variables we can also give
the values for multiple variables in a single line of code okay let's try to understand this
let me create variables as so you can also use digits in the variable names so i'm
using 01 but there should not be any gap like this so there should be no gap between them so i am creating 0 1
0 2 0 3 okay so we have three variables here the first variable is 0 1 second
variable is 0 2 and the third variable is 0 3 so we need to enclose the strings in codes
the first era will be iron man second will be let's say captain america
and third include dc superhero
batman okay so what happens here is
this 01 will take the value iron man and hero2 will take the value captain america and 03 will take the value
batman okay now let's try to print this print 01
and 0 2 and print
okay so as you can see here i am not using codes here because these are not strings these are variables we just need
to uh put codes for strings and not for variables so let me print this now as you can see here the hero one is iron
man and the name for hero2 which is a variable is captain america and hero 3 is batman okay so here you can just
include a space before or after after this come up or you can just leave it as such so there
is not any much differences in python so in some programming languages you would uh encounter some error but
python doesn't give errors for much spaces okay so if you run this code it will also give us uh the correct output
and we won't get any errors for this spaces okay now let's try to see
how we can give multiple variables the same data let's say for example let's take these variables
x is equal to y is equal to 0. so it is not that the variable should be a word it can also be let us okay so here we
are taking three letters x y and z x y and z is equal to let's say 23 and i'm going to print
all of them so print x print y and print
is it okay so this line will give the value 23 to x y
and z now we will get all this as 23 okay so this is how you
can give a single value to multiple variables and another important point to note here is you cannot just give a
capital x here and try to print a small x here okay so python is k sensitive and you have to use the same uh
you know either caps or small letters okay so python is case sensitive and that is
one of the important point okay so these are some basic things about
variables and constants now let's try to understand another function which is input
okay input function now
so in the previous code we have discussed about the print function okay
and now we are going to discuss about input function so what is this input function so
in c program you would have came across the function called as scanf okay so print is a an output command where
something you know some we get some output out of it and input is our scanf is an input
command where the user will give an input to it okay so let me try to explain it to you with an example so i'm
creating a variable called as number one so number one is equal to input so i'm using the keyword input
here so input so you need to open a parenthesis and let's say enter the first number
okay and let's say number two
is equal to input enter the second number
so what happens is this will ask the user for their input so
now we need to give the input to this command let's say i'm giving a number 23 so i'm pressing enter now we need to
give the second number let me also give it as 23 okay so
if you're aware of or if you have practiced c programs so you would have came across that scanf function and it
is very much similar to this input function okay so we use this input function where we need
to get some data or some value from the user okay so this is why input function is used now let's try to do some more
things now what we are going to do is we are going to get two numbers from the user
and we are going to add the two numbers and we are going to print the sum of those two numbers so i am creating
another variable called as sum so sum is equal to number one
plus number two okay so what happens here is so this will get two numbers from the
user and it will get the sum of these two numbers and now we need to print this sum
so print sum so what do you expect the output of the
code would be okay so if i'm giving the two numbers as 23 and 23 so the sum of these two numbers is 46 right but we
won't get it we won't get 43 as the 46 as the answer okay let's see let me give 23 as the first number
23 as a second number so we expect that these two numbers should be added and the output should be 46 but it won't be
the case as you can see here it is not the expected value so we get 2
3 2 3 as our output why is this case okay so this is one interesting thing to note here so what happens is
so when you use the input function it assumes that this value given by the user is a string okay it doesn't know
whether it is an in integer value or float value okay it just assumes that it is a string that is why
it uh let's say for example when we give 23 as the value it thinks that 23 is a string and the 23 is also a string and
it just try to concatenate the two two strings as we have seen in the print here so plus will join the two strings
so that's why it has joined these two numbers which is you
know strings for the for that program and it will print that number okay so we get two three two three
now how we can rectify this you can include in tier okay
so hint and another parenthesis and so this will
convert this string value to an integer now let's try to run this
i'm giving 23 again and 23 now as you can see here the output is 46
now so the important point to note here is so the input function will assume that the
value is a string and we need to convert this value to what it is actually okay so here we are expecting the value to be
integer so i am using this integer value so you can change the data type by using this uh method okay let's say for
example changing the data type in python
okay let me show you how you can change these data types
let's say that num is equal to 5
okay um now let's try to print the type of this
num so this will output that it is
an integer so as you can see here now what you can do is you can change this integer to a float
by mentioning that keyword and giving that variable name inside this
parenthesis so what happens is the value of num is 5 and this will create this 5 which is an integer value to a float
value okay and now let's try to print this number okay let me include that in the print
function itself as you can see here this integer 5 is converted to a float value 5.0 so this
is how you can change the data types in python and it is the same thing i have used here so i am converting a string to
a integer okay so these are some very basic things you need to know in python okay so let's do a fast recap now so
first of all we have uh seen some basic functions in print okay so how we can print strings so we have
seen that we need to include the strings in double quotes or single quotes so we have seen how we can join two strings
and how to print numbers and sum of two numbers inside the print function so and then we have
seen some basic data types of python which are integer float and string okay so then we have seen how to
find the data type of a value so we need to mention the keyword type here okay then we have discussed about constant
and variables so we have seen that we can change the value of a variable and we have seen how to
give multiple values for multiple variables and how to give the same value for multiple variables then we have
discussed about the input function which is used to get input from a user okay then we have discussed how we can change
the data type of a value okay so i'll give this collab file link in the description of the video in the next
video we will be discussing more basics of python like data types operators and other python and the second module of
this course is python basics for machine learning and this is the third video in this second module so let's get started
with today's video so i'll be doing my python programs in google collaboratory i have already made
a video on how you can access google collaboratory so you can check that out so let's get started so these are the
five data types in python okay so they are integer floating point complex boolean and string so these are the
basic data types we know that integer is a real number right so integer are numerical values and floating points are
decimal numbers and we know that complex number is something that has both real number and an imaginary number and
boolean is nothing but true or false values so it contains only two type of values one is true and the other one is
false and string is nothing but text or statements okay so these are the five basic data types in python apart from
these basic data types we have other complex data types such as list tuples etc so we will discuss about
that in a later video so these are the basic ones so let's get started and let's try to understand each of these
basic data types first let's discuss about integers so in python you can write comments
using you know this ash symbol okay so i'll make a comment here as integers okay
so integers i'm going to create a variable as a okay so in the previous video
with index 2.2 i have explained what is meant by variables so we are just declaring a variable here as c8 and a is
equal to 8 and now let's try to print the cl we know
that 8 is a integer right so let's print a so in order to run the cell you can
press shift plus enter so it will execute the cell and go to the next one so you can see here we have printed a
and it has printed eight because we have given the value for a as eight we know that eight is an integer right so let us
say that in some cases you are not sure what is the data type of a particular variable in that case you can use the
keyword type okay so type is a keyword in python which tells you the data type of a particular value here let's mention
a in this parenthesis so this will return uh what is the data type of va okay so
let's run this press shift plus enter okay here you can see here int which means in change represents integer
values right so this is how you can print integers values so you can give an integer value to a variable and you can
print it now let's discuss about floating points so i'll make comment here as floating point
and let's take the variable as b and let's give a value like 2.3 so we know that 2.3 is a decimal value so we know
that floating points are nothing but decimal values and now let's try to print this b
and let's also try to find the data type of b so type b okay so let's run this
so you can see here 2.3 so we have printer b whose value is 2.3 and we have found the data type of b as float okay
so short form for integer is in and for floating point its float now let us discuss about the third data type which
is complex numbers so complex numbers so we know that complex numbers has both
a real term and imaginary term so let's name this variable as c and i'll give a complex number as 1 plus
3 j here uh one is the real term and j is the imaginary term so j square will be equal to minus 1 so that is meant by
complex number where you know we can also use i so i or j is you know square of this j is equal to minus 1
that is the imaginary path and you can print c okay so let's also try to print the
data type of c okay so this prints the complex number which is one plus three j and also it
prints the data type of c which is complex so these are the first three basic data types in python as we have
discussed about these three data types there is another interesting thing that we can do we can convert one data type
to another okay so i'll mention a text here as conversion
of one data type to another so here i'm going to convert
two data types so let's try to convert an integer into a floating point and let's convert a floating point into one
integer so this will be integer to float
so let's name the variable as okay so i'll give some other variable name which is x so let's say that x is equal to 10
and let's try to print x first and let's also try to print the type of x the data type of x so i'll run this
okay so you can see here we have printed x the value of x is 10 and it is an
integer now let's try to convert this to a floating point so let's name this variable as y
and to convert integer into a floating point we need to mention the keyword float
and inside this parenthesis mention the term which you want to convert here x is an integer right and let's convert this
x into a floating point so you need to put x in this parenthesis so this will convert
okay one second so this will convert x to a floating point value and that floating point will
be value will be stored to y and let's try to print both y and the data type of y
so type y here you can see here now we get the
value as 10.0 so we know that 10 is an integer and 10.0 is a floating point or decimal value and we have successfully
converted this integer value using this keyword float and we have tried to you know print the data type of y and it
has printed float so this is how you can convert an integer to a floating point value now let's see how we can convert
a floating point value to integer okay so float to in and
uh i'll take the variable as x is x in this case let's give some random floating point value 5.88
and let's print x and also the data type of x so type
ex so the value of x is 5.88 and the data type is float now let's see how we can
convert this so y is equal to so previously we have used this keyword float right in this case we are going to
use the keyword in which will convert the value to an integer value so now mention x in this parenthesis okay so x
and once we have converted it let's try to print y
and also the data type of y so we can see here this 5.8 decimal value is now converted to an integer
value which is 5 and we have found the data type as integer so there is one main thing which you need to take note
of in in this case so when you convert this uh floating point into into an integer value it doesn't round the value
it doesn't convert this 5.88 to 6 it just removes you know this decimal values and it will give only this
integer value so this 5.88 won't be converted into six but this you know this 0.88 will be removed
and we will get only five okay so this is what happens when you convert a floating point to an integer
now uh we have the fourth data type which is boolean right so here i just mention a text as boolean
so as i have told you earlier boolean has two values one is true and the second one is false so i'll mention it
here true and false okay
now let's create the variable as ca and let's put a is equal to true so this is a boolean value okay so there
is another main thing here so this t should be in uppercase letters so it shouldn't be in lowercase letters so
this will give us an error so this is a predefined value so it should be you know as such it is in this case so the t
should be in upper case letter and let's try to print this a now so print
a and let's try to print the data type of a as well so type of a
sorry so type of a so this is printed as true and we got the data type as b so bolt represents a boolean okay so let's
create another variable as b and b is equal to false and
let's print b now also the data type of b
so you can see here so this is how you can uh you know assign a boolean value to a variable and you can print it and
find the data type of it and the final thing which we have is string right so
before that let's discuss one more thing about boolean so let's see where we can use these booleans so i'll create a
variable as ca and let's say that a is equal to 8 is you know let's say that 7 is
less than 3 so we are just you know checking whether 7 is less than 3 so you know that 7 is
not less than 3 so this is this statement is actually a false one right so this will return a boolean value when
you just compare two values so here we are checking whether it is less than 3 so we are checking whether 7 is less
than 3 when you run these kind of codes it will return a boolean value now you can try to print
a okay so let's also try to print the data type of a
okay sorry so p shouldn't be in uppercase letter
okay so you can see here 7 is not less than 3 so it will give a boolean value which is false and
we have tried to print print the value of a which is false and we have also tried to find the data type of a so
similarly i'll just copy this and let's change this symbol okay
so let's say that 7 is greater than 3 and this condition is true right so let's call
this as a condition so let's check whether this condition is true of course 7 is greater than 3 so this will return
the value as true so let's see so yes so true and it is a boolean value so we use these kind of uh
you know conditions in loops and in the case of if statements etc so in that cases uh we will get a boolean value so
this is one main application of boolean data type and the final data type which we are going to discuss is string
so strings are nothing but text and statements uh you know and let's try to print some statements
so i'll print machine learning okay so machine learning is a string so these
two words represents a string and let's try to print this so this will print you this string
the main thing about the string is the strings should be enclosed in ports okay so here i have used double quotes right
so instead you can also use single quotes so i'll just copy and paste this here
and replace this double quotes with a single quote and i'll run this this will give you the
same result okay so the main thing here is if you start with single quote it should in in you know single quotes as
well if you start in double quotes it should end in double quotes as well so the code shouldn't change but you can
use either double quotes or single quotes so let's discuss some basic operations in strings that we can use
so i'll give a variable name here as my string okay so let's say that my string is equal to
so as i have told you earlier strings should always be enclosed in codes whereas we don't have to enclose you
know values this integer values and floating point values in quotes so only the
strings should be enclosed in codes and here boolean is a different data type hence we do not enclose it in ports only
the strings should be enclosed in ports either single quotes or double quotes and i'll give the values the same
machine learning and i'll print this my string here we have
created the variable as my string and i am printing it
let's try to find the data type using the type keyword this type function so my stream
so let's run this now you can see here our string which is machine learning has been printed and we
found the data type of string so str represents string and let's try another thing
print hello and
okay so i'm using this symbol here this uh you know star symbol let's see what
happens we know that this represents multiplication symbol in python right so when you use this line of code and let's
try to print this what happens here is your uh string will be printed five times if you
mention five so if you mention four your string will be repeated four times so this is uh how you can replicate your
string using this line okay so now let's see how we can slice a string this process is called as
slicing i'll just make a text here as slicing okay
let's create a new string as let's name this variable as my string
and let's give the value as programming so this word programming has totally 11
letters okay and i'm going to slice this string slice means getting you know only a particular
portion of this string this particular word so let's print
my string but i don't want to print the entire thing i just want to print a part of this word
and you can mention the values such as 1 s 2 5 okay so let's understand indexing in python
so indexing or the numbering in python starts with 0. so the index of this first letter p is 0
and the index of the second letter r is 1 and 2 and so on so p will be 0 r will be 1 0 0 will be 2 and so on so 0 1 2 3
4 and it goes on and we can mention the letters based on their index so 1 means the second letter r right because the
indexing starts with 0 and 1 represents this second letter which is r and i want to print all the words from the first
index are to the fifth index five let's see which is the fifth index so p is the zeroth one so r o g r a
so uh zero one two three four and five so here is the index five so when you use uh this particular line 1s to 5
the values from this first index one will be printed all the way to this fifth index
but this fifth letter won't be printed this fifth index value which is va won't be printed so let's run this
and try to understand this okay so we got the values as rogr so this first index value will be printed which is r
and this second index value phi won't be printer so you will get the values from r o g r so this second
index value will be uh you know neglected so this is how you can slice a string so the main thing to note here is
the first value up to the last value minus one so here the value should be printed so i will
just make a note here so the values from index
1 to 5 minus 1 so 5 minus 1 is 4 right so
will be sliced will be sliced so in every indexing cases so this second index won't be
included so that is what you need to take note of in this case and there is another process called as step so we can
also you know slice the words having a step value here let's print
my string and my string and mention 0 to
10 let's take a step past 2 so i'm going to print from a 0 so the 0th index is p right all the way up to 10th index so
10th index is this end so 10 to get you know 10th index is n and sorry 1 second
so this is a 0 1 2 3 4 5 6 7 8 19 so 10th index is g let's try to print this step so what happens when you mention 2
here is so p will be printed and r will be you know removed o will be printed g will be removed so that means
you know step of two that means every second letter will be skipped let's try to run this
okay so here you can see here the tenth index value is cn so as i have mentioned you here that the second index
value won't be involved or it won't be included in this uh
slicing so we will get the value from this zero index to the index nine and every second letter will be removed here
uh when you take p as the 0th index the second letter r will be removed and we will get og will be removed and r will
be printed and a will be removed and so on so this is how you can slice a string by mentioning the step which we want
okay so there is another uh thing which you can do with string called as string concatenation
string concatenation so
concatenating is nothing but joining two strings so let's uh name this variable as word1
so let's give the value as word1 is equal to
machine so i'm mentioning single quotes here and let's take the second value as word
two so word two is equal to learning okay now
i'm going to create another word so let's let's print this so print
word one plus word two
so when you use this plus symbol so these two words will be joined so this process
is called as string concatenation so you can see here there is no space here right so uh
you cannot get a space with you know when you mention this plus so if you want to have a space you can just
mention a space here and let's run this so this will give a space between them so this is how you can concatenate or
join two strings so these are some basic details of the data types in python and basic operations on the data types that
we can do so i'll just give you a quick recap on what are the things we have done here so we have discussed the first
you know the five basic data types in python which are integer floating point complex
boolean and string we have tried to print uh we try to give uh you know give a value of integer to a variable a and
we printed it and we have also tried to find the data type of a and then we have tried the same with a floating point
value and we have also tried to create a complex number and then we have seen how we can convert one data type to another
using their respective keyword so in this case we have used this float keyword to convert an integer value to
float here we have used you know integer keyword to convert a floating point value to an integer and we have
discussed about the two boolean values which are true and false and we have seen how we can use these boolean values
in the case of conditions and then we have discussed about strings and how you can
replicate the strings and how you can slice the string by mentioning their indexes and now you can slice a string
by mentioning a step value and finally we have seen how you can uh you know concatenate two string so these are some
basic details about the data types in python hello everyone this is siddhartham in
the previous video we have discussed about the basic data types in python which included integer floating points
string boolean and complex numbers so in this video we are going to discuss the remaining special data types in python
okay so these data types include list tuple set and dictionary okay so basically there are two types of objects
in python so immutable objects and mutable objects immutable objects are those whose value cannot be changed once
it's created and mutable objects are those whose value can be changed once it's created okay
and the examples of immutable objects are integers floating points strings boolean
values and tuples okay and mutable objects are list set and dictionary okay so in this video we are going to discuss
about these four data types which are list double set and dictionary okay so first of all let's discuss about list
okay so list should be enclosed in
square bracket so i'll mention it in the comment here so list
okay so list should be included in the square bracket okay so list are nothing but they are like arrays in c program so
they can store multiple values okay so all these data types which are going to see today uh can store multiple values
whereas the previous uh you know data types we have seen which are integer float and strings can store only one
value okay so these list set and dictionary can store multiple values okay so i'll create a list and name it
as my list so my list is equal to
so we need to put all the components in the square bracket so let's say one two three four and five so this is my list
and let me print this so print my list okay
now i'll also check the data type of this so if you are not sure about what is a
particular data type you can use the keyword type and you need to mention the variable which you want to find okay so
i'll put my list here so this will return the data type of this particular variable
okay so as you can see here our list is printed in square bracket and so we have checked the data type of my list and it
is written that it is a list data type okay so this is how you can check the data type and now let's discuss about
some important properties and operations that can be carried out on list okay so list scan so let's stick and store
multiple data types so here we have only integer values right so similarly it's not the case that only integers or only
floating points should be present in a list so we can have integer values floating point values strings and
boolean in a single list okay so i'll mention this list can have
multiple data types okay whereas some of the data types such as
set does not allow this okay so they can have only one type of data okay so
my list is equal to let me put 2
3 so 2 and 3 are integers so let me put a floating point now let's say 1.8
and let's now include a stream let's say english so english is a word so it is a string value
so and it's also include a boolean value true okay so we have multiple data types
here now let me print my list okay
so as you can see here we have different data types and list and multiple data types are supported in a single list
okay now as i have told you earlier that list are mutable okay
so list are mutable so mutable means they can be changed
once they are created okay so they are changeable okay
so now let's see how we can add elements to a list so add the elements to a list okay
so first of all let's copy this list here okay
my list so i'll copy this okay so you can use the function append
to add a add an element into a list okay so let me mention my list
okay so dot append is the function that is used to add any element so let's say that we want to add 6 to our list okay
so this will add the element six at the end of our list okay now let's print our list so print my list
okay as you can see here in our original list a new value is added which is six so
that is why we are using the function dot append okay so each of these elements has a particular
index in the list okay so as i have told you earlier in the previous video that indexing in python starts from zero so
the index of this first element is zero and the index of this second element is one and third is two and it goes on okay
so you can print the several elements in a list using their index okay so now we are going to
see how we can print elements
of a list using their index okay
so let's print this so print mention my list and you need to specify the index in
square brackets okay so so when i mention the index as 0 it will print the first element which is 2 okay
now let's print the third element the third element is 1.8 right so
my list the index of 1.8 is 0 1 2 okay now let's print and see this
as you can see here it can print the individual elements once we mention the index okay so this is how you can call
the specific elements in a list using their index okay so another important property of list is that it allows
duplicate values so just allow
duplicate or repeated values whereas sit does not allow duplicate values so in the case of set it removes
a duplicate or repeated values so we'll be seeing that when we are discussing about set okay so here let's create a
list as list one let's say list one is equal to so we
want to put the elements in square brackets say one two three four five and again one two
and let's see two and three let me print this
print list one okay i'll run this as you can see here it allows the duplicate value
so here we have the duplicate values as two one three okay so it is one main properties of list okay
now we can check the number of elements in a list using one function okay so let's
check how many numbers are there so totally one two three four five six seven so totally we have eight numbers
in this list okay so you can check the size of the list here so using the function length okay so
the short form for length is l e and len and inside the bracket inside the parenthesis mention
the list name so list one so this will count the number of elements present inside the list one okay so i'll print
this so as you can see here it has printed the number of elements present in the in
this list which is eight okay now let's see how we can initiate an empty
list initiating an empty list
so let's say that list 2 is equal to
square bracket so you need to mention the opening square bracket and the ending square bracket so this is nothing
but an empty list so we can print this empty list as you can see here it is a list but it
does not contain any values and you can add values to this using the function
list2 dot append which we have seen already let's say we append the value 5 to it okay
so now let's print this print list2 so this is how you can create an empty list and add a value to
it so this feature is very important because in lot of cases we will create an empty list and we add values one by
one okay so this is how you can initiate a list so as i have told you earlier lists are
mutable right they are changeable so hence we can
delete the element present in a list okay so delete an item in a list but we cannot do that in the
case of tuples and other immutable data types okay let's say that
list 2 is equal to let's copy the elements from this list okay
we'll copy these elements okay and i'll put it in this list and let me print
this list so print list two
okay now you can delete the elements present in a list using the function delete so d
e l okay so mention the list name and mention the index number which you want to delete so let's say that i want to
delete this 1.8 the index of 1.8 is 2 so index of 2 is 0 this is 1 and two so it is in the normal numerical order instead
it starts with zero okay so that's in about index so index of one point eight is two okay so list and mention the
index in the square brackets say two and now let's print our new list so list2 so this basically prints the
list without deleting any item in this line and then we will delete the third item using the index 2 and then we will
print the deleter list okay so i'll run this so as you can see here the third element
which has the index of two is deleted from this list so this is how you can delete items in a list
and then one more interesting feature about the list is you can join to list
okay so let me create the list as list three which is equal to
one two three four five okay and i'll create another list as
list four which is equal to 6 7
8 9 and 10 okay now we can
join these two list okay so i'll create another list as list 5 and list 5 is equal to
list 3 plus just 4.
so the important point to note here is when i add these two list it won't add these elements element wise okay so it
will join the two list so it will concatenate the two list so let's print this list five
as you can see here the list three and list four are joined together and they are stored in the list phase so this is
how you can join to list okay so these are some important features and properties of list okay now let's
discuss about tuple so tuple are similar as list
except the fact that they are immutable objects so once you create an element in a tuples
you cannot change it hence it is called as an immutable data type okay so let's create a tuple as
double one so tuples should be enclosed in parenthesis
or round brackets okay so let's put the elements as two three four and five okay whereas the list should be enclosed in
square brackets so let me print my tuple so print tuple one and let's check the data type
also as you know using the function type of tuple one so this will
print the data type of this variable tuple one okay as you can see here the tuples are
always enclosed in around brackets or parentheses and this type function has printed our data type as temple okay now
let's discuss some properties of tupper so likewise so you know similar to list tuples also allow multiple data types in
a single tuple so you can have integers floating points strings etcetera in a single tuple okay
so double allows multiple
data types in a single tuple okay so let's create the tuple as tuple 2 which is equal to again
parenthesis let's say one two three point five
let's include a string as machine learning and another boolean as false so boolean
data types are nothing but true and false values so let's try to print this tuple 2 so it runs properly because it
can allows multiple data types integers floating points um
strings etc okay now let's see how we can convert a list into a tuple okay
so converting a list to a tuple
so first of all let's create our list as my list and let's say my list as the elements so
this should be enclosed in the square brackets let's say it's three four five and six okay now we need
to convert this to a tuple before that let me print this list so print my list
okay so now let me create another variable called as my tuple okay so my tuple is equal to so for
converting a list to a double or other data types to a tuple you need to use the keyword tuple okay so tuple in the
parenthesis mention this listener name so the list name is my list writes file paste it here so this will
convert this my list to a tuple and store it to this variable my double so now let's print this my tuple
print my tuple okay so as you can see here it has printed
our list first and this list is converted to double so you can distinguish it using its square brackets
okay so this is how you can convert a different data type to a tuple so similarly
we have printed the individual elements in a list by using by mentioning their
index value right so you can see here so we have mentioned the index value to print the elements of our list
so similarly you can use indexing to print the elements of list as well sorry a tuple as well let's say we want to
print my tuple the first element of my tuple so we will
give the index 0 now let's print
my tuple and now let's mention the index one so this will
sorry index one this will print the first two elements which are three and four okay
as you can see here this is how you can call specific elements using their index values okay so
as i have earlier told you tuples are immutable tuples are
immutable which means unchangeable so once they are created their elements cannot be changed so we
can try this so in the case of list we have used the function dot append to append or join a value to
a list but we cannot do that in the case of tuple let's say that my tuple
dot append 6
so this will throw us an error because triple values cannot be changed
okay so as you can see here so tuple object has no attribute happen so we cannot change the elements of the
tuple using this append or any function because they are immutable okay now we can also find the number of
elements present in the tuple using the same function length so let's print
my double length of my tuple okay so as you can see here this my tuple has
four elements so this is how you can print the number of elements using the keyword length okay so this is about the
important properties of table now let's discuss about another important data type set
so set are also mutable data types and so we have seen that the list elements should be enclosed in square bracket
double elements should be enclosed in parenthesis around brackets and set should be enclosed in
curly brackets okay curly brackets
so let me create the set as my set which is equal to so put the elements in a curly brackets
let's say 1 2 3 4 and five and i'll
print my set and let's check the data type as well
so type my set so as you can see here the elements are
printed in the curly brackets and we can found we can sorry we can find the elements and and we can find the data
type of the set and it is printed here using the keyword type okay now we cannot call an element present in the
set using their index so we have seen in the case of list and tuple we can you know print specific elements using their
index but set does not support indexing so let's try this let's say that we want to print
the first element of my set so i'll mention zero so if i run this we will get an error because
set does not support indexing so as you can see here set object does not support indexing so you
don't have any index value associated to the elements of set so this is one main feature of set because uh this is what
distinguishes between list table and set okay now
you can convert a list through sorry list into a set let's see how we can do that so convert
list to a set let's say that let's create a list as
list 5 which is equal to so list should be
included in square bracket let's say 4 5 6 7 and so these are the elements of
the list now i need to convert this to a
set so what i'll be doing is i'll create the set and store it in the variable x
okay so x so you can use the keyword set to convert one data type to a set okay so now we are going to convert this list
5 into a set so mention the list 5 here so list 5
okay now let me print this x so what happens here is so we have a list here and this list will be converted into a
set using this set function and it will be stored in the variable x and now we are going to print this
variable x as you can see here we got a set because we have curly brackets and in the list we have square bracket so
this is how you can convert list or tuple into a set okay so and one important feature of set when compared
to list and tuple is that set does not allow duplicate values whereas list and double do allow duplicate values or
repeated values in it whereas set does not allow
duplicate values okay so let's check this and say that set 3 is equal to
so i'll mention the elements in curly brackets 1 2 3 4 5 and again let me put 1
2 and 3 now let's print this so what happens is the repeated values
automatically gets deleted okay so as you can see here the repeated values 1 2 3 are not printed because set
does not allow any repeated values so this is about some important features of it and now we are going to discuss about
the last data type which is dictionary okay so dictionary are special data types because they are quite different
from the other data types list tuple and set okay so the peculiarity of dictionary is that
it contains a key value pair so dictionaries have a key value path so
each element has a key in it and a value associated with that key let's see always that so let me
create the dictionary as my dictionary okay so my dictionary is equal to so dictionary values are also including
curly brackets so first let's create the key as name okay so this is the first key
and you need to put a column there and let's say that the name of the person is david
okay so david now this is the first element so this key so name is the key and david is the
element okay so this is the first element now let's create another element as
h okay so let's say h so age is the second key
and age of david is 30 so this is the second element and now let's create the third element as country
entry of david so again colon let's put india okay so this set this dictionary has three
elements so each element has a key in it and a value associated to it so in this third element country is the key and
value is india okay so let's try to print my dictionary
okay and also let's check the data type of this so put type
and my dictionary okay
as you can see here we have printed our elements in the dictionary and the elements are enclosed in curly brackets
and we have got this data type as dictionary okay now
so in the case of list and tuple we have seen that we can call specific elements in a list or tuple using their index but
in the case of dictionary we can call this value using their respective key so we can call a value using their key so
if i want to print this david i need to mention the key which is name if i want to main sorry print the age i need to
mention age and if i want to you know print india i need to mention the country so let's see
how we can do it let's say print my dictionary
and in the square brackets you can close which you want to print so first i want to print the name
and now let's print the edge
and lastly let's print country okay okay so this will print their respective
values so as you can see here this is how you can call the values inside the dictionary using their keys okay so in
lot of the cases dictionaries are very useful for us okay so and another important properties of dictionary is
that dictionaries does not allow duplicate values so list and tuple allows duplicate values whereas set and
dictionary sorry list and double allows and second dictionary does not allow duplicate values or repeated values so
does not allow duplicate values so
let me create a dictionary as dictionary 2 which is equal to so i'll copy this
key and value okay so
i'll paste it here in the dictionary too and i'll again paste this so you can see here we have repeated
values so we have duplicate values now let's try to print this dictionary tool and see what happens
as you can see here the duplicate values are removed so hence set and dictionary does not allow duplicate or repeated
values so that is all about the special data types in python list tuple set and dictionary so the
difference between the other basic data types is that these data types can store multiple values in them okay so these
data types are very similar to arrays in c programming okay so python do check out my previous videos so in this video
we are going to discuss about one of the main topics in python which is operators so basically there are six operators in
python they are arithmetic operators assignment operators comparison operators logical operators identity
operators and membership operators okay so now let's discuss about each one of these separately okay so first of all
arithmetic operators okay so
so arithmetic operators are the basic mathematical operations that we can perform on integers and floating points
and other data types okay so [Music] let's discuss about this so this is one
of the most basic operators so let's create a variable as number one okay so num1 is equal to let's say 20 and let's
create another number so the second variable is number two which is 10 so we have two
numbers the first number the value of first number is 20 and the second number is 10 right so now let's see what are
the different arithmetic operators so first is the addition operators okay so addition operator is nothing but the
addition symbol so let's say create a variable called the sum and let's add the two numbers
number one plus number two okay so this plus sign we are using right so this is
called as the addition operators okay so similarly there are other operators in arithmetic type okay
so you can leave space here or you can remove the space here so both are the same so it is
not a significant point so you can do both the ways so first is the addition operator so let me print the sum
okay so let's say that sum is equal to
okay so this will print the sum of the numbers okay so this is the addition operators which is plus sign and there
is subtraction operator so these are nothing but the basic math operations okay so let's create a
variable stiff which represents difference so number one minus number two so this minus symbol is
the subtraction operators okay so print difference
so this will find the difference of the two numbers and it will print it here so difference
is given by tl okay so the third arithmetic operators was
product or multiplication so multiplication operators let's say that pros of pro means product
so product is equal to number one so
so i'll just write the code with the space you can write with space or without space so
this symbol represents multiplication operator okay so let me print it so print
product so product is equal
to okay the fourth operator is division of course
okay so division so let's write quo but which represents
quotient so number one for division we use this forward slash
okay so number one and number two and let's print the quotient
q u t okay so quotient and here we need to print it
okay so apart from these basic four operators there are also other arithmetic operators so they are
exponent so how we can represent exponential let's create a variable as exp which
represents exponent so we want to let's say that we want to find the exponent as 20 power 10 okay so you can
write that as number one you need to mention this multiplication operator space it means number one to the power
of number two okay so you can do this or you just can't remove the space between
them okay so this will so this is similar to you know
um 20 power 10 so it is similar to it okay
now let's print the exponent okay so the exponent is
equal to exp okay
so then there is this modulus operation okay so let's create the variable smart
which is equal to number one so this modulus operator is represented by the percentage symbol so
num2 so this basically gives the remainder of this division so what happens here is so the this number
two will be divided by number sorry number one will be divided by number two and instead of printing the quotient so
the reminder will be printed okay so if you want to print the question we use the forward slash so if we want to print
the reminder we use this percentage symbol okay so
let me print reminder is equal to
so let's print this so these are the basic arithmetic operators in python okay so sum which represents the
addition operators and then we have seen the subtraction operators multiplication operator division operator exponential
operators and modulus operator okay so these are the arithmetic operators so the second operators which we need to
discuss is assignment operator okay so let's discuss about it now so this is
assignment operators so assignment operators as the name suggests it's assigning values to a
variable okay so let's say there is a variable a and the value of this variable is 5 so i am
basically assigning the value 5 for this variable here equal to sign is the assignment operators okay so let's
print the say of course it prints five okay so there are other assignment operators as well let's say that
again a is equal to 5 and a yes plus is equal to 5 so basically
what this means is so this is similar to telling our python interpreter that a is equal
to a plus 5 so instead of writing a plus b so we can write a plus is equal to 5 so
this will add 5 to this a okay so if we print a now it will give us 10 because a is
already 5 and we are adding 5 to it okay so let me print this and we have 10 okay
so similarly there are also other things we can do with it so is equal to let's say 2
okay so this is similar to v is equal to b minus 2 okay
so let's print first of all we need to mention b right so let's say that b is equal to 5
and print b okay so these are some interesting assignment operators so we have seen two
assignment operators there are other assignment operators as well so let me mention them
in this text here okay so they are so the first one as we have seen h plus is equal to
and next we have seen this and the next operators you can do it with the multiplication symbol
so you can try all these with different variables okay so it is similar to all these things
and i'll just mention it here so you do practice this so another one is the exponent okay and then we also have this
for division and for modulus okay
okay so okay
so i have just shown you two basic uh assignment operators so you can
practice all these assignment operators okay so now we have discussed about arithmetic and assignment operators now
let's discuss about the comparison operators okay so comparator operators basically compares two variables or two
objects okay so three is comparison operators
okay so let me create a variable is equal to 5
and b is equal to let's say 10 okay so we need to compare these two variables let's see what are
the symbols used to compare the two variables or two objects okay so let's print this comparation
operators returns a boolean value so boolean means it outputs either true or false okay so
these two things are only we are expecting so it won't print any function but sorry it won't print any values but
it will print this boolean values which are either true or false so let's say that
a is equal to 5 so i have mentioned 2 equal to symbol this means
it will check sorry so a is equal to b so when i mention this equal to equal to 2 equal to signs it checks whether a is
same as b okay so this is nothing but equal to comparison operator
okay now let me do another thing so here
so i'm mentioning exclamatory mark and equal to so this means a is not equal to b so let's say that in the first case it
will check whether a is this a is same as b so it is not same so it will output the value as false and
now here we have we are checking whether a is not equal to b so a is not equal to b hence it will output
false okay so this is nothing but not equal to
print is greater than b okay so
here a is less than b so it will output false for it so this is greater than symbol of course
so this is greater than symbol so similarly we have other symbols right so other
common symbols which is less than b so all these conditions will be compiled and there is another
two comparison operators which is less than or equal to b and
is greater than or equal to b okay so i'll run this so this will output
either true or false so this condition will be checked and the output will be printed so first condition checks
whether a is equal to b so is not equal to b hence we are getting false and now we are checking whether a is not equal
to b so it is the correct uh condition so it gives true so similarly all these conditions will be checked so these are
the comparison operators so these symbols between a and b okay now
we are going to discuss about the fourth operator which is logical operators so i'll mention it here
so the fourth operator is logical operators
so there are three logical operators they are and are
and not so they are similar to the logic gates which we would have studied in the year secondary so let's say that a is
equal to 10 okay so
this logical operator also gives i gives boolean values so it will print either true or false and it won't give any
values so numerical values okay so here we have given that a is equal to k so let's
say that print let's say a is greater than 20
okay and a is
greater than five so we have two conditions here and we have used uh logic logical operator and so what
happened here is so these two conditions will be checked it will check whether a is greater than 20 so a is equal to 10
which is this condition is false because a is not greater than 20 it is less than 27 next
this condition will be checked which is a is greater than 5 of course a is greater than 5 so out of these two
conditions only one condition the second condition is correct and the first condition is wrong so if we use the and
operator it will give the output as true if both the
conditions are true okay so in this case only one condition is true
we will get false as the output okay now i'll use or operator okay so i'm just
copying the same thing but i'm just replacing this and with
r okay so this r operators similarly check the two condition it will output the value as true if either one of it is
true so it's it's obvious from its name so and which is the both of them should be true or means either one can be true
and there is another operator called as not operator so it is similar to the not gate
so it will inverse the values okay so let's say that
a is greater than 8 so it is true and a is
greater than 5 so both these conditions are true right so but this not operator
will convert this or it will invert this output okay so if this
gives an output of true when it goes to this not operator it will be converted to false so let's run this
so as you can see here we have used and operator so only one condition is true strange we will get a false so in second
condition also same the two only one condition is true but we are using an or operator so we will get a true and this
condition outputs are true but we are using a not so it will be inverted to false so these are the three main
logical operators so and are and not okay so the fifth operator is identity operator
so fifth one is identity operator okay
the identity operator are this and this node okay so it again compares the
value and gives a boolean output let's say that x is equal to 5 and y is equal to
5 so both are same right so it will compare this sprint
so the operator is nothing but is right so x is y so it will check whether x is the same as y and it will give either
true or false so it is printing true because both of them are same right if i
just do the same thing and give different value to 10 so this will give us an output of false because
both of them are not same right so false so this is the identity operator
is so we can do the same thing but this time with is not function so the second identity operator is not so
you can do that so this is basically opposite to this is operator okay so x is not y
it is false because x is the same as y right so again i'll do the same but in this case and change this value here
of course x is not y so it will give us the boolean value as true okay so it will check whether both of them are same
when we are using the operator risk and here it will check whether the two values are not similar okay so this is
nothing but the identity operator so the finally we have this membership operator okay so membership operator checks
whether a particular value belongs to a sequence of elements like list so i'll explain you this in a moment
fix this membership operator okay
so there are two membership operators in and not in
okay so i'll put a is equal to
5 and b is equal to 10 and in c i'm creating a list so we know that lists are always enclosed in
square brackets right so let's create a list with the elements one two three four and five now we are going to use
these operators in and not in okay so this is this also gives us boolean values so i am printing
the eis so a n c and i'm
printing b in c so as you can see here a has a value of 5 which is present in this list
c b has a value of 10 which is not present in this list so this fifth line gives us an output of true whereas the
next line gives an output of false okay so as you can see here this is the membership operator so this basically
checks whether the first element is one of the member of the second uh object okay so it is
the not in function is similar to this but it's it's actually the opposite of it
so i'll copy this so this will give us an inverse answer so let's say that a
not in b not in so these are keywords okay so as you can see they are blue in color
so it will give an opposite result so i am just checking whether a is not in c but
a is actually present in c hence we are getting a false value and here b is not in c and we hence we are
getting true value okay so this is about the membership operators so we have seen the six basic operators in python the
first is the arithmetic operator so the basic mathematical operators and then we have seen various assignment operators
so after that we have seen the comparison operators the equal to not equal to greater than less than symbols
and then we have logical operators which are and or and not and then the identity operators
and is not finally the membership operators in and not in okay so that is all about the operators in
python hello everyone this is siddharthan this is the sixth video in python basics
module in our machine learning course so in this video we are going to see what is mean by this if else statement and
how we can use it in python okay so this if statement is one of the basic things which we will start learning
while we are getting started with programming okay so the use of if else statement is that in some cases we need
to perform or we need to run only a specific part of the code and we want to neglect a specific part of the code so
for that purposes we will be using this if while statement okay so in this video i'll show you how you can
use the say file statement in python what is the syntax for it okay so first
let's create a simple if statement simple effects statement so there are
more complicated ways of uh using the cfl statement so let's start from the most basic
okay so let's create a variable called a ca and let's say that a as a value of 30 okay
let's say that b has a value of 15 okay now given two values are given two numbers
we need to uh find which is the greatest number okay so for this purpose we can use a fills
condition let's say that if a is greater than b
we need to print that
is the greatest number okay now else
we need to print that b is
the greatest number okay so basically what we are doing is we are
checking the condition so if a is greater than b so we will tell that a is the greatest number else so else
condition is that b will be the greatest number so we will be printing b is the greatest number so it may seem very
simple so this is just for demonstration purposes so when we are using if statements there will be a lot of
complicated places so but this basic knowledge is you know important for us to do those
complicated things so i'll run this so now it prints that b is the greatest number because b is 50 right so now we
can also do this in a different way where a is equal to let's say yes equal to
in input enter the first number
okay and b is equal to end
input enter the second number okay
now you can just copy this here
so basically what i'm doing is so in this case we have uh given the value for a and b
in this code itself but in this case we will ask the value from the user so when i use this keyword input so it will
get the value from the user and that value will be converted to integer okay so now let's run this so when we run
this so the user will be asked to give two numbers and the greatest number you know this uh
code tells us whether the first number is greater or the second number is greater let's say
that the first number is equal to 150 okay i'm pressing enter so let's say the
second number is let's say 100 so it obviously prints that the first number is
the greatest so here a is the greatest number because we have just used it so you can just put here that
first number is the greatest okay
in this case second number is the greatest so this is how you can get some values from the
user and you can print which is the greatest number okay so let me print
16 here and let's print 20.
so as you can see here the second number is the greatest so this is a simple way of using if statement okay so this is a
simple method there is another thing called as
elsif condition so this is if and else statement
okay so l if which means else if okay so the short form for else if scale if so let's
say that we have three numbers in this case let's say that a is equal to 15 and b is equal to 25
c is equal to 30 okay so in the previous case we just add two numbers and we just wanted to
check two conditions whether a is greater than b so if a is greater than b this code will be printed so it won't go
into the sales condition so if this condition is proven wrong so this condition so sorry this statement will
be printed okay so here we just have two conditions right but when we have three conditions or you know more than two
condition we can use this l if uh statements okay and there is one important point to note here that
if there is this if else pair so either one of this will be printed so like how can i say this is
in no condition both of these statements will be printed okay so only
this condition can be true or the else condition can be true never both the conditions can be true for if feldspar
similarly in this case let's say that in this case we have three numbers and we need to compare
these three numbers and print which is the greatest number okay so for this purpose we can use if else if undeal
statement let's say that if a is greater than b
which is again greater than c okay so let me put it this way a is greater than b and it is also
greater than c okay
sorry okay so a is greater than b and it is greater than c so in that condition i want to print
that a is the greatest number okay so
now i want to have two other conditions now i should use if fails sorry else if
so else if so the keyword is l if so e-l-i-f if
[Music] b is greater than a and greater than c i want to print
that d is the greatest number okay so finally we have the else
statement okay yes print so if both these conditions are
false that means c will be the greatest number so i'll mention that in the else condition so c is the greatest number
so there is no need that you need to mention the condition for uh else so if both these conditions are failed
there is only one conditions so that is that c is the greatest number so you don't need to mention the condition for
else okay so here as i have told you earlier in this uh you know triplet only one conditions will be true either
a is greater than b and c or b is greater than e and c or c is greater than a and c in no cases
two conditions can be correct or three conditions can be correct so in this triplet only
one statement will be printed okay so i'll print this so it should tell that the c is greatest number
okay so c is the greatest number so this is how you can use if you'll say fund else statement so there is another
method of or another variation of this uh if else statement so it's called as
nested if condition suggested if it's a statement
okay so nested if means using a if statement inside an if statement so that is called as nested if
condition so let's say that similarly we have three values let's say that a is equal
to 20 and b is equal to 40 and c is equal to 60 okay and let's say that if
a is greater than b okay so i want to check which is the greatest number so what i will do here is first i
will check whether a is greater than b so if a is greater than b i should check whether a is
greater than c also okay so if a is greater than b
i need to check that if a is greater than c also so in this
condition a is the greatest number because it is greater than b and it is also greater than c so here i can print
that a is the greatest number okay if this condition is false which
means if a is greater than b but a is not less than not greater than c means c will be the
greatest number so yes i hope you are getting what i am telling so print so in this case c will be the
greatest number so c is the greatest number okay now
so this is for this pair okay so this is for this if else is this pair and there is another riff here so we are
we are using one if l statement inside if condition hence this is called as nested if okay so that is another thing
we need to note here so if a is not greater than b or else if b is greater than a this condition won't
be satisfied and these statements won't be printed okay so the interpreter control won't go into this statement so
in this case else so else means if else here means b is
greater than a okay so in that condition we need to again check whether b is greater than
c as spell so in that condition sorry
if b is greater than c also we need to print that is the greatest number
okay now we need to include another else condition so which means in this
condition c is greater than c is the greatest number
okay so what we are basically doing is first we are checking whether a is greater
than b so if a is greater than b we need to check whether is greater than c also now i am checking whether a is greater
than c if these two conditions are satisfied that means a will be the greatest member and this particular
statement will be printed or else if a is greater than b but if it is not greater than c that means c is
the greatest among all the three numbers so in that conditional you want to print this statement which means c is the
greatest number then we have the sales condition where
so when this condition will be uh you know carried out as if this condition this if
is false okay so which means if a is not greater than b or b is greater than a so it will go to this statement because it
is unsatisfied so it won't go into this statements so the control comes here okay and check these conditions so now
we know that b is greater than a right and now it should check whether b is also greater than c as well now it
checks it if b is greater than c this line will be printed or else this line will be printed which is c is the
greatest number okay so let's run this so we got that c is the greatest number because it has a value of 60. so this is
a simple example for nested if statement where we use if statement inside an if statement so you can see here
among this fifth line you know and tenth line so only one conditions can be satisfied and among this sixth line and
eight line only one condition will be satisfied okay so you would have noticed this indentation so when you mention a
semicolon here in the if statement line so there will be indentation or space so we call this
space as indentation so this is very important in the case of these if statements and for loops and while loops
okay so so this indentation means this particular uh line of code comes under
this if condition so this indentation means it comes under this else condition so whenever you use this column here so
there will be an indentation in the next line okay so in colab it automatically creates that indentation in some of the
basic python consoles you need to give that indentation or you need to give that
space okay so these are some variations of if statements okay so we have seen a simple if else condition and then we
have seen how we can use uh the input feature to get the numbers from the user and print the greatest
number and we have seen how we can use this else if condition by uh get having more than two conditions then we have
finally discussed about the nested if statement where we can use if statement inside an if statement so that is all
about the fill statement so in this video we are going to discuss about loops in python okay so there are
basically two important loops in python they are for loop and while loop okay so in this video we will see where we will
be using loops and what is mean by this these loops okay so before starting the video if you want to learn data science
you can check out my amazon data science course with python i have given the link for my course in the description of this
video okay so getting started with today's video first of all let's understand about for
loop okay so so i'll give you an example of where this
is used so first of all let me create a variable as laptop1 so in this laptop on variable we want
our user to type an input okay so laptop one is equal to input
enter the price of the laptop
okay so if i run this this will ask the input from the user so you enter the price of
the laptop so here we can give some price let's say the price of the laptop is 20 000 okay so this is how
you can get input from the user using this input function okay so when you get input from a user it will consider this
input as string so strings are nothing but text okay so we need to convert it to integer so even though it is an
integer or it is a number so this input function will think that this input is a string so we need to convert it by
putting this in keyword here so this will convert this string into an integer okay so i'll run this again now
it will be considered as an integer okay so
now what i'll do is let's say that we want to get the price for five laptops okay so
for that what we will be doing so we will type this lines five times right so laptop
one so i have pasted it five times so i will change this variable to laptop
to laptop three laptop four and laptop so when i run
this so it will ask for the price of the laptop let's say again it's
20 000 for the first laptop and there is another laptop and the price of that laptop is
30 000 and next it's let's say 40 000 and
50 000 okay and the fifth laptop will be
let's say it's 60 000 okay so this is how you can get price of five laptops right so with this
data you can add all those prices and tell the user that what is the total price of the five laptops right so
this is all we can get five inputs but you can look the code here this is not an efficient way to write a code so in
this i have just repeated the same line of code again and again except this change in the variable name right so
in this case only we will use loops so loop is used to repeat a certain action again and again okay let's see how we
can use loop to do this same action so we want to uh ask input from the user five times about the price of the laptop
but we want to do it in a concise way in a short way okay so for this purpose of reducing the size of the code we can use
loops and to repeat the same action again and again okay so for this i can use the for loop as for
i in range 5 okay so
laptop and we put as laptop price so laptop places
input so again you can just copy this here so i'll explain you about the syntax in
a minute okay so just wait a minute okay so what i have done here is okay so this is the syntax for for
loop so we will use this keyword for and i is a variable so for i in range 5 so range 5 means it's nothing but
0 1 2 3 and 4 so in python indexing starts
from 0 as i have told you in the previous videos so it starts from 0 so 5 means 5 numbers so the 5 numbers are 0 1
2 3 4 okay so totally we have five numbers okay so this will count five times and i takes the value of these
five numbers okay so when it runs this loop for the first time it will take the value of zero and then one two three
four so totally we have five times our loop running okay so if i run this okay
so it does not define so i should just make some spelling mistakes so it is int okay so i'll run this
so now we can enter the price of the laptop in the same way as we did so let me put twenty thousand again
thirty thousand forty thousand 50 000 and
60 000 so now you can see here in the previous uh piece of code we have did the same action in five lines of
code but here we have did that you know in two lines of code so this is the advantage and use of loops so we can do
the same thing again and again and it will reduce the size of our code and it will be a very efficient way to do that
so this is the syntax so we will use this for i in range so instead of i you can use
j or anything like that so this is just a variable name so this in a strap is important okay so what happens is for
in5 so when this loop runs for the first time this i will take the value of 0 okay so
5 means these 5 values which are 0 1 2 3 4. so this basically counts the number of times the
loop is running ok so for 0 in range 5 so the first time this code will run ok and this first line will be printed once
we have given the price of the laptop so this will again go to the start now this i will take the
value of 1 and again this loop will be performed so again this the second line will be printed and when i give the
value for this particular line it again goes to the top of the loop and now i will take the value of two and this
continues as long as it gets the first five values so that is when i'm mentioning the value as 5 okay so if i
put something like 7 here so if i run this so it will ask us for 7
values let's say the price of the laptop is 3k so it's 3 000 okay so let me put us three just
consider it's three thousand four five
six seven okay so
i've just typed the enter so that's the problem so let me run it again quickly six
seven eight nine
two three four
okay so as you can see here it has printed this seven times so that is the use of this particular range okay so
when you give seven so it will take the values as zero one two three four five one six okay so this particular number
will be excluded because the number is starting from zero so this is the use of loops and this is how you can use loops
okay so there is another uh way of using this okay so i hope every one of you is familiar with
list okay so let me create a number list so create the list named as numbers
and it contains the numbers as fifty hundred
okay fifty 500 150 and 200 so this list contains four values 50 under 150 and 200 now what i want to do is print these
individual elements so for that you what you can do is you can
put this print function and you can mention the name of the list which is numbers and inside that you can
mention the index values okay so i'll just copy this so
i want to print all these four numbers so one two
three okay so because indexing starts from zero as i have told you earlier so index of 50 is 0 100 is 1 150 is 2 and
200 is 3 so let me run this this will print the individual elements okay as you can see here so instead of doing
this what we can do is use a for loop similarly as we did in the previous case and print these
individual numbers okay so this is the list we have and now what we can do is use a for loop for
in numbers so this for and in are the two important
keywords for for loop so for i in numbers print i
okay so as you can see here so we have this list which contains four elements so
what happens when we run this for loop is so when the loop runs for the first time this i will take the first value
which is 50 and it goes inside this loop so inside this we have one statement which is to print i so for the first
time the value of i is 50. so once this i is completed it will take the second value okay and now it will print the
second value which is 100 and 150 and 200 so this is how loops work okay now
let's discuss about the second important loop which is f while loop so we have discussed about for loop and now we will
discuss about while loop okay now what is the difference between for
loop and while loop so you can see in this case so in this case we know that we want to
print this uh lines seven times right so before we know that we have to print that five times so in this we are
printing it some time so there will be cases in our program or in our code that we may not be sure how many times we
want to run a particular statement so in that particular cases we can use while loops but when we are using a for loop
we should mention the number of times we want to print a function okay so that is the
difference between while loop when you are not sure about the number of times an action has to be executed so this is
how you can create a while loop so you need to initiate
value for i so it can be any variable so i'll use i is equal to 0 and y
i is less than 10 okay so while i is less than 10
i want to print i so let me explain you in a minute what this code does
okay so what i'm doing is so this is i'll just put the syntax of while loop here
so it's while condition oil if the condition so there is condition here
okay so this is the while while loop condition sorry syntax
okay so so we will include this while keyword
and there will be a condition if this condition is true then this statement will be
carried out okay so in this case you can see here so we have this while keyword and then we have a condition which is i
is less than 10 okay so if this condition is satisfied this program will go into this statement
okay so you can see the indentation here so you can see the indentation in the case of for loop also so that means this
particular statement is inside the loop okay so basically what we are doing is first of all we are initiating i is
equal to 0 and we are checking the condition i is less than 10 so as long as i is less than 10 this loop will be
carried out again and again okay so first of all i will take the value of 0 now it will check the condition so i is
less than 10 so we have the value of i s 0 so 0 is of course less than 10 so the condition is true and now this will be
carried out so i will be printed then we are incrementing i with 1. so this basically means so what this basically
means is i is equal to i plus 1 so the short form for writing this
particular line is i plus is equal to 1 so this these two are the same things okay
so just delete here so what happens once i is printed so it will be added with one so now the value
of i will be one right and now it will again check the condition now one is again less than ten so it will print uh
i which is one now and again it will be incremented so this process will
continue as long as ie value is less than 10 so let's print this
as you can see here so 0 1 2 3 so this will print i up to 9 because so if we have made the conditional size
less than or equal to 10 we will get a 10 right so that's why it has printed up to
9 only okay so this is how you can use while loop when you are not sure how many times the loop should run okay but
in the case of for loop we will mention the number of times you want to run a particular action again and again okay
so this is one case where you can use while loop okay so
as i have told you if this condition is true only this while loop will be carried out so let's see what happens if
the condition is not true so i is equal to 5 while
i is less than 3 print
i is equal to one so i'll run this so nothing will happen as you can see here
it just executed but we i is not printed because this condition is not true so you can see here i is equal to 5 so here
the condition is i should be less than 3 but i is of course greater than 3 right so this condition returns a false value
and hence the program won't go into this while conditions in this while loop okay so
that is why we won't get any outputs so this while loop will be skipped so when this condition is true as in this case
we will be you know the statements inside these loop will be printed whereas when the condition is false the
statement inside the loop won't be printed okay so this is about while loop so the important thing you that you need
to know between foreign wireless so in for loops we know the number of times the code has
to be repeated again and again but we can use while loops when we are not sure how
many times the code should be repeated so in these cases i have just made some
very simple very basic examples so that you can understand and when we do various projects and other programs in
python so it will be very complicated very complicated and complex loops will be used okay so this is for your basic
understanding so i hope you understood the basic function of for and while loops in this video i am going to
explain you about one of the important concepts in programming so it is nothing but functions so we are going to see
what is meant by functions and how we can implement functions in python okay so as you can see here i have made a
description about function here so a function is a block of code that can be reused in a program so this is about
function so let's say that we have a thousand line of code in python okay so in the thousand line of code there is a
particular block of code which is then the length of that particular block of code is 100 lines and in our thousand
line code we need to use this particular underlines again and again so what we can do is instead of writing this
underlines again and again we can just create a function so by creating a function you can reuse
it and you don't need to write the entire code again so you just need to mention a word
and using that word you can call that entire hundred lines of uh code okay so i'll explain you this with an example
okay so what we will do is so i'll create factorial program of a number
so factorial factorial of a number so you can understand about functions better with
an example so i'll explain you how you can create a function for factorial of a number
so so what is a factorial so i'll just give you a definition about
it factorial of a number
is the product of all the positive numbers
the positive integers less than or equal to
i give one number okay so so factorial of a number is the
product of all the positive integers less than or equal to number equal to the given number so we would have
learned about this in our you know early classes in school so let me give you an example of
factorial let's say that we want to find the factorial of 5 so factorial of
5 so as you can see the definition above so factorial is nothing but the product of all the integers of all the values
that should be less than 5 in this case so it's nothing but so less than and equal to 5 so it's
5 into 5 4 3
2 1. so the product of all these numbers which are less than and equal to 5 will
be the factorial of h and the value will be 120 so the factorial of 5 is 120 so this is how you can find the factorial
of a number by multiplying it with all the numbers less than and equal to it okay now let's see how we can create
or how we can find the factorial of a number in python okay so i'll create a variable as number
and let me put input enter a number
to find its factorial
okay so this input function asks the input from the user so the user will give a
number and we will find the factorial of that particular number okay and we need to
mention interior because you can see the input function here so this input function consider that the value given
by the user is string so strings are nothing but text so we need to convert that text to an integer okay so so
number is equal to so we need to find the factorial of this number okay so what you can do is create another
variable called as factorial let's put factorial is equal to 1 as the initial value so
as you would know that factorial of 1 is 1 and also factorial of 0 is 1 so there is this important point to note here
that the factorial of 0 is not 0 but 1 okay so i'll create uh this factorial vary variable and give it
the value of one now let's say that if number if the value
number is nothing but the value given by the user if the number is equal to zero so you should put 2 equal to is because
it means the number if the number is exactly equal to 0 so if the number is equal to 0
in that case i want to print that the factorial of 0 is so as i have told you factorial
of 0 is 1 okay so
if the number is not equal to 0 if the user gives some other input input except 0
so what we need to do is we can make an else condition here so
else we can use a for loop to find the factorial for
i in range one comma number plus one
okay so i'll explain you about this after completing this loop factorial is equal to
factorial into i okay so what i'm basically doing is so you can see this step here so for
factorial of 5 we need to multiply 5 by 4 3 2 and 1 so that is what i am doing in this for loop so let's say that the
number is 5 so what happens is so the value of number in this case will be 5 and you can see here we have mentioned
the number here so the range in this case will be so range
of 1 comma
number plus 1 okay so number plus one here the number will be five so five plus one is six so basically a
range of one to six means all the numbers between one and six and this is the important point note
here that it will include 1 but it will exclude 6 so when we mention the range here so it will include this first value
but it will exclude this second value so what it basically means is so range of 1 comma 6 means it
includes all the values from 1 2 3 4 and 5 so this 6 will not be included but the previous number will be included so
1 will be included and 6 will be excluded so as you can see here we have 1 2 3 4 5 and we need to multiply all
these numbers which will give the factorial of that particular number so this is what we are doing in this uh
for loop so [Music] when i is running when this for loop is
running for the first time it will take the first value in this range so the first value in this range is nothing but
one right so it will take the value of one so as you can see here we have already
initiated the value as one for factorial so one into one which is one so and
as it completes this particular statement it again goes to the top of this loop now it will take the second
value which is 2 right now it will again go here now factorial is equal to factorial into a
now it's nothing but so when the for loop runs for the second time so factorial will be equal to
already the factorial is equal to 1 and second time the factor will be equal to sorry this i will be equal to 2 and as
the for loop continues to run so in the third step it will be one into two into three in
the third in the fourth step it's nothing but one into three into four and finally it's one two
three four five so this one two three four five and the
product of all these numbers gives nothing but the factorial of five so this is what we have done in this
particular for loop okay so now
i just need to print this factorial value right so let us print this
but the spring should be in this indentation same line of for because it comes under the sales loop sorry else
condition okay so by this for loop we will find the
factorial of the given number so print the factorial of
number yes so basically i am substituting the
values so the factorial of uh the number given by the user is the value we have found here okay so let us
run this now the user should give a value let's give the value as 5 okay so as you can see here the factorial of
5 is 120. so this is how you can find the factorial of a number in python so let me run this again
now let's say that the value is 10 so we need to find the factorial of 10 so the factorial of 10 is this particular
number so you can check it whether uh the answer is correct or not so this is the exact factorial of 10 okay so now we
have created this factorial function let's say that we want to find the factorial of some other numbers okay so
we cannot write this entire all the lines of code okay so for this particular purpose we can use function
so this is why function is used because it can be reused so that is the application of function that it is a
block of code that can be reused so i'll explain you how you can create a factorial function now so this is
creating a factorial program and this is how to put that in a function so factorial
function so for creating a function you need to mention the keyword diff so def which
means define so we are defining a function so let's name our function as factorial value
okay so we are going to do the same thing that we have done here but we will do that in this function name called as
factorial value and inside this i will mention that input value we are going to give let's
say that input number or i'll just put num
okay so you can see the indentation here also so
so we have to do all the things we have done here so i hope you understood how to find the
factorial of a number so factorial is equal to 1 if the number is equal to 0
we have to say that the factorial is 1 so
what we will do is let's not print but will the return so this function will return a value so
if the number given by the user is zero so we have used this variable as num so
we should uh mention it here so if the value given by the user is 0 it should return the value
which is factorial so we need to mention this also okay so we have already mentioned the
factorial is equal to 1 okay now yes so as you can see here
then we have used the sales condition right so
i'll just do that yes for i in range
okay so i'm just copying this same piece of code but i am putting this inside this
function called as factorial value okay so this will return the factorial value so let's try to run this code
so we have successfully created our function factorial value so what happens is if you call this factorial value and
give a particular number it will print the factorial of that number so i am going to print
factorial value factorial value of let's say that 5 so you want to find the factorial value
of 5 now okay so
sorry it has took the value from here so we just need to mention that so this is the
part where i made the mistake okay so i should give num because that is what we are taking here number means it takes
this value so i'll just run this again now let's find the factorial of i so as you can
see here now it will give the value of i so we don't need to write this entire piece of code again or we don't need to
run this entire code we can just again just call the function which is factorial value
and you can mention some number let's say that we want to find the factorial of 10
and now it prints the factorial value of 10 so as you can see here so instead of writing this uh
11 lines of code again so i have just put it in a single word so this word is now called as a function so as you can
see here so inside this function and i have mentioned all the statements that can find the factorial of a number and
when i call this function with a particular value in it it will give us the factorial value of that particular
number so you can find any factor of sorry factorial value of any
number so factorial value of let's say 6 so this is the use of function so as you
can see here we have reused this particular block of code by defining the function as factorial value so what
happens is when you mention this factorial value and dimension or number inside it or a value inside it so this
will call this function which is factorial value and inside this number the input which we have given will go
and this particular block of code will be carried out so this is the use of
function so the advantage of function is that even under lines of code can be compiled
to a single function name okay so i hope you have understood about function and the advantage of using functions in
output first of all numpy so the full form for numpy is nothing but numerical python
okay so this numpy is basically used for several new numerical operations and other numerical things which we want to
do in our project or in our domain say for example in machine learning we will encounter
large data sets so data set containing lags and even millions of data points and numbers okay so this numpy library
is used for processing that numerical value is better and other such kind of things okay so yes it is uh the short
form for numerical python is numpy okay so numpy arrays has two main advantages
over list and purple so list and tuple are the inbuilt data types in python so they store more than one values in a
data type say for example an integer offload can only store one value but in a list we can store multiple values so
list and tables are nothing but a collection of values okay and the numpy arrays are you know they are just like a
list and double but they are more advanced than that okay so the advantages of
numpy array over list is that they allow several mathematical operations to be performed on them compared to list okay
so we cannot uh perform as many uh operations that we can do on a numpy array on a list okay so and the other
main important thing is the operations that we do on a numpy array are very faster as compared to list okay so these
are the main advantages of it and so you can see this documentation here so you can just search for numpy documentation
so you will find this numpy.org site so this is where you can find the explanation about the several
functions and what is mean by numpy and what is mean by numpy arrays and all those kind of things so if you are if
you have any doubt while you are working on this okay so now let's get started with this
so first in order to use numpy you need to import
this library okay so for that you just need to give import numpy okay so now what i'm going to do
is i'm going to shorten this numpy to enp so i'll import numpy as np so what happens is this will
import the numpy library in the abbreviation np okay so you can run this so press shift plus enter to run this so
this environment is called as google collaboratory so in this google collaboratory you can run python codes
so if you are new to this google collaboratory check out my google collaboratory basics video and the index
of that video is 2.1 so in that i have explained how you can use google collaboratory and other features of
google collaboratory okay so here we have successfully imported numpy okay so as i told you earlier numpy is a python
library so libraries are nothing but pre-made functions and pre-made classes which are stored in a python file okay
so we can access these functions which are pre-made for our uh programming say for
example that can be under line of code okay a particular function
can be under lines of code so we don't have to write the entire hundred lines of code
so rather than what you can do is you can create a module or a library and store that under lines of code in a
single word or a function okay so using uh that particular library you can call that
call that function and this is the use of libraries so instead of just recreating the code you can just call it
with a function or libraries okay so that is the use of libraries in python so and here we have this numpy library
and i have imported numpy snp so as i have told you the one main
advantage of numpy rs is that the operations are faster in it okay so i'll just show you
i'll show you how we can find that so i create a text here as this to us is
numpy time taken okay so here what i'm going to do is i'm
going to perform a simple task on both list and number separately and i'm going to find the time taken to do that
particular operation okay so or that particular process okay
so for this i need to import time so from time so time is another library so from time input process time
okay so this process time is used to measure the time required for a particular process okay so i'll run this
okay now let's see the time taken for a particular task in a list
time taken by a list okay
one second okay so what i'll do is i'll create a python list so i'll declare the list as
python list so we are creating a list named as python list and so list should be enclosed in square
brackets and what i am going to do is i am going to create a for loop to assign values to this list okay
so i for i in range
for i in range let's say ten thousand okay so what i'm basically doing is i
want this python list to have values starting from one to ten thousand so that is what i have mentioned through
this range uh ten thousand so i'm creating a for loop that will uh give the list values from 1 to or 0 to 10 000
okay so now what i am doing is i am mentioning this start time okay so start time is equal to
process time so we are using this process time to measure the time taken by this
particular process now what i am going to do is so again i am calling this this python
list and in this list i am going to add the value 5 to all the variables
so we have totally we would have 10 000 values right from 0 to 10 000 so i am going to add 5 to all the values in this
particular list okay so we can do that by using this line of code so i plus pi for
i in python list so this is the similar for loop as we
have used it so the difference is that so i am taking all the values from this python list and for each value i am uh
adding the value 5 okay so this is the process i am doing doing and i will just give i end time here
okay so in time is equal to process time and
let's print the amount of time required by this particular process so it can be found by end time minus start time
okay so what i'm basically doing is i'm first initiating or creating a list and in that list i'm putting the values from
0 to 10 000 and i'm creating a start time area and an in time area and between that we have this particular
process happening which is to add 5 to all the values of this particular list so what happens is we
have this start time and end time so this particular cross time function process time
function will find the amount of time required or an amount of seconds required for this particular process to
complete and we are finding the difference in it and this will print the number of seconds taken by this
process to complete okay so let's run this so as you can see the amount of time
required for this particular process so it's this is in seconds so it is around 1.7 milliseconds right so this is
the amount of process taken by a list to complete this particular process now what we we shall do is now let's create
a numpy array and do the similar process and see how much time a numpy array takes okay so i'll declare the variable
as np array and let's say np array is equal to np dot array so you can see here i have imported the numpy library
as np so i am just calling that numpy library here and this numpy dot array function is used to create arrays okay
so numpy array i am just using the same code i have used in the previous cell which is
i for i in range
10 000 okay it's the same code that we have used so i want to create a numpy array in this
case with values from 0 to 10 000 and i'll create a start name okay i'll
just copy the code from here so start time and now what we will do is we will add
this 5 to all the values in this numpy array so it is the same process that we have done here so np array
plus equal to 5 okay so this is similar to uh just adding
numpy array is equal to numpy array plus five so this line so we have this line right so this is
similar to this so np array plus is equal to five is similar to numpy array numpy array plus five so what i'm
basically doing is i am adding this value five to all the elements of this array okay so that's why i am doing
which is very similar to this process we have done okay so the only difference is that in this case we have added 5 for
all the elements in a list but in this case we are adding 5 to all the elements in a numpy array now we need to mention
this in time okay so i'll just copy this end time and start time so
this is basically the same process now this process again will take place and for all the values in this numpy array 5
will be added and the amount of time taken for this process to complete is calculated okay
so you can see the difference here so the time taken for this numpy array to complete is very much less as compared
to this particular line right so it is almost 5 to 10 percentage faster than the list okay so this is the
significance of numpy array so you can say that this time difference is not much right but in this case we are just
dealing with uh you know 10 000 values but there are cases where we will deal with uh
you know a million of data points or million of numbers so in that case the time
difference is quite significant okay so this is one advantage that i have mentioned to you that in numpy array we
can do operations much faster as compared to a list okay so now let's get into numpy arrays so let's see how we
can create numpy arrays and how we can perform several operations or functions on a numpy array okay so i'll create a
text as okay sorry numpy rs
so let me show you how you can initiate a list
so we are creating a list here so this one so i mean i'm declaring the name of the list as list1 and let's say
that the value of this list are 1 2 3 4 and 5 okay so i want to print this list
print list1 and i want to check the data type of the
list okay so
type list okay so first let's create a list and see so as you know
the list should be enclosed in square brackets okay so this type list will give us the data type of this
particular uh data type okay of this particular object so we you can us okay sorry
it's list one okay as you can see here we have printed the list and we have found the data type
of this particular object as list okay now let's do the same for numpy array i'll declare the numpy arrays np array
and this numpy array is equal to let's say np dot array which is equal to so you need to uh
pay attention to this parenthesis and square brackets so you need to mention this
parenthesis first and inside this you we need to create a list and put the elements in this particular square
brackets okay so we are going to create a numpy array and the values are same to this okay so one two three four
five okay so now i'll print this numpy array so np array and also i'll check the data type once
type np array okay so this is an example of a numpy array
so you can see here in list the elements are separated by comma but in this case the values are elements are not
separated by comma in the case of numpy okay and we have found the data type to be numpy dot nd array so nd represents n
dimension array so arrays are similar to matrixes okay so we would have studied about vectors and matrices in
mathematics so this array is similar to a matrix in matrix okay so let's see how we can create these kind of arrays
and more dimensional arrays okay so creating a
one-dimensional array so it is the same as we have done here so i will declare the variable as here
so the name of the array will be a in this case so a is equal to np dot array and let's say the values are 1 2 3
and 4 and now we can print e
okay so we have successfully printed the numpy
array here now what you can do is we can check the shape of this numpy area this particular function shape will give us
the number of rows and columns in that particular numpy array okay so you can see here we have only uh one
value because this number is one dimensional so this four represents we have four columns okay so now let's
create a two dimensional array so i'll create or i'll declare the variable as b so b is equal to
np dot array and what i'll do is
let's say the values are one two three
and four five six seven and eight okay so now let me print b
as you can see here this is similar to a two cross four matrix containing two rows and four columns right so this is
how you can create arrays with multiple dimensions so in this case we have just created a one dimensional array
containing one row but here we have created an array with two rows and four columns so now
you can check the shape of b okay
so the first value represents the number of rows and the second value represents the number of columns so we have two
rows and four columns in the case of the array b okay so in this case we have just only one dimension so we have just
one number here okay so in this case four represents the number of columns but in this case so the first value
represents the number of rows and the second value represents the number of columns so totally we have two rows and
four columns in this case now let's do another thing i'll create
another array c is equal to np dot array and so as you can see here all the
values are integers in this case right so now let's see how we can put values with
float floating points floating points are nothing but the decimal values so np dot array which is equal to
say 1 2 3 and 4 and 5 6 7 and 8 okay and now you can
mention the data type as d type so d type represents data type float okay
now let's print c as you can see here now we have floating point values which is this is similar to
1.0 2.0 etc so by mentioning the data type float so you can uh create an array with a floating point values so if you
don't mention any uh mention any data types the default value is integers so we get an array of integer values okay
so now let's discuss about placeholders in array
so now we are going to discuss about initial placeholders in
numpy rs okay so these initial place orders are
nothing but in some cases we want to initiate arrays with certain values say for example in several cases we may need
to initialize an array in which all the values are 0 in some other cases we need the initial values to be 1 in all the
values so such kind of things so that is meant by initial placeholder so initial place order placeholder means the
initial value is present in that particular numpy array okay so now let's create
a numpy array of zeros so let's name the array as x so x is
equal to n p dot zeros so zeros is the function which is used to create an array
containing the all the values are zero so in this particular parenthesis you need to mention the shape of your array
four comma phi let's say that we want to create an array of four columns four rows and five columns and we need all
the values to be zero okay so that's what we are trying to do here so you can note here that i have used used two
parenthesis here so inside this parenthesis i mentioned the shape of the array that i want so now let me print
x okay now as you can see here we have created an array
with all the values as zero of four rows and five columns okay so you need to use this np dot zeros function and inside
that you need to mention the dimension of the array that you need now let's create a numpy array with all the values
as one okay create a numpy array
of ones so i'll create a the numpy array as y so np dot once is the function that's used
to create array with value 1 so now let's put the shape of the array as let's say
3 comma 3 okay so i want a 3 comma 3 array with all the values as 1
let's print y as you can see here we have created a 3 cross 3 array with all the values as 1.
so this is some example of initiating an array with the values of 0 and 1. now let's see how we can create an array
of a particular value okay so particular value so let's say that the array is at and is it is equal
to np dot full this full function helps us to create an array with a specific value so first you
need to mention the shape or the dimension of the array you want so let's say that i want an array of five comma
four uh shapes of five it means five rows and four columns right and next you need to mention the value which you want
to give let's say that i want a 4 cross 5 array or 4 cross 5 matrix with all the values as 5
and now let me print is it as you can see here we have got a five
rows and four column matrix with all the value as five okay so this is how you can create an array with a specific
value now let's see how we can create an identity matrix so create an
identity matrix so we would have studied about this ident identity matrix in our basic
mathematics so this identity matrix means all the diagonal values will be having the value of one and the other
values will be zero okay so this identity matrix is also used in various cases in our programming so i'll create
the numpy s a and for creating an identity matrix you need to use the function i so np dot i
and in that mentioned the the shape of your matrix okay now you you should not uh mention the number of rows and
corners because identity matrix have the same number of rows and columns okay so we cannot have uh identity
matrix of five comma four uh array or we cannot have an uh identity matrix of four comma five uh
array okay so in the case of identity matrix the number of rows and columns should be equal so example this case so
the number of rows and columns is equal so in such case we can have a identity matrix or in case where the shape of
that is 4 cross 4 or 5 5 cross price so those kind of things so you need to mention so let's say that we want a
identity matrix of four rows into four columns okay so let's print a now
as you can see here we got identity matrix where all the diagonal values is equal to 1 and the remaining values are
nothing but 0 so this is an identity matrix so you can just change this value and see so this will give us a 5 cross 5
matrix but it is an identity matrix ok so this is how we can create identity matrix using np dot i function okay so
we have just given this pre-made values in this case so we we created array with all the values as zeros and then one and
a particular value all those kind of things now let's see how we can create a numpy array
so create a numpy array with random values so i want to create a numpy array with
random values let's say that the number is b and you can use the function np dot
random dot random so in that you need to mention the shape of the array that you want let's say
that we want a three cross four matrix uh three rows four column matrix or three cross four column three rows four
column array with random values so but there is one important thing to
note here so let me run this first so we got these random values in our
numpy array but the main thing to note here is all the values will be from or all the values will be between 0 and
1 okay so let's run this again we will get some other value okay so we won't get the same value so we will get some
other values but that value will be between 0 and 1 okay so this is how we can create a numpy array with random
edges now let's see how we can create an array with random values but we need random integers okay
so let's see that so random value
random values array and in this case we want integer okay so random values are a
random integer values are a and we can mention the range we need so random integer values are is
within a specific range okay so i'll create the number is c so c is equal to np dot
random so we have used this random dot random function to create numpairs with values
between 0 and 1 to 1 so now you can use this function np dot random dot rant in so it means random integers okay so now
you need to mention the starting and ending point of your value so here you just need to mention
the range in between you want the values to be let's say that it's 10 to 100 okay and next we need to mention the
shape we want let's say that we want a three rows and five column array so basically what happens is we will get a
3 cross 5 array and all the values will be in the range of 10 to 100 okay so now let's print this
so as you can see here in the previous case we got a decimal values between 0 and 1 and now we have got all the values
between 10 and 100 okay so this is how you can create a random value array with specifying their starting point and
ending point okay so if you run this again you will get some other value but the value will be in this range 10 and
100 okay so you can change this shape to get a different dimension array okay so next what we will do is let's see how we
can create an array of
evenly spaced values evenly values so
d is equal to for this you can use the function np dot lin space
okay so np dot lin space in that you need to mention the
starting point and the ending point or the range in which you want the values let's say that i want the values between
the range 10 to 30 okay so i want five values in this particular array okay so what i am doing is i am
mentioning the starting point and ending point and the number of values i need so let's run this and see
so we will get five values between this range uh 10 to 30 but all these five values
will be evenly spaced so i am running this so as you can see here we got five
values and these five values are evenly spaced okay so or you can just use six and c
so i want uh six values and they should be evenly spaced and that value should be like should lie between 10 and 30
okay so here we are getting an array of evenly spaced values and here we are specifying
the number of values you want specifying the number of values required okay so there is another
method of creating a evenly spaced values but in this case we can mention
the step number okay say i'll just do this and explain you so
array of evenly spaced values
and now we need to specify specifying the step okay so i'll explain you what
is meant by this step so let's create the array as e so e is equal to for this uh you can use the function a range
so a range i want the values between 10 and 30 and i want the step value to be 5 okay
so in this case you need to note here is so we are not mentioning that i need five values here we are mentioning that
the step should be five so the if the value starts from ten the step should be five the other value should be fifteen
twenty thirty uh fifteen twenty twenty five like that okay so let's run this
so print e as you can see here we get uh the step as five so here we are not mentioning
that we need number of values so here you can see we have only four values so here we are mentioning the step value
which we want okay so we want the values to jump with five units so that's what we are mentioning this using the sa
range function but in the case of lin space you will mention the number of values you want so let's say for example
in this case let's mention 5 so these both are the same but we are just using different function let's run and see
this so it will give us 5 evenly spaced values but this will give us evenly spaced values between this
particular range and mentioning this step so this is how you can create in your
evenly spaced arrays now let's see how we can convert a list to an array convert a
list to a numpy array okay
so let's declare the list as list two so let's say that list two is equal to so the list should be enclosed in square
bracket let's say that the list as well is 10 20 30 40 and 50 okay
so let's create a numpy array as np array and
we can use the function np dot as array so this np dot s array will convert one uh particular data type to a numpy array
so we are converting this list to a numpy array here inside this mentioned list two okay so
this will convert this list to which is typically a list to a numpy array and now let's
print this np array and let's also check the data print
sorry type so this will give the data type so let's run this
as you can see here we have converted this list to a numpy area as you can see here there are no comma here so we have
successfully converted this list 2 into a numpy array and we have got the data type as numpy.nd array okay so this is
how you can convert a list to a numpy array so you can also convert a tuple to a numpy array so the tuple will be
enclosed in parenthesis but the list will be enclosed in square brackets okay so this is how you can convert a
different data type to a numpy array now let's see how we can analyze a particular array so
analyzing numpy array so analyzing is nothing but getting various information about that
it's just inspecting array okay so analyzing a numpy array so let's say that
so let's create an array as c so c is equal to np dot random dot random so i want random
values let's take integer values so random dot random
so in that i want the values between let's say 10 to 90 and i want a five cross five matrix okay
so i want a five cross five matrix or five cross by array with values ranging between ten and ninety okay so i'll also
print this c so print c so we got a 5 cross 5 array with the
values between 10 and 90 so let's do some analysis on this so you can find the array dimension using this
function so we have already seen this sorry dimension so what you need to do is
i'm just printing this so mention the array name so here in this case the array is nothing but c okay so put c
here so c dot shape so this will give us the shape of the shape of the array is nothing but the number of rows and
columns okay now let's check the number of dimension it has
so number of dimensions so let's print so for that you can use
the function c dot n dime so i am using c because the name of this particular array is c okay so this is
the function we have so n dot dime so it means it gives the dimension value so as you can see here we have two
dimensions two dimensions because we have rows and columns here right so it is a
two dimensional array so if you have just a single row it it will be a single dimensional array as we have rows
and columns in this case it is a double dimensional array or it is a 2d array okay so you can also check the number of
elements present in the array so checking the number of
elements in an array let's print
c dot size so this size gives the number of elements
so let's print this so as you can see here totally we have 25 values so we have five rows and five
columns so totally we have 25 values so you can find the number of elements present in an array using this size
function okay so now let's see how we can check the data type present in this array okay so
checking the data type of
values in the array okay so
it's printed so print c dot d type so d type represents data type
so we know that all the values are integers because we have initiated the random integers values so it is in 64
that means 60 in 64-bit integers values okay so this is how you can find what is the data type present in a particular
numpy array okay so this is about analyzing or inspecting an array now let's see some mathematical operations
that can be performed on an array so mathematical operations
on a numpy array or np array so i just want to give you another
example here so i need to show that in with the list so i'll create the list as list one which is equal to
one two three four and five and i'll create another list as list 2 which is equal to
6 7 8 9 and 10 okay so now what i'll do is i'll just add both of this list and print it so let's print list one
plus list two okay so what do you expect this to give so
let's try to run and see this so we have we tried to add this list but what actually happened is so when we use
this add symbol the elements are not adding so these the element wise addition is not happening
say for example the the addition value does not give us the values of 7 and 9 where we
add the values element twice okay so in the case of list when you use this add symbol between two lists it will
concatenate the two list okay so concatenate means just joining the two list so this plus sign
will concatenate our
joins to list so we cannot add uh or we cannot have element choice addition in the case of list so concatenate or join
to list but we can do this in the case of ah numpy rs so let's see how we can
do that so let's create a numpy array so a is equal to np dot and just copy this from above sorry
okay i'll just do that do this here so np dot random dot random so i want a
in random integers for integer values and i want the values between 0 and 10
okay so 0 and then now let's mention the shape we want let's say i want a 3 cross 3 array so 3
row and 3 column array and all the values should be between 0 and 10 and i'll create another array
i'll name this array as b okay so we have basically we have two rs a and b and now i want the values between
10 and 20 in this case okay so first array contains value between 0 and 10 and the second array contains value
between 10 to 20 and the shape is similar which is 3 cross 3 so let's run this
let's print both of these arrays so print a and lens
print this b so as you can see here we we got an
array with random values so the first array has values between 0 and 10 and the next array as values between 10 and
20 so now what we can do is we can run some mathematical operations in it so let's
run let's say that it's a plus b so we want to print a plus b so in the case of list
when we add the two list it will concatenate or joins the two list but in the case of
numpy array when you add two numpy arrays so we will get element twice addition say for example in this case
the first element is 7 in the first number and in the second number array the first element is 15 so both these
values will be added so that will be elementwise addition so let's also do a minus b
and let's do all the mathematical basic mathematical functions just a into b so
you a into b and a divided by b
so a by b okay so you can run this so this will give us element to its addition subtraction multiplication and
division so we get four numpy arrays and all this the element twice operations will be done okay so in the first numpy
array a and b will be added element twice then it will be subtracted then it will be a multiplied and uh divided okay
so this is one way of doing it where we just add both of these arrays so we can do this in another way
so it is we will just print
just mentioned np dot add okay so in that you need to mention the two is which you want to add let's say
that we want to add the other two numpy arrays a and b so i'll just
copy this and i'll just make another array here so i want another
a and b so i'll run this now we will have different values for a and
b let me print that so print a comma b sorry so print a and
print b so we will get new values for this so instead of just putting a plus b what
you can do is you can mention this np dot add function this add function will add two
arrays so i have mentioned a and b now print
mp dot subtract so this will uh find the difference between the two arrays element twice so
a comma b and then we can np dot multiply
a comma b and finally let's print
mp dot divide e and b okay so let's run this so this
is similar to this particular code but it is an another way of doing that using this np
dot add on np dot subtract function so we got four mathematical basic operations
performed on a numpy array okay so this is how you can perform some basic mathematical operations on it okay so
now let's do some array manipulation so i'll just create a text here
all right manipulation so let's create
an array so i'll declare the name of the array array itself so mp dot random dot
random and i want the values between 0 and 10 and i want the shape of the array to be
2 comma 3. so it will be a 2 row and 3 column matrix as we know now i'll just print this array
and also i'll print the shape of this array so print
array dot shape okay so this is similar to a two cross three matrix where we have two rows and
three columns right so now you can create the transpose of this matrix so i'm going to
create the transpose so let's name the transversus trans which is equal to for that you can use
the function np dot transpose okay so mp dot transfer so inside that mention the array which you want to
convert so i want to convert this particular array and find its transpose so np dot transpose
array and let's print this
trans okay and now let's print the shape of this transverse array
as well so trans dot shape so transpose is nothing but if the matrix is 2 comma 3 it will be converted into a 3 cross 2
matrix so all the rows will be converted into columns and the columns will be
converted into rows so if we have the values as 1 2 8 0 7 the values will be 1 8
2 0 and 2 7 so let's run and see this so as you can see here the array is transposed so this is how you can create
an array and you can create the transpose of that particular matrix so there is another way of finding this
transpose so i just copy this right so it will give us new values okay
so as you can see here now the values are different so there is another method of finding the transpose so i'll create
trans another transfer says trans 2 which is equal to so mention the array name so here the array name is array dot
t so when you mention this dot t it will find the transpose of this uh array and it it will store that in this
trans two okay so now let's print
trans2 and let's print
the shape of this trans two so trans two dot shape okay
so now we can see here that uh this trans this particular matrix is transposed using this dot t function so
these are the two ways of finding the transpose of a matrix
so now let's uh see another thing so this is the last function which we are going to see
so reshaping array so let's create a array which is equal to np dot
random dot random and let's say that we want the values
between 0 and 10 and i want the shape of the matrix or shape of the array to be 2 comma 3 so it
is a 2 comma 2 rows on 3 column array with values between 0 and 10 so let's print a
and also let's check the shape of
a dot shape so as you can see here this is the random
variable which we got so it is a two comma three uh shape matrix or two comma three shaped
array so now you can reshape this array let's say that let's create another array as b
so b is equal to a dot b shape and
let's say that 3 comma 2. so in this case we have a 2 comma 3 matrix and now let's say that i want to convert
this to a 3 comma 2 matrix so in this case it will be 3 rows and 2 column matrix so this particular array which is
here so you can see this is the array so this will be converted to a three comma two array okay so let's
and it will be stored in this array b okay so let's print b and let's also print the shape of b
so i'll run this so now you can see here this is how we can reshape our array so this reshape is one of the most
important function we will be do we will be using in array okay so these are some of the most important functions and the
most important properties you need to know about arrays so you can make note of this or you can save this code
anything you want but these are very important so these can be seen very simple for you and it is actually very
simple and these will be used in various uh you know
times when we are working on machine learning projects or any other projects so this is why numpy array is very much
important for us so the main thing to note here is the numpy arrays are very faster than
the inbuilt python data types like list or temple and we can do several mathematical operations and other
operations as well so there are also other functions beyond this but these are the important functions
which we will encounter regularly so i hope you have understood all the things we have done
here pandas library in python okay so this is the third module in our hands-on machine learning course with python in
the first two modules we have discussed about the machine learning basics and the python basics required for machine
learning okay so in this module which is the third module we are going to discuss about some of the most important
libraries that are required for machine learning okay so in the previous video we have discussed about the tutorial on
numpy library and in this video we are going to see about pandas library okay so as you can see here i have made some
description here so pandas library so the main use of pandas library is for data processing and analysis okay so in
machine learning we deal with lots of data okay so there can also be in cases where we will be dealing with even
millions of data points okay so we need a certain tool or a suitable tool to
perform various operations and functions on those data okay and pandas library is one of the main tool we will be using in
machine learning for data processing and for also analyzing the data set okay so pandas contains an important object type
called as data frame okay so as you can see here pandas data frame is two dimensional table or data structure with
labeled axis okay so these are nothing but very structured tables okay so these are two dimensional tables having rows
and columns okay and there will be uh column names for each columns okay so this is about the pandas library so
pandas library basically has two objects so one object is this data frame and there is also another object called as
pandas series okay so but in machine learning we will be using this data frame predominantly so i will explain
you most of the important functions that are that we will be using in this data frame
okay so i i will be explaining you all the functions by taking two example data
sets so i have already uploaded one data set file here so diabetes.csv file so this is the diabetes prediction dataset
so we have already made a project video on predicting diabetes of a patient using this dataset so you can check that
video as well if you are if you haven't seen that okay so and we will be using another data set
called as boston house price prediction data set so these are the two datasets we will be using and we will be doing
all the code in google collaboratory so if you are new to this channel or if you new to google collaboratory you can
check my video on google collaboratory basics in which i have explained you about
how you can access google collaborated through google chrome and what are the various features of google collaboratory
okay so now get started with this pandas tutorial so first we need to import the library
importing the pandas library so libraries are nothing but pre-made
codes so these codes are pre-made already and they are stored in these modules or these libraries and we can
use these libraries for those specific functions okay so for that you need to mention this import so this will import
that library so let's input pandas so i want to import pandas in a short form so i don't
want to use pandas in all the code so i just want a shorter form of this library so let's import pandas as pd okay so
this is the general convention that we use in machine learning or any other python related codes so we will be
importing pandas as pd and if we are working with numpy library we will import numpy snp okay so i am importing
pandas pd here so you can press shift press enter to run this code okay so this will import our pandas library
now let's create a pandas data frame okay creating so you can join my telegram group i'll
give the link for that in the description of this video so in that i will be notifying you once i post new
videos okay so getting into this we need to create a pandas data plan so
first of all let me also import the boston house price data set so we have already imported the csv failure now we
will import the boston dataset from sklearn okay so importing the
boston data okay master no space data so it is uh present in the scale and
library so you can use this for that from sklearn dot datasets
import load boston okay
so i'll create or i'll declare the variable as
boston dataset so boston dataset is equal to load boston so this will load the boston
dataset to this boston dataset variable okay so i'll run this
you can check the data type of this particular object so type so i want to check the type of
boston data set okay so as you can see here it is a sklearn
utils bunch so bunches like a dictionary object so it contains a lot of data so let's try to print and see this data
okay so print boston data set so this is the data set we have imported
as you can see here so i hope you know that a dictionary contains a key and a value so here the key is nothing but
this the word data and these are the values in it so we have various values in it and this is the target so this
target is nothing but house price so these values are in thousand dollars okay so twenty four thousand dollars
twenty one point six thousand dollars and those kind of things and uh these uh data represents various values like age
of the person owning that house or the tax they need to pay
and the crime rate and all sign all kinds of data and this target variable contains the price of the data set sorry
the price of that particular house okay so you can see the feature names here so these are the different features or
columns so we have the crime rate zone number etcetera okay so we have already done this
project for predicting so you can check that video if you want to get more information on this okay so now
we have successfully imported this boston house data set from escalant as you can see here there are so much
numbers here right so this you know type of data is not very suitable for analysis so this is where
pandas comes into play so this pandas helps us to import this data set into a more structured table okay so let's see
how we can do that okay found us
data frame so i'll declare the variable as
boston df so df means data frame okay so is equal to you can use this pd dot data frame function okay so pd is
nothing but panda so we have imported pandas pd okay
so in this mention what is the data that you want to include so let's say that i want to
include all these data okay so i want to uh include this data from this boston dataset object so i don't want to
include this target or price of this right now so i just want to include all these data in my data frame so you need
to mention so pd.dataframe mention the dataset name which is faustin dataset dot data
okay and also mention the column names
or you can just mention columns so columns is equal to boston data set dot
feature names okay so i'll explain you what is meant by this so we are creating a pandas data frame and inside this we
need to give the data we want and the name of each of the column we want so let's first see about this so this is
nothing but boston dataset.data which is nothing but this so you can see here that we have printed this boston dataset
right so these are the data so i want to include all these values and i want to get the columns column names as well
here the columns names are nothing but these feature names the crime rate zone etc okay so i'm loading all this data to
my data frame which is known as boston df and i am importing all the feature names as
column name okay so let's run this okay so now let's see the sample of this
data set so boston df dot here so when you use this yet
function in a pandas data frame it will print you the first five rows of that data frame
so as you can see here we have printed the first five rows so we have all these columns as crime rate zone indus etc
okay so this is how you can see the sample of this data set now
what we will do is let's check the shape of this data frame so boston
df dot shape so this tells us the number of rows and columns in this particular data plane
so the first value represents rows and the second value represent columns okay so totally we have five not six data
points are fine all six values for a different houses and then we have 13 columns okay so this is how you can
check the shape of a data frame so by this we can by using this data frame function this is how we can load a data
set into a pandas data frame now i am going to show you how we how you can
import a dataset from a csv file okay so importing a pandas
sorry importing the data from a csv file
to a pandas data frame okay so as i showed you earlier i have already uploaded this
diabetes dataset so it is it is nothing but diabetes.csv so csv are nothing but comma separated
values i'll show you how this data actually looks so i'll open this in notepad
so in this all the values will be separated by comma okay so this is the comma separated values so
this is the diabetes dataset vr and you can see the column names here so each of these represents each column name and
these are the data okay so the problem with this is that we cannot do any analysis if we have the data like this
right so this is why we need a structured table and this is where we will use this data frame okay now i'll
show you how you can import this csv file to a pandas data frame so
[Music] csv file to round us data frame okay
let's create the data framework declare the data frame as diabetes and dfs which means diabetes
data frame so the previous data set we have worked on is boston data frame so diabetes data frame just copy the path
here so copy copy the path of this diabetes csv
and for this you need to use the function td dot read csv so this read csv function
will read the csv file and store all the values in the csv file to a data frame whereas in this case we have used this
data frame function because we already add this data okay so now use this pd.treat csv
and inside codes mention the path of this file okay so it's nothing but diabetes.csv
okay so now let's run this and now you can check the data type of this particular object so which is
diabetes df okay okay so it's not defined
that is okay so there is a small spelling mistake here
okay so as you can see here it is a panda score frame data frame so it is a data frame object so you can check the
same with this boston df as well so boston df
so as you can see here it is a data frame whereas before it was a scalene or cycle and bunch data type okay so this
is how you can load a csv file into a pandas data frame so you can similarly find the head of this data
frame as diabetes df dot here so this will print the first
five rows so i'll run this so these are the first five rows so these are various uh columns such as
pregnancy so this dataset basically contains the values for uh women okay so we have the pregnancy values
blood glucose values blood pressure values skin thickness insulin bmi pedigree function agent finally we have
this outcome okay so outcome is nothing but one represents that the person is diabetic and if the label is zero it
means the person is non-diabetic so these are nothing but the labels so we have two labels here one and zero okay
so this is about the sample the sample of this data set so you can also find the shape of this data set by using this
that is pf dot shape okay so we have totally 768 data points or
768 0009 columns okay so you can also read a excel file i'll just make a text here so in this we have read
a csv file right so you can also do this with a excel file for that you need to uh use
this particular function it's loading the data from
the excel file to a pandas data frame okay so i'll just put
it in text you can check this with some excel file okay so it is very similar to this you just
need to use the function pd.read excel okay so i'll just mention the function here
so pd dot read so this is the function and in the codes
you need to mention the path of the file so
file path so this will read the excel file and it will store all the values to a pandas data frame okay so
now let's discuss how we can export a data frame to a csv file okay so exporting
a data frame to a csv file okay
so we have discussed here how we can load the contents of a csv file to a
pandas data frame using this read csv function now we are going to discuss how we can load this particular data frame
to a csv file okay so it is the reverse order for this so what i am going to do is i am going to load all the contents
of this boston data frame to a csv file okay so i'll take this boston data frame so
mention the data frame name name here here the data frame is boston df so boston df dot 2 csv this 2 csv is the
function that will so you can see this here so it will load all this data to a comma separated value
file so in this you need to mention the file name so i want the file name to be boston.csv okay so this is how you can
do this so i'll run this so you can see here we don't have any file as boston csv here so once we run this particular
code it will create a csv file containing all the values from this data frame okay
so here you can see that we have this boston.csv file so this is how you can convert a data frame to a csv file so i
just download this csv file so let me open and show it to you
so you can do this for an excel file also you can also load the contents of a data frame into a excel file as well so
just a second it's taking some time okay so we have this boston.csv file now now
you can open this in a in excel or in notepad to see how this looks
okay so we have successfully converted this boston data frame from
uh this sklearn bunch to a data frame and now from data frame to this csv file okay so this is how you can
convert this now you can also do this by storing or by importing or exporting all the values from a data frame to a
excel file okay so for that you just need to use the function so like pd dot read csv you just need to
mention the data frame name here so i'll just put it here exporting
the pandas data frame to a excel file
so for that so you need to mention the data frame name here so i'll just put df so in this
case you need to mention as boston.tf dot 2xl okay so this will store all the values in a excel file so
in the parenthesis you need to mention the file name okay so it's the same procedure so this is how you can do this
so now let's see how we can create a data frame with random values
so i am going to create a data frame with random values so for this particular function i need
the numpy library as well so i'll import numpy library so i'll just import it in the first line
okay so i'll run this so this will import the numpy library as np so we are going to create a data frame
with random values so let's declare the name of the data frame as a random df so this random df is equal to it's the
same function which is pd dot data frame which we have used before so pd dot data frame here you need to mention
mp dot random so this mp is nothing but a numpy library so
random dot rand and in this
parenthesis you can mention the number of rows and columns you want so i'll say that i want 20 rows and 10 columns so
this will create a data frame containing 20 rows and 10 columns with random values okay so i'll run this
now you can see the sample of this data frame so random df dot yet
okay so i'll run this now you can see see here so we got the first five rows of this entire data
flame so totally we have 20 rows and we have 10 columns so we got these 10 columns and these are nothing
but random variables but the main thing to note here is when you use this random dot rand function the values you get
will be in in the range of 0 and 1. so all the values will be between 0 and 1. so this is how you can create a partners
data frame with random values between 0 and 1 okay so if you want to have different uh rows or columns you can
change this here okay so you can check the data frame shape so
random df dot shape okay so this will give us the shape which is
20 and 10 so which we have used here okay so this is how you can create random data frame now let's see
how we can do some inspecting on a data frame so we are going to inspect certain features or properties of a data frame
so inspecting a data frame so
first let's see how we can find the number of rows and columns finding
the number of rows and columns so this we have already seen
which is to use this dot shape function so for this i am going to work on this boston data frame so we
have this boston data frame loaded as boston boston underscore df right so i am going to use this particular data
frame okay so mention the data frame name here so once
you mention the data frame name just put dot and shape so this shape function will return us a value
containing the number of rows and number of columns of that particular data set so we have seen that this boston data
frame contains five or six data points or five or six rows and 13 columns so now let's see how we can print first
five rows so i have also shown this to you already so first five rows in our data frame
so just mention the data frame name boston df dot yet so this will print the first five rows
so as you can see here so this is helpful for us to understand what is the range of the values in a data frame okay
and what are the different values are looking like okay so you can also print the last five rows asked by rows
of the data frame so you can do that by mentioning the data frame name which is boston df dot a
okay so this yet function will print the first five rows whereas the tail function print the last five rows
so you can see here so this printed us the last five rows of the data frame okay so
now let's see how we can get some information about the data set so this particular function will give us
informations certain informations about the data frame so mention the data frame name which is
boston df dot info so use this info function so i'll run this this will give us the
information such as the number of entries entries are nothing but rows so 0 to 5 0 5 so in python indexing starts
from 0 and not 1 so it is inch it has given us 0 so 0 to 5 not 5. so totally we have 5 or 6 values and then we have
totally 13 columns so these are all the different columns we have so the 13 columns so it's starting from zero and
we have five not six non non values so non null means these are this basically means that there are no
missing values okay so these are like uh if there is a value is not available if a value is missing then it will show it
here so like for example let's say that in this crime column uh 10 values are missing okay so in that case it will
give us 496 non non values because 10 values are missing okay so it also gives the data
type of the values so here we can see that here the value is in 64 bit floating point so floating point
are nothing but decimal points you can see the values here so this is a 64-bit floating point values okay so it also
gives the size of this file in on kb or mb whatever it is okay so this is how you can get certain information about a
data frame now you can also use this function to
find the number of missing values in each column so finding the number of
missing values so this particular info function gives us the number of real values or number of values that are
present in it okay so as you can see here the non-null count so you can find the number of missing values using this
particular function boston df dot is null dot sum this will give us the number of
missing values in each column so but as we have seen this year the the no values are missing in this
particular boston data frame okay so you can print this so as you can see here so the number of
missing values is 0 in all the columns so which is a very good thing because in several data sets there will be a lot of
missing values and mistakes should be there so in those cases we need to uh replace those
missing values with some other values so we will be discussing about this in data pre-processing module but for now just
understand that we can use this null function dot sum to find the number of missing values in a typical data frame
okay so now what we shall do is um
i want to show you some more function but i want this diabetes data frame so those
functions can be explained well in this diabetes data frame so i'll just take this
so diabetes df so let's
print this yet again diabetes
so this will print the first five rows as we know okay so now what we are going to do is
we are going to count the number of specific values so in this case you can see that see that
the labels are nothing but 1 and 0. so i have told you earlier that if one that represents that the person is diabetic
and 0 represents that person is non-diabetic so now what we are going to do is
count the values based on this particular label okay counting
the values based on the labels
so um i'll mention this type it is df
you can use this value counts function for this so value counts and in that mention
outcome so i want to count the number of zero and number of one values okay so
let's run this so totally we add about 750 values so out of those 500 values has a value of 0
and 268 values has a value of 1 so it means in this entire dataset we have non-diabetic values for 500 data
points and diabetic value for 268 data points so this is how you can count specific values in a column so you
can just use this value counts to see what are the different values and how many values are present in this say for
example if we just mention edge inside here so what happens is it will tell how many people are in the age of 50 or 31
32 etc so this is the use of this value confirmation so this is very helpful to count the values based on their labels
so in this case the labels is nothing but the outcome okay so now let's see how we can group the data based on these
labels so we are going to group the values
based on their mean okay based on the mean so mention the data frame name
diabetes df dot use the function group by
okay so in this group i mentioned the column name outcome dot mean
so let's see what we are getting okay so there is something wrong here okay so i just need to mention the
parenthesis so now as you can see here we got the two values of zero and one right so
these are the two labels we have zero and one and
so here we have grouped the values based on this outcome based on their mean value so for all the labels of zero for
all the non-diabetic people the average values for glucose level is one not mean so let's not uh look at this pregnancies
values let's look at this glucose value the mean glucose value of all the non-diabetic people is one not nine okay
so but the mean or the mean glucose value for people who are diabetic is 141 and you can also see
this change or a change in this mean value for diabetic and non-diabetic people in this insulin value so this is
very helpful for us to understand what are the different mean values for each of these labels so what is the mean
value for people having diabetes and non-diabetes so this is how you can group the
values based on their mean okay so now let's
see how we can get some statistical measures about the data set statistical measures
so these measures are very helpful for us to understand what are what is the mean of all the columns and what is the
standard deviation of all the columns and such kind of things so for this i am going to use this boston data frame so
i'll just use that here so now first we are going to see the count or number of values in
each column number of values count or number of values so i will use this boston data flame in this case
so boston df so dot count so when you use this count function it will tell us the number of values we have in each
column so as you can see here in each column we have five not six values okay and it
also gives us the data type of all the values so it is 64-bit integer in this case okay so now
let's see how we can get the mean value so mean value column wise
so boston df
dot me so this gives us the mean value for each of this column the mean value for this
crime column is 3.6 for this zone is 11.3 index is 11.11.1 etc okay so now
let's find the standard deviation standard deviation this is also column wise
austin df dot std so this gives the standard deviation column wise and
minimum value so this particular function which is min gives us
the minimum value in each column so boston df dot min so this gives us the minimum value in
each of the column and similarly we can get the maximum value as well so maximum value for each column
so boston df dot max
so these are the maximum values for all the columns okay so this is how you can get the statistical message about the
data and there is another method so instead of doing all this separately we can get all the statistical measures in
one go so all the statistical measures about the data frame
so for that you can use the function describe so boston df dot we are going to use the function describe
okay so this gives us so the count so the number of values
mean value for each of the column the standard deviation minimum value percentile values so 25th percentile 58
percentage 75 percentile and maximum values okay so this percentile means 25 percentage of
the values are less than 0.08 in this crime column and 50 percentage of the values are less than 0.25 value okay so
these are meant by percentage and these are different from percentages okay so this is how you can get all the
statistical measures like mean standard deviation etc using this describe function okay so this is one of the main
thing that we will use because it tells us an idea of what is the range and what is
the mean value of this data frame so it is very useful for exploratory data analysis now let's see how we can
manipulate a data set so manipulating a data frame
so in this we are going to see how we can uh drop a row how we can drop a column or how we can add new column to a
data frame okay so those things we will be seeing here now let's see how we can add a column
so adding a column to our data frame okay so
if you have seen before so we have imported this boston data frame from sky learn right so we have
imported all the values so all the data but we haven't imported this target value okay so this target is nothing but
the price of houses okay so the prices houses in boston in thousand dollars okay so now i'm going to add all these
values in my pandas data frame so in this boston data frame so you can see this data frame here we don't have this
last column which is price so i'm going to create a column named as price and i'm going to store all these values okay
so you can do that by so you can see here the
name of this particular target sorry the price values is target so you need to mention boston data set dot target so
before we have used boston data set dot data to get all those data now i'm going to use this dot
target to get all the price values so this is how you can add a column to a data frame and the main thing to note
here is the number of values should be same so some boston
df mentioned give a square bracket so this will
create a column so i want to create a column named as price okay so this price is equal to
boston data set so this is the data set that we have imported from sklearn okay so boston data set dot target
okay so this is the price value okay so now let's see the end of this data frame so
boston.df.eight so now you can see that there is another column called as price so this is the
last column so this dataset is basically used to predict the price of the house given all these data okay so you can see
the previous data frame of this boston data set so that is not this price column right so we have added a new
column so the main thing to note here is the number of uh values should be same so we have totally fine or six data
punch so this price column also contains five or six data points so if the number of values is uh different we cannot do
that okay so this is how you can add a column and now let's see how we can remove our
row and how we can remove a column so removing a particular row
so mention the data frame name so boston data frame so boston df dot drop so this drop function is used
to drop a particular row or column anything so let's see how we can uh drop row first
so you here you need to mention the index so index is nothing but this number okay
0 1 2 3 4 it's like the serial number so you want to remove the first index which is the first row okay so you need to
mention the index is zero so you can see the index here so i want to remove this first row for now and you need to
mention the axis as zero okay so if you want to remove a row you need to give access is equal to zero and if you
want to remove a particular column you need to give the axis as one so let's run this and see
now you can see here that this zeroth row which is the first row is removed and the data frame starts from the first
row which is the second row basically so this is how you can remove a particular row mentioning their index number okay
so now let's see how we can drop a column so mention the data frame name which is
boston df dot drop and in that mention the name of the
column so let's say that we want to uh remove the column is a 10 okay so the zone value so i'll do that now
by using column dot sorry boston df dot drop and in the column variable you need
to mention the name of the column so let's say i want to mention this zone is a 10 so you can see the name of the
column here and as i have told you earlier if you want to remove a column you need to give the axis value as 1 so
if you want to remove a row you should give access value as 0 so this will remove the zone column
okay once again so it should be columns so now you can see there is not this is
a 10 column so we have removed this one column and now we get a data frame without this is a 10 column okay so
now let me show you another thing how you can locate
particular rows or locate particular columns let's say that we want to uh locate this particular second row so
second this is basically the third row which is given by the index two so i'm going to show you how you can print this
particular row using this index value okay so locating a row
using the index value mention the data frame name boston data frame
oh sorry boston df dot i look so this i lock function is used to locate a particular row or
column so let's say that i want to print this third row the index of which is 2 okay
so i'll run this so this gives us all the values in uh the second row so this second row or
sorry the second index which contains values from point zero two seven nine seven seven point zero seven so all
these values will be printed okay so now let's see how we can locate a particular column
so if you note here in this data frame so we have removed the particular row okay so this won't be
saved here so we have removed this 0th row but in this case
it it it's coming again so if you want to remove that permanently you can just create another variable another data
frame name as boston df2 okay so what happens here is so that row will be removed and we we will get a
new data frame without that row so i just want to remove these rows and columns temporarily since i can do this
method okay so same with the column as well so now we get the zone column again because we haven't permanently deleted
it so if you want to delete it permanently you can store it in a different data frame okay so now let me
show you how you can build specific columns locating
a particular column so i'm going to print different columns
so mention the data frame name boston df dot me look so you need to mention the
square bracket here colon comma and 0 so if you do this you will get
the first column so i will just make a comment about this so what is when by this particular language it prints
the first column of the data frame okay so you can just
do this again ok so i will just change this to
this will mention minus okay so as i have told you earlier in in python indexing starts from zero so the index
of this first column is zero okay where it is okay so the index of this first column prime is zero and this is a 10 is
1 2 3 and it goes on okay so i am printing this column specifically by mentioning their index number so if
you want to print only the columns alone you just need to uh mention this value behind this column and comma okay so now
so this particular line will give us sorry so it will give us the value of second column
and this will give all the values for the third column and when you use minus one it gives all
the values for the last column okay so last column values so here the last column is nothing but the price right so
let's try to print this so it will give all the values so we cannot uh show all the values in this output hence it has
shown this dot three dots so basically all the values are in between it so we have printed the first column which is
uh crime rate so you can see the crime value starts from point zero zero six three so
this is the crime rate so which is the first column so you can also see the name of this particular column so by
using this index value i am printing the all the values in that particular column including the name of the column so
similarly i printed all the columns and finally i have printed the last column using the index minus one here the last
column is nothing but price okay so this is how you can locate a particular row or a particular column so this is the
final thing which we are going to discuss here in pandas which is correlation
so i'll explain you what is meant by this correlation but basically there are two types of correlation
positive correlation and negative correlation so you can see the data frame here
so we have totally 13 columns right so totally we have 13 columns so
we call this columns as variables also so this these are nothing but 13 variables so
like excluding the sorry including the price we have totally ah 14 columns so 14 columns are
14 variables so correlation is nothing but the correlation is used to find the relationship between these various uh
columns let's say for example let's consider this crime rate and price so we can say that the time rate and price are
negatively correlated because if the crime rate increases in a city the price of house in that particular area will
definitely decrease right so one value or one variable decreases in one value when one variable increases so this is
known as negative correlation okay so like this we have positive correlation so positive correlation are cases in
which one value increases if the other value increases okay so let's see let's consider the number of rooms in a house
if the number of hours in a room increases the price of that particular house also increases rate then in that
case the number of rooms and price these two variables are positively correlated but in the case of crime and price both
the variables are negatively correlated so this is nothing but the correlation so you can also
find the correlation of a data frame by using this particular function so i'll mention the data frame name here so
boston df dot core so this function will give us the correlation value so negative
correlation value means they are negatively correlated so you can see all the columns column names here and here
as well so all the values will be all the columns will be compared to other columns as well so let's consider this
first row so here the crime value or the crime column is matched with this price column okay so you can see a negative
value so negative value means it is negatively correlated so if one value increases if crime value increases the
price value decreases by minus 0.3 so you can see this positive correlations here so we have a positive correlation
of 0.36 here so for this zone column if this particular column zone column
increases the price also increases so these are positively correlated so you can see this rm so this is nothing but i
think it's the number of rooms so if the number of rooms increases the price also increases so it is positively correlated
so this correlation value is very important for us because it tells us which columns or which features are very
important for analysis okay so it tells us which columns are related to each other which
columns are related to the price of that particular house so this helps us to understand more about
the data understand more about that particular features okay so we can also visualize this in a heat map
which will be discussing in a different video so that is all about pandas data frame okay
so this is how you can create a data frame and how you can ah inspect a data frame such as uh the shape of the data
frame printing the first five rows of the data frame and such kind of things and i have
also explained you how you can manipulate the data in a data frame by removing a particular row or adding a
particular column and such kind of things and also finally we have seen how we can find the correlation between the
data frame okay so i hope you understood all the things we have covered in this video
hello everyone i am siddharthan welcome to my youtube channel in this video i would like to give you a detailed
tutorial on matplotlib library in python okay so as you can see here i have mentioned here that matplotlib is very
useful for making plots and graphs okay so often in machine learning and data science we will deal with immense amount
of data and it is not possible to derive meaning from this data by just looking at this raw data but when we plot this
data in plots and graphs it gives us important insights from the data okay so this is where matplotlib library comes
into picture so in this video i'll explain you detailee about various functions and plots that we can make in
math broadly library okay so before getting into the video i just give you a quick introduction about my
channel so this is my youtube channel and here i'm making ants on machine learning course with python so you can
see the introduction video here so here i have mentioned the course curriculum so you can see about the videos which i
am going to post in the future so i will be posting three videos per week two videos will be on
monday evening and wednesday evening and these videos will be in the course order and friday i will be posting one machine
learning project every week okay so you can download the course curriculum from here so it contains all the details and
you can also join my telegram group where i will post regular updates about my videos okay so i'll give the link for
my telegram group in this video so you can go to this playlist here so currently we are in the third module so
this is my machine learning course so in the first module i have explained about all the machine learning basics like
supervised running unsupervised learning deep learning etc so in the second module i have made videos on python
basics okay so you will find videos or all the basic things you need to know in python programming okay
so this is the model now we are currently working on so in this module i have already posted two videos so these
two videos are numpy tutorial and pandas uh tutorial okay so and then we have machine learning project videos so i
will be posting project videos every friday as i have told you before and now we are currently in this third module so
subscribe to my channel and stay connected and follow this course okay so now get into this today's video so this
environment is called as google collaboratory so if you are new to google collaboratory and if you haven't
know like you if you don't know how to use it you can check out my uh google collaboratory basics video so it will be
in this second module so as you can see here in this 2.1 i have explained how you can
access google collaboratory and how you can use it okay so it basically runs python programs okay so now let's get
into map broadly okay so first of all let's see how we can import matplotlib library
so if you put ash in your code it means it means like you are writing some comment about your code okay so it's
always uh important and you know essential to write comments about your code of what you're trying to do so it
helps a third person to see your code and understand what you're trying to do okay so now we are going to
import so importing matplotlib library okay
so import math plot lip
dot pi plot okay so pi plot has pld so pi plot is nothing but python plot so i am just
you know instead of using this map lib dot pi plot i just want to use it in a short form so that's why i have imported
it it has plt so it is the general convention in python so we import uh matplotlib.pipelot as plt okay
so now you can run this so you can run this particular cell by pressing shift plus
enter so it will run this code and it will automatically goes to the next cell okay so as i have told you earlier
matplotlib is useful for making plots but we need data for plotting right so when we are working on machine learning
projects we will have the data set which we will use to plot a graph so now let's take some random values so for that we
need numpy library so i have already made a tutorial on numpy library so you can also check that one if you are
new to numpy so import numpy to get data
for our plots okay so import numpy
as np so the general convention of importing number is np okay so let's import numpy snp now we are going to get
some data okay so let's say that x is equal to so let's get some values for x and let's also get some values for y so
let's say that x is equal to np dot lin space okay so this particular lin space live lin space function is
present in this numpy library so as you can see here i have imported it as mp so i'm using this linspace function in
numpy library and in this i'm going to mention 0 comma okay so what happens is it gets equally
spaced values between 0 and 10 okay and how many values it takes it takes android values so we will get evenly
spaced 100 values that lie between 0 and 10 okay so that's why i'm using this linspace function
and so we will have 100 values in x okay so now i'll create y and now what is this y is
so y is the sign okay so sine means like we have uh we have read about this in trigonometry right so np dot sign x so
this will uh find so this will take x as the angle and you will find the sign value for all those angles okay so np
dot sign is the function that gives us sign value of this particular angle okay so let's also take easier so is it let's
check that it is cosine value of x okay so x is the values between 0 and
10 so evenly spaced under values and y is the sine value of those standard values and is it is the cost value of
all those android values okay so let's run this so press shift plus enter now let's print x y and z
so i'll show you how these values are so we will get evenly spaced floating point values so totally we will have 100
values here so this is the values of x okay so now let's try to print y print y so this will give the sign value
of all these values okay so these are the sign values okay so you can also
print z similarly so is it is nothing but the cosine values as you can see here it is np dot cos it is cosine value
okay so now let's try to plot this okay so i'll make a text here
so plotting the data so as you would have guessed by now that
if we plot x and y we will get a sine curve and if we plot x and e z we will get a
cos wave okay so here we will get a sine wave and here we will get a cost name so let's do that so we are going to
build a sine wave so what you need to do is so
as we have seen that we have imported this map.lab.pipeplot as plt and this is what this plt is what we are going to
use to make plots so i'll mention it here plt dot figure
okay so this will create a empty plot a empty figure okay so and in that figure i want to
plot two values x and y okay so x are values between 0 and android and y is the sign value of all those values okay
so this will plot the graph of x and y and you need to mention this function
plt dot show so this will print our plot so i'll run this okay so there is some error in this so
plt dot figure x comma y okay so we should not use figure so it's plt dot plot
okay so plt dot plot xy plt dot show so as you can see here we have got a sine wave because x is all these values
between 0 and 10 and this y is nothing but sine value of all these values so if we don't mention what
kind of plot we want so it will give us a line plot so this is a line right so all the
points will be plotted and it will be joined by a line so we will get a sine wave because we have y is nothing but
the sine value of x now let's similarly build a cosine wave
so sorry cosine wave
it's the same function which is plt dot plot the only difference is that now we are
going to plot x and e z because is it is the cosine value of x so again mention plt dot show
okay as you can see here now we got a cosine wave okay so this is how you can get some values for x and y or z and you
can plot those values using matplotlib library okay so now uh if you see this graph it is not
complete right so this graph does not have any title it doesn't tells us that what is this x-axis and it does not tell
what is this y-axis now we can also add x label y label under title to our graph or to our plot okay so let me explain
how you can do that so adding
title x-axis and
y-axis labels okay so let's again plot the sine wave which
is x and y so plt dot plot so mention x comma y and
plt dot x label so this x label function helps us to give a x label value so i want the x label to be angle because x
is nothing but the value of angles right so we are finding the sine value of all these angles so x
label let it be angle and plt dot y label is the function to name our y axis so y level let it be
um sine value and let's name our plot as sine wave okay so plt dot title
so this title function is just to give a title to our graph so this title is sine wave
okay so now it's the same plt dot show so let's run this as you can see here we have plotted this
sine wave but in this case we have x label which tells us it is angle and y axis is nothing but sine value and the
title of this uh plot is sine wave so you can similarly change uh the title x level and viably anything you want okay
so this is how you can give names for the x-axis y-axis and title for the plot okay so now we have successfully
plotted sine wave and cosine wave now let me tell you how you can you know plot a
parabola okay so parabola
let's take x as np dot lin space so line space is the function
which gives us numbers between particular range okay so i want in this case the numbers between minus 10 and
plus 10 and i want 20 values okay so this will give us 20 equally spaced values between minus 10 and plus 10 okay
and let's say that y is equal to x into
so this means x power 2 or x square okay so this will give us a parabola curve okay
so let's plot this plot sorry plt dot plot and x comma y
plt dot show okay so i'll run this as you can see here this gives us a
parabola so this is how you can construct a parabolon this is the equation for it so similarly uh you can
give x label and y label and title to this graph when you are practicing it okay so now
let me tell you how you can so this is a line plot right so as i have told you earlier if you don't mention what kind
of uh line you want it will just take the default value as line okay so now i tell
you how you can plot this with dots and other symbols okay so now let's plot this same parabola so let
this x and y values be the same values so you can also print the x and y values and see so
now i am going to plot it with the different symbols so plt dot plot and
i want to plot x and y and i want to plot this in red color and i
want to use the plus symbol okay so plt dot show
so as you can see here it will plot the parabola but in this case it will uh plot with the plus symbol as i have
mentioned here so r represents red color okay so it uh plots with red colored plus symbol so you can also use other
symbols as well so for example plt dot plot
x comma y and in the codes let me put g and dot so it means it will
plot with dot symbol okay and the dots will be green in color so plt dot show
so as you can see here now the values are plotted in green dots so this is how you can plot uh graphs with the
different symbols and colors there is also another thing so let's do another thing as well so plt dot plot
x comma y comma let's see
r and x so this will plot the values with exmark so plt dot so this is nothing but rx so that means
x symbol and r which means red color so there are similarly various symbols and colors so you can
refer matplotlib documentation just you can just search matplotlib documentation in google so it will take you their
official site where you will see the explanation for all their functions and other things as well so there you can
see what are the different colors and different symbols you can use for these uh particular plots okay
so now i'll tell you how you can plot multiple uh graphs or multiple lines in a single graph
so let me take x as np dot
in space now let's take the values from minus 5 to
plus 5 and in this case i want 50 values okay so i want values from 5 minus a to plus
5 and 50 equally spaced values and i'm going to plot so in the before cases so previously we
have seen so we will get a value for x and we will get a value for y right so you can just
do it in a simple way by this so you can see here plt dot plot
let's say in the first graph i want x value and sine value of x so i can mention it here
instead of just putting y and giving that mp dot sign so i can just give it here so np dot sign x this will plot x
and sine of x okay and i want the graph to be g and let's put iphone here so it means
it will uh this represents green color line okay a normal line okay so this is
what we will get so this is a sine wave and in that graph i want to plot another thing as well so plt dot plot i
want to plot x and np dot cos okay of course and
in this case i want a red color dotted line so by mentioning two iphone here so it will give us a dotted line graph so
plt dot show so now let's see what we are getting as you can see here we have two gaps in
this particular plot so we have made a straight a solid line using this green color and vm dot limb using our uh using
this uh np dot cos function okay so this is how you can plot multiple uh lines in a particular or in a single plot okay so
now let me explain you another type of code so this is bar plot okay so bar plot is also very important in data
science and machine learning so it will give us several insights so you can also watch my project videos
where i have you know implemented these bar graphs in different projects so now we are going to see about bar plot
so let us create a variable as figure so figure is equal to plt dot figure so this will create a empty plot and in
that empty plot we will do several things so mention ax so ax represents axis
so figure so mention this uh variable we have used which is figure so in this
figure we are storing this plot okay so figure dot add axis add axis
0 comma 0 1 comma 1 so what is this is this will enclose our
plot in a rectangle so this first two zeros represents the coordinates so zero and zero means switch the origin and one
and one represents the height and width of the rectangle so it is generally you know it's usually to mention
uh the area in which we want to have our plot okay so in this case we have uh used this plot function so we don't need
to mention those axes but here we are just creating an empty figure and adding access to it so that's why we are adding
this access function here so as i have told you this 0 and 0 is original one and one command represents the width and
right of this plot which we want okay so i'll create another variable called as languages
okay so language is equal to let's take five languages so let's say english
and let the second language be fringe and let's take spanish
and latin and finally german so we took five
languages okay so let's say that we have a group of people and in that group uh people speak five languages okay so
let's say that there are about 100 people and now uh that hundred people you know some number of people speak
english french and a few people speak spanish latin and german okay so let's give some random
numbers for these languages people speaking languages so people so
i'll create another uh variable as list so this is basically a list so list will be enclosed in square
bracket so let's create another list so let's say that there are totally 100 people who are speaking
english and let's say that 50 people are speaking french and 150 people speaking spanish
40 people speaking latin and just some random numbers let's say 70
people are speaking german so as you can see here i have enclosed these values in uh quotes because you need to mention
sorry you need to include the strings or the text in codes but you don't need to uh you know enclose the numbers or
integers in the codes okay so we have created two list one is languages and the another one is people so we have 100
people uh speaking english 50 people speaking french and other things as well okay so now let's plot this in a bar
graph and see what we can do so a x dot bar
i want to plot languages and people okay
so i'll give x label as let's say x label is languages so let me put all in caps
and go edges and i want y label to be
number of people right so it's number of people
okay so now we can print this graph using plt.show okay so
i'll run this so this will put all these values in background so this tells us you know
which language is spoken more and which language is the second and third those kind of things okay so when you have you
know 100 or more data points it is very useful to plot all those values in these kind of bar plots okay so it tells us
how many uh categories are there and how many people are there in uh such categories okay so
it helps us to you know visualize the magnitude of that particular value okay so for spanish it is huge of course so
those kind of things so in several cases in data science and machine learning we use these bar graphs to understand about
the data okay so this is known as data visualization so in data visualization we use several plots and analysis and
this is one of the important plots which we will use okay so now let's discuss about another important uh
plot which is a pie chart okay so pie chart is very useful to find the distribution of the data in the entire
data set okay so now we are going to build a pie chart and let's create a figure as figure one
so figure one is equal to plt dot figure so it is the same procedure
so plt dot figure and i'll create access as so it's figure one dot add axis
so it's the same axis which is zero comma zero and one comma one so it is the general uh value used you can also
change it and see it so i just copy these values so
okay so i'll paste this here so now let's see how we can plot a pie chart okay so you
can use the function so in a x or x we have you know use this add access so on that we are going to build a pie chart
okay so a x dot i so this will create a pie chart and mention what you want here so people so
i want to you know built a pie chart containing the number
of people okay so people and i want the labels to be languages so labels is equal to
