Professional Documents
Culture Documents
Py PPT 06
Py PPT 06
Py PPT 06
on
Machine Learning Level-1: Advanced Python & Machine Learning
Foundations
Hands-on Workshop
on
Machine Learning Level-1: Advanced Python & Machine Learning
Foundations
Data Exploration
i ons
at
plic
Ap
PC
Machine Learning
Web
Deve
lopme
nt
Numpy:
Stands for
Numerical Python
General Purpose
Array processing
package
Numpy is the fundamental package for numerical computation with Python, it contains a powerful
N-dimensional array object
Numpy:
import numpy as np
np.array()
.array() is a function to create
numpy array (array may be “dtype = float” create array data as
1D, 2D or so on) float type
Ex1: Ex2:
2D Array:
b = np.array([(1.5,2,3),
(4,5,6)])
Ex:
import numpy as np
b = np.array([(1.5,2,3), (4,5,6)])
print(type(a))
print(a)
3D Array:
c = np.array([[(1.5,2,3), (4,5,6)],
[(3,2,1), (4,5,6)]])
Ex:
import numpy as np
c = np.array([[(1.5,2,3), (4,5,6)],
[(3,2,1), (4,5,6)]])
print(type(a))
print(a)
Important Functions:
.ndim
.shape
import numpy as np
a = np.array([7,2,9,10])
print(a.shape)
reshape
Numpy Functions:
.zeros( )
np.zeros((shape of array),dtype)
.ones( )
np.ones((shape of array),dtype)
.eye( )
np.ones(No. of rows,dtype)
Numpy Functions:
.random.random( )
np.random.random((shape of array))
.random.randint( )
np.random.randint(start_value,end_value,(shape of array))
.linspace( )
np.linspace(start_value,end_value,no_of_items)
Mathematical Functions:
➔ np.add(x,y)
➔ np.subtract(x,y)
➔ np.multiply(x,y)
➔ np.divide(x,y)
➔ np.mean(x)
➔ np.median(x)
Python Program:
Pandas is an open-source
Python Library
Used for
high-performance data
manipulation and analysis
Series
➔ Series is a one-dimensional array
➔ It consists of a Homogenous Data
A 1 2 3 4
Creating Series in Pandas:
Syntax:
pd.Series(data=[ ], dtype= )
Example:
Types of Data
Ex: Ex:
● Salary ● Male / Female
● Age ● Yes / No
● Weight ● Rating
Numerical Data
Categorical Data
Nominal
Ordinal Data
Data
pd.read_csv( ‘titanic.csv’ )
titanic Dataset
Python Code
Data Accessing Methods in Pandas
1. Indexing
2. Slicing
3. Filtering
Indexing Method
.loc function
df.loc[“row1”] df.loc[[“row1”,“row2”],[“col1”,“col2”]]
Ex: Ex:
Slicing Method
df.iloc[ <row_range>,<col_range>]
Python Code
Filtering
Python Code
Data Exploration Techniques
2. Value Count ➔
4. Drop Feature ➔
5. Feature Mean ➔
6. Feature Median ➔
7. Feature Mode ➔
Map Function in Pandas:
Syntax:
df[“<column_name”] = df[“<column_name”].map(<function_name>)
Python Code:
Apply Function in Pandas
Syntax:
Python Code:
Apply using Lambda function in Pandas:
Syntax:
Python Code: