0% found this document useful (0 votes)
29 views208 pages

ML Week 1

Uploaded by

Shweta Jain
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)
29 views208 pages

ML Week 1

Uploaded by

Shweta Jain
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/ 208

INTRODUCTION TO MACHINE

LEARNING WITH PYTHON


PROGRAMMING
[email protected]

SkillifyMe

SkillifyMe LinkedIn Page


MADE BY SKILLIFYME
CONTENT
01 Overview

02 What is Machine Learning?

03 Human Vs Machine

04 Applications of Machine Learning

05 Environment Setup

06 Basics of Python Programming

MADE BY SKILLIFYME
WHAT IS MACHINE LEARNING ?

MADE BY SKILLIFYME
Human can learn from past experience
and make decision of its own.

MADE BY SKILLIFYME
What is this object?

Ans :
It is a car

MADE BY SKILLIFYME
LET US ASK THE SAME QUESTION TO HIM
But, he is a human being.
He can observe and learn!

MADE BY SKILLIFYME
Let us make him learn.

MADE BY SKILLIFYME
Let us make him learn.

MADE BY SKILLIFYME
Let us ask the same question now

MADE BY SKILLIFYME
Let us ask the same question now

MADE BY SKILLIFYME
What about a Machine ?

Machines follow instructions

MADE BY SKILLIFYME
We want a machine to act like a human

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Algorithm

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
HUMAN VS MACHINE

MADE BY SKILLIFYME
MACHINE LEARNING
Refers to a computer or a Means improving at a task
system that can process by gaining experience.
data and perform tasks.

"Machine Learning" is about teaching a computer to learn from data.

MADE BY SKILLIFYME
How does Machine Learning works?

MADE BY SKILLIFYME
My first machine learning model

Teach a machine to identify


vehicle types

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Are all features useful?

MADE BY SKILLIFYME
Let us consider single feature

MADE BY SKILLIFYME
Given the #Wheel
Identify the vehicle

MADE BY SKILLIFYME
Let us estimate

MADE BY SKILLIFYME
Let us estimate the probability
(type|#wheel)

MADE BY SKILLIFYME
Ask the question now

MADE BY SKILLIFYME
More Features

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Machine Learning Workflow

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MOST USEFUL LANGUAGE
FOR MACHNE LEARNING :
PYTHON

MADE BY SKILLIFYME
Python is a high-level, interpreted programming language known for its
readability, simplicity, and versatility.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Common Uses of Python

Web Development: Frameworks like Django and Flask make it easy to build
robust web applications.
Data Analysis and Visualization: Libraries like pandas, NumPy, and
Matplotlib are widely used for data manipulation and visualization.
Machine Learning and Artificial Intelligence: Libraries such as TensorFlow,
Keras, and scikit-learn are popular for developing machine learning models.
Automation and Scripting: Python is often used to write scripts for
automating repetitive tasks.
Scientific Computing: Tools like SciPy and SymPy are used for scientific
research and numerical computations.
Game Development: Libraries like Pygame allow for the creation of simple
games and multimedia applications.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Writing your first Python Program

MADE BY SKILLIFYME
Comments in Python

Comments in Python are the lines in the code


that are ignored by the interpreter during the
execution of the program.

MADE BY SKILLIFYME
Python Variable
Python Variable is containers that store values.

Rules for Python variables


A Python variable name must start with a letter or the underscore
character.
A Python variable name cannot start with a number.
A Python variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ ).
Variable in Python names are case-sensitive (name, Name, and NAME
are three different variables).
The reserved words(keywords) in Python cannot be used to name the
variable in Python.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
VALID AND INVALID VARIABLES NAME
Var1
_var1
my_variable
_myvariable
myVariable
123hello
var!name
my#variable
class
for
return
VAR12

MADE BY SKILLIFYME
Python Data Types
Data types are the classification or categorization of data items. It represents
the kind of value that tells what operations can be performed on a particular
data.

MADE BY SKILLIFYME
1. Numeric Data Types in Python
The numeric data type in Python represents the data that has a
numeric value.

Integers – This value is represented by int class. It contains positive or

negative whole numbers (without fractions or decimals).

Float – This value is represented by the float class. It is a real number

with a floating-point representation. It is specified by a decimal point.

Complex Numbers – A complex number is represented by a complex

class. It is specified as (real part) + (imaginary part)j. For example – 2+3j

MADE BY SKILLIFYME
Note –
type() function is used to determine the type of Python data type.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
2. Sequence Data Types in Python

The sequence Data Type in Python is the ordered collection of similar or


different Python data types

Python String
Python List
Python Tuple

MADE BY SKILLIFYME
String Data Type
A string is a collection of one or more characters put in
a single quote, double-quote, or triple-quote.

MADE BY SKILLIFYME
OUTPUT

MADE BY SKILLIFYME
Accessing characters in Python String

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1

S K I L L I F Y M E
0 1 2 3 4 5 6 7 8 9

MADE BY SKILLIFYME
MADE BY SKILLIFYME
String Slicing

