Python Video Notes
Python Video Notes
ML
Subset of AI
Types
Supervised
Unsupervised
Semi supervised
Reinforcement
SUPERVISED
Training set
Test set
Training set , test set – create ML model , accuracy of model tested using test
set
2 types of supervised
UNSUPERVISED :
SEMI SUPERVISED:
Combination of supervised and unsupervised learning
We use this when we have few data points are classified while majority are
not
REINFORCEMENT:
3 major components:
PYTHON
Programmer – does not see bytecode file – that’s why python does not look
like compiled language
SCRIPTING LANGUAGE:
Interpreted directly
JAVA VS PYTHON:
Anaconda:
JUPYTER NOTEBOOK:
Uses ipynb files – which are text files with their content stored in JSON
format
DATA TYPES:
NUMBERS – immutable
Instance function – check if data type of an object matches the specified data
type
String :
Immutable
Operator:
[]
[:]
And in
Not in – returns true if character does not exist in the given string
REPLACE FUNCTION:
Split – split the string into substring based on the specified operator
LIST:
[]
Heterogeneous
Specify by indexing
SET:
DICTIONARY:
If it is there then it sit to 5th and old 5th index value is shifted to right
CONTROL STRUCTURES:
While loop :
Entry controlled loop – because it will only happen if the condition evaluates
to true at least once
Pass:
Use this when we want loop to run but no operation to be performed in the
body
FUNCTION:
PASS BY REFERENCE:
Changes to the object inside the function are reflected to same objects,
which were passed as function arguments, outside the function
** reference to the object was passed to the object rather than a copy of the
object itself
If not in same order it might no throw error but cant perform as expected
During function invocation if args is not passed then default args will be used
**kwargs
SCOPE OF VARIABLE:
Global – variables that defined outside any function or class, they accessed
anywhere within the program
When local and global variables have same name then local variables
overrides the global variables and then the function terminates then local
variables is no longer exist and then global variables are executed
Lamda function:
anonymous function
No name
Filter – assign the every value of x to list2 which the function returns true
SHALLOW COPY:
Copy a list using assignment operator leads to both list referring to same
data
Eg:
Mylist=[[3,3],[4,6]]
Newlist=mylist.copy()
However , elements within nested list are changed – that reflect in original
list also
Because , the nested list are copied by reference when performing a shallow
copy
METHODS OF LIST:
It return 1 if a>b
Return -1 if a <b
Return 0 if a=b
SLICING:
Slice by : operator
Lifo
List as queue:
Fifo
Dequeue , enqueue
List comprehension:
Testlist=[“abc”,3]
List
Output:
[‘string’,’integer’]
Creating shallow copy using : operator without specifying start and end index
Listcopy=mylist[:]
Mylist=[ ]
Tuple is immutable if you want to perform some changes then you convert
into the list and then to do it:
Tuple=list(newtuple)
Remove – we gave the value directly
del x[10]
del x[2:4]
tuples:
immutable
eg:
a=( )
print(I,j)
out:
0 10
1 20
2 30
Extending:
T=(3,4)
Print(t*2)
Len()
Count()
Min()
Max()
List inside the tuple – it should not replace because the list is part of tuple
element but content of list can be changed
Eg:
Tup1=
Tup2=
Str(res)
SET:
DICTIONARY:
Functions in dict:
COPY()
Update()
REGUALAR EXPRESSION:
Metacharacter:
\t, \n, \r, \f - tab, newline, carriage return, and form feed respectively
| - either or match
Functions :
Search() - scans the entire string looking for first occurrence of pattern
Split()
Sub()
Subn()
Escape()
Match()
Finditer()
LIBRARIES:
NUMPY
Numerical python
PANDAS:
High performance open source python library used primarily for data analysis
and data manipulation
2 ds:
Series - 1d
Data frame – 2d
2 types