0% found this document useful (0 votes)
11 views33 pages

Py PPT 06

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

Py PPT 06

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

Hands-on Workshop

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:

NumPy or Numerical Python is a general-purpose array processing python


package for scientific computing.

importing numpy library:

import numpy as np

‘numpy’ is library name ‘np’ is short-form of numpy defined using as function


Array Types:
Creating 1D Numpy arrays:

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

Numerical Data Categorical Data

Ex: Ex:
● Salary ● Male / Female
● Age ● Yes / No
● Weight ● Rating
Numerical Data

Continuous Discrete SAT Score


Data Data

Data Changes with Data within some


respect to Time numerical Range
Categorical:

Categorical Data

Nominal
Ordinal Data
Data

Categories without Data with


mathematical
weightage
mathematical
weightage
4
Data Frame
DataFrame is a two-dimensional array with heterogeneous data.
Loading .csv File in Python Program

pd.read_csv( ‘titanic.csv’ )

titanic Dataset

Python Code
Data Accessing Methods in Pandas

1. Indexing

2. Slicing

3. Filtering
Indexing Method

Accessing single column Accessing Multiple columns

df[“<column_Name >”] df[[“<column1>”,“<column2>,..”]]

Python Code: Python Code:


Indexing Method

.loc function

Access Rows Access Rows & Columns

df.loc[“row1”] df.loc[[“row1”,“row2”],[“col1”,“col2”]]

Ex: Ex:
Slicing Method

.iloc function ➔ Access Rows & Columns using index range.

df.iloc[ <row_range>,<col_range>]

Python Code
Filtering

➔ Filter the required data based on Logic.

Python Code
Data Exploration Techniques

1. Identifying Unique Elements ➔

2. Value Count ➔

3. Null Value Check ➔

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:

df[[“<col1”, “<col2”]] = df[[“<col1”, “<col2”]].apply(<function_name>)

Python Code:
Apply using Lambda function in Pandas:

Syntax:

df[[“<col1”, “<col2”]] = df[[“<col1”, “<col2”]] .apply(lambda <arguments>:<expression>)

Python Code:

You might also like