The String Slicing method is used to access a range of characters in the String.

Slicing in a String is done by using a Slicing operator, i.e., a colon (:).

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python String Reversed

MADE BY SKILLIFYME
Deleting/Updating from a String

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Escape Sequencing in Python

MADE BY SKILLIFYME
MADE BY SKILLIFYME
STRING FORMATTING

MADE BY SKILLIFYME
Case Changing of Python String Methods

MADE BY SKILLIFYME
MADE BY SKILLIFYME
INPUT OUTPUT IN PYTHON

MADE BY SKILLIFYME
PRACTICE QUESTIONS
1. WRITE A PYTHON PROGRAM TO PRINT YOUR NAME ,ROLL NO.
,BRANCH WITH COMMENTS.
2. YOU ARE DEPOSITING YOUR CASH IN A BANK . THE BANK WANTS TO
TAKE USER INPUT OF AMOUNT ONLY IN INTEGER VALUE .WRITE A
PROGRAM TO PRINT THIS .
3. DELETE THE CHARACTER 'E' FROM THE STRING S = "HELLO" USING
SLICING AND CONCATENATION.
4. RAM PRINTS A STRING OUTPUTS MACINE LEARNING . THE SPELLING
IS WRONG .HE WANTS TO UPDATE THIS WITH MACHINE LEARNING
.WRITE A PROGRAM TO UPDATE THIS .
5. APPLY ALL STRING FORMATTING OPERATORS TO STRING “I WANT TO
LEARN MACHINE LEARNING”
MADE BY SKILLIFYME
List of String Methods in Python

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
LIST
Lists are used to store multiple items in a single variable.
Lists are created using square brackets.

List items are ordered, changeable, and allow duplicate values.

MADE BY SKILLIFYME
Access Items

MADE BY SKILLIFYME
Note: The search will start at index 2 (included) and end at index 5 (not included).

MADE BY SKILLIFYME
Check if Item Exists

Change Item Value

MADE BY SKILLIFYME
Change a Range of Item Values

MADE BY SKILLIFYME
Insert Items

Append Items

MADE BY SKILLIFYME
Remove Specified Item

Remove Specified Index

MADE BY SKILLIFYME
Clear the List

Sort List Alphanumerically

Sort the list numerically

MADE BY SKILLIFYME
Sort Descending

To sort descending, use the keyword argument reverse = True

MADE BY SKILLIFYME
Copy a List

MADE BY SKILLIFYME
Join Two Lists

Using the + operator

Append list2 into list1

MADE BY SKILLIFYME
List Methods

MADE BY SKILLIFYME
Tuples
Tuples are used to store multiple items in a single variable.
Tuple items are ordered, unchangeable, and allow duplicate values.
Tuples are written with round brackets.

MADE BY SKILLIFYME
Create Tuple With One Item

Access Tuple Items

MADE BY SKILLIFYME
Check if Item Exists

MADE BY SKILLIFYME
Python - Update Tuples

Tuples are unchangeable, meaning that you cannot change, add, or remove items
once the tuple is created.

MADE BY SKILLIFYME
Add Items

Add tuple to a tuple

MADE BY SKILLIFYME
Remove Items

The del keyword can delete the tuple completely:

MADE BY SKILLIFYME
Join Two Tuples

Multiply Tuples

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Boolean
Represents one of the two values i.e. True or False

MADE BY SKILLIFYME
Boolean value from the expression

Integers and Floats as Booleans

MADE BY SKILLIFYME
Boolean Operators
Common boolean operations are –
or
and
not
== (equivalent)
!= (not equivalent)
Boolean OR Operator

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
PYTHON SET
Python Set is an unordered collection of data types that is iterable,
mutable, and has no duplicate elements.

Creating a Set in Python

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python dictionary

A Python dictionary is a data structure that stores the value in key:value pairs.

MADE BY SKILLIFYME
Nested Dictionaries

MADE BY SKILLIFYME
Python Operators

Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators

MADE BY SKILLIFYME
Python Arithmetic Operators

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Assignment Operators

MADE BY SKILLIFYME
Python Comparison Operators

MADE BY SKILLIFYME
Python Identity Operators

MADE BY SKILLIFYME
Python If
It is used to decide whether a certain statement or block of
statements will be executed or not.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Nested If Statement

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Check if a number is positive, negative, or zero.
Determine if a number is even or odd.
Check which of two numbers is greater.
Grade calculation based on marks.
Check if a number is divisible by both 5 and 7.
Determine and display the oldest person among four people.

MADE BY SKILLIFYME
Python For Loops
A for loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string).

MADE BY SKILLIFYME
Python For Loop with String

MADE BY SKILLIFYME
Python for loop with Range

MADE BY SKILLIFYME
Python for loop Enumerate

MADE BY SKILLIFYME
Nested For Loops in Python

MADE BY SKILLIFYME
Python For Loop Over List

MADE BY SKILLIFYME
Python For Loop with Zip()

To iterate over two lists in parallel.

MADE BY SKILLIFYME
Continue in Python For Loop
Python continue Statement returns the control to
the beginning of the loop.

MADE BY SKILLIFYME
Break in Python For Loop
Python break statement brings control out of the loop.

MADE BY SKILLIFYME
For Loop in Python with Pass Statement

The pass statement to write empty loops. Pass is also


used for empty control statements, functions, and
classes.

MADE BY SKILLIFYME
For Loops in Python with Else Statement

MADE BY SKILLIFYME
PRACTICE QUESTION 1

MADE BY SKILLIFYME
MADE BY SKILLIFYME
PRACTICE QUESTION 2

MADE BY SKILLIFYME
MADE BY SKILLIFYME
While Loop in Python
In Python, a while loop is used to execute a block of statements
repeatedly until a given condition is satisfied. When the condition
becomes false, the line immediately after the loop in the program is
executed.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Continue Statement
returns the control to the beginning of the loop.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Break Statement brings control out of the loop.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
The Python pass statement to write empty
loops. Pass is also used for empty control
statements, functions, and classes.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
While loop with else
Note : The else block just after for/while is executed only
when the loop is NOT terminated by a break statement.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python while loop with user input

It first asks the user to input a number. if the user enters -1 then the loop will
not execute, i.e.
The user enters 6 and the body of the loop executes and again asks for
input
Here user can input many times until he enters -1 to stop the loop
User can decide how many times he wants to enter input

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python while loop with Python list

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Simple while-loop exercise code to build countdown clock

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Functions
Python Functions is a block of statements that return the specific task

NOTE: The idea is to put some commonly or repeatedly done tasks


together and make a function so that instead of writing the same
code again and again for different inputs, we can do the function
calls to reuse code contained in it over and over again.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Calling a Function in Python

MADE BY SKILLIFYME
Arguments

Information can be passed into functions as arguments.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Types of Function Arguments

MADE BY SKILLIFYME
Default Arguments

A default argument is a parameter that assumes a


default value if a value is not provided in the function
call for that argument.

MADE BY SKILLIFYME
Positional Arguments

We used the Position argument during the function call


so that the first argument (or value) is assigned to name
and the second argument (or value) is assigned to age. By
changing the position, or if you forget the order of the
positions, the values can be used in the wrong places, as
shown in the Case-2 example below, where 27 is assigned
to the name and Suraj is assigned to the age.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Keyword Arguments
The idea is to allow the caller to specify the argument name
with values so that the caller does not need to remember
the order of parameters.

MADE BY SKILLIFYME
Arbitrary Keyword Arguments

In Python Arbitrary Keyword Arguments, *args,


and **kwargs can pass a variable number of
arguments to a function using special symbols.
There are two special symbols:

1. *args in Python (Non-Keyword Arguments)


2. **kwargs in Python (Keyword Arguments)

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Variable Scope

A variable scope specifies the region


where we can access a variable.

MADE BY SKILLIFYME
Python Local Variables
When we declare variables inside a function, these variables will
have a local scope (within the function). We cannot access them
outside the function.

MADE BY SKILLIFYME
Python Global Variables

In Python, a variable declared outside of the function


or in global scope is known as a global variable. This
means that a global variable can be accessed inside or
outside of the function.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Nonlocal Variables

In Python, nonlocal variables are used in nested functions


whose local scope is not defined. This means that the
variable can be neither in the local nor the global scope.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Recursion

Recursion is the process of defining


something in terms of itself.
In Python, we know that a function can call other functions. It
is even possible for the function to call itself. These types of
construct are termed as recursive functions.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Program to Find Sum of Natural
Numbers Using Recursion

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Lambda

A lambda function can take any number of arguments, but


can only have one expression.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Python Arrays

An array is a collection of items stored at contiguous memory


locations. The idea is to store multiple items of the same type
together.

MADE BY SKILLIFYME
Create an Array in Python

Array in Python can be created by importing an array module.


array(data_type, value_list) is used to create array in Python with
data type and value list specified in its arguments.

Python create array : one of integers and one of doubles.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Adding Elements to a Array

Elements can be added to the Python Array by using


built-in insert() function.

Accessing Elements from the Array


In order to access the array items refer to the index
number. Use the index operator [ ] to access an item in
a array in Python. The index must be an integer.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
MADE BY SKILLIFYME
Removing Elements from the Array
Elements can be removed from the Python array by using
built-in remove() function

MADE BY SKILLIFYME
Slicing of an Array

Slice operation is performed on array with the use of colon(:).

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Searching Element in an Array
In order to search an element in the array we use a
python in-built index() method. This function returns
the index of the first occurrence of value mentioned in
arguments.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Updating Elements in a Array
In order to update an element in the
array we simply reassign a new value to
the desired index we want to update.

MADE BY SKILLIFYME
MADE BY SKILLIFYME
Different Operations
on Python Arrays
1. Counting Elements in a Array
In order to count elements in an array we need to use count method.

MADE BY SKILLIFYME
2. Reversing Elements in a Array
In order to reverse elements of an array we need to simply use reverse method.

MADE BY SKILLIFYME
THANK YOU

You might also like