L O A D I N G ## Machine Learning with Python – 01M0 ## DAY 1 Intro Video

`print('5+3=',5+3)  #comment 1#practice day 1var1 = 45print(type(var1))  #<class 'int'> integer# we have 5 basic types of data (datatypes)var1=55.0print(type(var1))  #<class 'float'>var1 = 3jprint(type(var1))  #<class 'complex'>print(3j * 3j)  #(-9+0j)var1="Hello"print(type(var1))  #<class 'str'>  stringvar1=True  #Falseprint(type(var1))quantity = 53price = 119.77total_cost = quantity * price#The total cost of 50 pens costing 119 is total_costprint("The total cost of",quantity,"pens costing",price,"is",total_cost)#format string - f stringprint(f"The total cost of {quantity} pens costing {price} is {total_cost:.2f}")name1 ="Rohit";country="India"position="Captain"print(f"Player named {name1:.<12} plays for {country:X^15} and he is {position:>15} of the team")name1 ="Mangwabate"country="Zimbabwe"position="Wicket-keeper"print(f"Player named {name1:<12} plays for {country:^15} and he is {position:>15} of the team")var1,var2 = 50, 60`

## VIDEO 2 Basic Python Programming

`print("I am here");print("Hello \\\n Ok \tfine",end=". ")print("How are you?"     );#str, float, int, bool, complex# \ is called escape characternum1 = 55name1 = "Sachin"#whenever you read as input, the data type will always be stringname2 = input("Enter your name: ")print(name2)num2 = input("Enter radius: ")num2 = int(num2)print(num2)area = 3.14*num2*num2print("Area = ",area)# + / - *#  // (integer division - this will give you only integer part of the division)# **  power# %(modulo -remainder)num1 = 13num2 = 5#Arithematic/math operationsprint(num1 + num2)print(num1 - num2)print(num1 * num2)print(num1 / num2) #output wll always be floatprint(num1 // num2) #output will always be intprint(num1 ** num2)  # 10 to the power 5print(num1 % num2)  #modulo -`

## VIDEO DAY 3 PYTHON

`#logical operators: Input is bool values and output is also bool: and or not#and - even if one value is false it will give you false#or - even if one value is True it will give you true#not - opposite: not True = Falseprint(True and False)print(False or False)print(not False)num1 = 9num2 = 13print("Logical operator")print(num1 > num2 or num1 < num1 and num2 == num1 or num1 != num2 or num1!=num2)#(T)#comaprison operators: < > <=  >=  ==  !=  : True/Falsenum1 = 9num2 = 13print("is num1 equal to num2? ",num1==num2)print("is num1 not equal to num2? ",num1!=num2)print("is num1 greater than num2? ",num1>num2)print("is num1 greater than or equal to num2? ",num1>=num2)print("is num1 less than num2? ",num1<num2)print("is num1 less than or equal to num2? ",num1<=num2)r=5pi=3.14print("Radius = ",pi*r**2)# is 71 divisible by 9 ?print(71%9)#####################is x divisible by y or not?#conditions - they are used to check if its condition 1 or 2# if to check conditions followed by Conditional or logical- they only# give you True or False as outputx = 72y = 9if x%y==0:    print(f"{x} is perfectly divisible by {y}")    print("PERFECT DIVISIBLE")else:    print(f"{x} is NOT divisible by {y}")`

## DAY 4 Video

`num1 = 0if num1 >0:    print("Its positive")else:    print("Its not positive")num1 = 0if num1 >0:    print("Its positive")elif num1<0:    print("Its negative")else:    print("Its not positive")sum=448avg=sum/5print("AVG = ",sum/5)#if avg>90 - grade A# 80-90 - grade B # 70-80 - grade C # 60-70 - grade D# 50-60 - grade E #40-50" grade F  #<40 - Failif avg>=90:    print("PASS")    print("Grade = A")elif avg>=80:    print("PASS")    print("Grade = B")elif avg >=70:    print("PASS")    print("Grade = C")elif avg >= 60:    print("PASS")    print("Grade = D")elif avg >=50:    print("PASS")    print("Grade = E")elif avg>=40:    print("PASS")    print("Grade = F")else:    print("Grade = Failed")#Nested conditionsif avg>=40:    print("PASS")    if avg >= 90:        print("Grade = A")        if avg>=95:            print("You win President's medal!")    elif avg >= 80:        print("Grade = B")    elif avg >= 70:        print("Grade = C")    elif avg >= 60:        print("Grade = D")    elif avg >= 50:        print("Grade = E")    else:        print("Grade = F")else:    print("Grade = Failed")num1,num2,num3=10,15,20if num1>=num2:    print(f"{num1} >= {num2}")else:    print(f"{num2} >= {num1}")`

## VIDEO DAY 5

`#Repeating - loops in programming language# range(a,b,c): a-start number (including), b-end number (excluding), c-incrementrange(3,15,4) # 3, 7, 11,range(3,7)  # c is default 1: 3,4,5,6range(4) #a is default 0, c is default 1:  0,1,2,3# there are 2 ways loops are implemented in Python: FOR  / WHILE#for - when you know exactly how many times to runfor counter in range(1,11):    print(counter)#odd numbers between 1 and 10for i in range(1,11,2):    print(i)# even numbers between 1 and 10for i in range(2, 11, 2):    print(i)for i in range(5):    print("*")for i in range(5):    print("*",end=' ')print("\n\n")'''* * * * ** * * * ** * * * ** * * * ** * * * *'''for j in range(5):    for i in range(5):        print("*",end=' ')    print()'''*  * * * * * * * * * * * * * *'''for j in range(5):    for i in range(j+1):        print("*",end=' ')    print()'''* * * * ** * * * * * ** **'''for j in range(5):    for i in range(5-j):        print("*",end=' ')    print()'''    *     * *   * * *  * * * * * * * * *'''for j in range(5):    for i in range(5-j-1):        print(" ",end='')    for k in range(j + 1):        print("*", end=' ')    print()'''* * * * * * * * *   * * *   * *    *''''''1* 1=1   2* 1=2 ... 10*1=10...1*10=10  2* 10=20 ...  10*10'''for n in range(1,11):    for m in range(1,11):        print(f"{m:>2} * {n:>2} = {n*m:>3}",end="  ")    print()#while - when you until what condition`

## DAY 6 Video

`num = 51isPrime = Truefor i in range(2, num):    if num % i == 0:        isPrime = False        breakif isPrime:    print("Its  a prime number ")else:    print("Its not a prime number ")# print prime numbers between 1000 and 5000start, end = 1000, 5000for k in range(start, end + 1):    isPrime = True    for i in range(2, k):        if k % i == 0:            isPrime = False            break    if isPrime:        print(k, end=" , ")### WHILE LOOP#print numbers from 1 to 10i = 1while i <=10:    print(i)    i+=1choice = Truewhile choice:    print("Hello")    ch = input("Press n to stop")    if ch=='n':        choice = Falsewhile True:    print("Hello")    ch = input("Press n to stop")    if ch == 'n':        break`

## DAY 7 - While example

`#Stringsstr1 = 'Hello'str2 = "Hi there"str3 = '''Hi there how are youWhere are you?'''str4 = """I am fineI am hereHow are you"""print(str4)print(str1 + str2)print(str1 *3)for i in str1:    print(i)print(str1)#str1 = "B"print(str1, str1[-1])print(str1,str1[-5])print(str1[:3])print(str1[-3:])str1= "Hello How ARE YOU"print(str1.isalnum())num1 = input("Enter a number: ")if num1.isdigit():    int(num1)    print(num1)else:    print("Invalid number")str2= '     'print(str2.isspace())print(str2.islower())print(str2.isupper())str3 = "Hello HI There"print(str3.lower())print(str3.upper())print(str3.title())str4 = str3.replace("h","ABC",1)print(str4)str4 = str3.split('e')print(str4)str5 = "e".join(str4)print(str5)print("HI" in str3)print(str3.find("HI"))print(str3.count('e'))`

## Video 8: String Tutorial

`#Sets#data structures - collections: String, List, Tuple, Dictionary#SETS - A B M O C - there is no order# doesnt allow duplicateset1 = {2,4,6,8}print(set1)#union intersection minusset2 = {6,8,10,12}#unionprint(set1.union(set2))print(set1 | set2)#intersectionprint(set1.intersection(set2))print(set1 & set2)#differenceprint(set1.difference(set2))print(set1 - set2)print(set2.difference(set1))print(set2 - set1)#symmetric difference#union of 2 differencesprint(set1.symmetric_difference(set2))print(set1 ^ set2)print(set1, set2)#update doesnt give new set, it changes the main setset1.update(set2)#union -> update# {intersection_update, difference_update, symm_diff_update}print(set1, set2)set3 = {2,4,10,12}# sets to list and to tupleset1 = tuple(set1)list(set1)set()` ## SET DISCUSSION VIDEO

`#List - linear ordered mutablelist1 = []print(list1)print(type(list1))list1 = [2,4,6.5,"Hello",True,[2,8,12]]print("Number of elements = ",len(list1))print(list1)print(type(list1[-2]))print(type(list1[-1]))#sum and avg of 5 markslist_of_marks=[]sum = 0for i in range(0):    m=int(input("Enter marks: "))    list_of_marks.append(m)    sum+=mprint("Sum = ",sum)print("List of marks = ",list_of_marks)## 2 ways to add values to an existing list: append, insertlist_of_marks.insert(1,100)#index, valueprint("List of marks = ",list_of_marks)list_of_marks.insert(1,80)print("List of marks = ",list_of_marks)list_of_marks.insert(1,90)print("List of marks = ",list_of_marks)list_of_marks.insert(1,30)print("List of marks = ",list_of_marks)list_of_marks.insert(1,40)print("List of marks = ",list_of_marks)list_of_marks.sort(reverse=True)print("(Sort)List of marks = ",list_of_marks)list_of_marks.reverse()print("(Reverse)List of marks = ",list_of_marks)num_to_delete = 80if num_to_delete in list_of_marks:    list_of_marks.remove(num_to_delete)print("(remove)List of marks = ",list_of_marks)list_of_marks.pop(3)print("(pop)List of marks = ",list_of_marks)num_to_delete = 80if list_of_marks.count(num_to_delete) >0:    list_of_marks.remove(num_to_delete)print("(remove)List of marks = ", list_of_marks)list1 = [10,3,4,5,3,4,6,3,7,8,3,6]print(list1.count(3))print(list1.index(3))  #index(element,start,end)#index of all the values in the list:element_search = 3inx_found=0for i in range(list1.count(element_search)):    print(list1.index(element_search, inx_found), end=" ,")    inx_found = list1.index(element_search, inx_found) + 1print()list1 = [1,3,5,7]list2 = list1   #they are same , just have 2 nameslist3 = list1.copy() #copy - creates a different copyprint("1. List 1 = ",list1)print("1. List 2 = ",list2)print("1. List 3 = ",list3)list1.append(15)list2.remove(5)list3.append(19)print("2. List 1 = ",list1)print("2. List 2 = ",list2)print("2. List 3 = ",list3)# TUPLE - immutable form of Listt1 = ()print(type(t1))t1 = (1,)print(type(t1))t1=list(t1)t1.append(40)t1 = tuple(t1)#list, tuple and sets are all 3 inter convertible#advantage of tuple -its fast to accesst2 = (1,2,3)  #packinga,b,c = t2  #unpackingprint(a,b,c)#Dictionary - uses its own key to track values`

## LIST AND TUPLE DISCUSSION VIDEO

`#list, tuple, sets - linearlist1 = [2,3,4,5,2,3,4,2,3,2]list1=list(set(list1))print(list1)#Dictionary: key:value pairsd1 = {}print(type(d1))d1 = {4,5}print(type(d1))d1 = {4:"Sachin","Matches":5}print(type(d1))print(d1)print("Keys: ",d1.keys())print("Values: ",d1.values())print("(Key, Value): ",d1.items())print(d1['Matches'])d2={'City':'Mumbai'}d1.update(d2)print(d1)d2={'City':'Hyderabad'}d1.update(d2)print(d1)#deep v shallow copyd3 = d1  # deep - creates another name for d1d4 = d1.copy()print("D1 = ",d1)print("D3 = ",d3)print("D4 = ",d4)d1.update({'Sports':'Cricket'})print("D1 = ",d1)print("D3 = ",d3)print("D4 = ",d4)#remove a member: pop(), popitem()d1.pop(4)  #pop takes key as inputprint("D1 after pop: ", d1)d1.popitem() #last added value is removed - remeber last added is not same as last updatedprint("D1 after popitem: ", d1)print(" iterating through keys: ")for i in d1.keys():    print(i)print("  iterating through values: ")for i in d1.values():    print(i)print(" iterating through items")for i in d1.items():    print(i)for i,j in d1.items():    print(f"Keys = {i} and value = {j}")women = {101:"Renuka", 103:"Smriti",105:"Harmanpreet",107:"Deepti"}men = {102:"Sachin",104:"Virat",106:"Rohit"}all ={211:'Steve',222:'Warner'}all.update(women)all.update(men)print(all)for key,val in all.items():    if key in women.keys():        print(f"{val} plays in women's team")    elif key in men.keys():        print(f"{val} plays in men's team")    else:        print(f"{val} neither part of mens or womens team")`

## Dictionary tutorial video

`# SET - sets - linear unordered mutable collection - doesnt allow duplicateset1 = {'Apple','Grapes','Banana','Orange'}print(type(set1))set1.add('Cherry')set2 = {"Pineapple","Mango","Apple","Orange"}# two ways to removeset1.remove("Banana")set1.discard("Apple")#set1.remove("Rose") - if value isnt there throws errorset1.discard("Rose")  #doesnt throw errorprint("1. Set1: ",set1)set1.pop()set1.update(set2)  #unionprint("2. Set1: ",set1)set1.clear()print("3. Set1: ",set1)### SET FUNCTIONS  ####set1 = {'Apple','Grapes','Banana','Orange'}set2 = {"Pineapple","Mango","Apple","Orange"}#UNIONprint("UNION")print(set1 | set2)print(set1.union(set2))print("INTERSECTION")print(set1 & set2)print(set1.intersection(set2))print("DIFFERENCE")print(set1 - set2)print(set1.difference(set2))print(set2 - set1)print(set2.difference(set1))print("SYMMETRIC DIFFERENCE")print(set1 ^ set2)print(set2 ^ set1)print(set1.symmetric_difference(set2))#update() will update the values of main set# set1.union(set2) - this gives a new set as output# set1.update(set2) - set1 is updated with the values# union - update()set1.update(set2)print(set1)# intersection: intersection_update()set1.intersection_update(set2)print(set1)# difference_update()set1.difference_update(set2)print(set1)#symmetric_difference_update()set1.symmetric_difference_update(set2)print(set1)# set, list, tuple => they are inter-convertiblelist1 = [3,6,9,12,3,6,9,3,6,3]list1 = list(set(list1))print(list1)set1 = {'Apple','Grapes','Banana','Orange'}set1 = list(set1)set1.index("Grapes")set1 = set(set1)set1 = tuple(set1)set1 = set(set1)print(set1.issubset(set2))#list1 = [3,6,9,12,3,6,9,3,6,3]list2 = [3,6,9,12,15]#does all the elements of list2 present in list1?t_list1 =set(list1)if set(list1).issuperset(set(list2)):    print("yes, list2 value exists in list1")else:    print("No, list2 has additional elements")` `# Basic data types (stores only 1 value) - int, float, str,bool and complex# Collections (stores multiple values - 1D) - list, tuple,dictionary, set# functions - own functions - user defined functions# print(), input(), type(), int(), str(), len() : in-built functions (developers of python have already written for us)# we will learn to write our own functions#first part of writting function is to Define the meaning- functiondef mytext(val1, val2,val3):#required positional argument    print("Hello How are you today?")    print("Where are you going?")    print("I am fine.",val1)def mytext2(val1=0, val2=0,val3=9):#default positional argument    print("Hello How are you today?")    print("Where are you going?")    print("I am fine.",val1)    print("Values are: ",val1,val2,val3)#demo keyword (non-positional) argumentsdef mytext3(val1, val2,val3):#default positional argument    print("Hello How are you today?")    print("Where are you going?")    print("I am fine.",val1)    print("Values are: ",val1,val2,val3)#default argument (non-required) & keyword argument (non-positional)mytext(5,10,0)print("Done with one time calling now calling second time")mytext2(20,4,10)mytext2(20,4)mytext2(10,5,1)mytext3(val3=10,val1=9,val2=8)mytext3(100, val3=9,val2=8)#print()# numpy, pandas (Multi-D)def isPositive(val1):    #result = "Positive"  # "+ve" / 1    if val1 >0:        return 1    else:        return 0  #print("Its not Positive")res = isPositive(100)if res==1:    print("Its positive, now lets go ahead building our logic")else:    print("STOP! STOP! STOP!")isPositive(-100)isPositive(90)`

## Function Video 1

`def myfun1(val1):  #Required positional argument    print(val1)myfun1(10)def myfun2(val1,val2,val3):  #Required positional argument    print(val1, val2,val3)myfun2(10,30,20)# Default argumentdef myfun3(val1,val2=100,val3="New York"):  #Required positional argument    print(val1, val2,val3)    return val1+val2myfun3(10,30)## keywords - (non-positional)result = myfun3(val2=99,val3=77,val1=44)print("Result = ",result)## single function to perform perimeter of triangle, square, pentagon, hexagondef calcPerimeter(s1=0,s2=0,s3=0,s4=0,s5=0,s6=0):    if s1==0:        return "You have not provided any value!"    elif s2==0:        return "Perimeter of a line is the same value which is "+str(s1)    elif s3==0:        print("We cant have a closed shape with 2 only sides!")    elif s4==0:        print("Its a Triangle! Perimeter is",s1+s2+s3)    elif s5==0:        if s1==s2 and s2==s3 and s3==s4:            print("its a square with perimeter",s1*4)        elif s1==s2 and s4==s3:            print("Its a rectangle with Perimeter",2*(s1+s3))        else:            print("Its an irregular 4 sides shape with perimeter",s1+s2+s3+s4)    elif s6==0:        print("Its a pentagon with perimeter",s1+s2+s3+s4+s5)    else:        print("Its a hexagon with perimeter",s1+s2+s3+s4+s5+s6)result = calcPerimeter()print(result)result = calcPerimeter(5)print(result)calcPerimeter(6,8)calcPerimeter(8,7,5,4,3,3)def checkNum(val1):    if val1 <0:        return -1  #for negative    elif val1==0:        return 0  #zero value    else:        return 1  #positiveres = checkNum(100)if res==-1:    print("Negative")elif res==0:    print("Zero")else:    print("Positive")res = checkNum(-100)if res==-1:    print("Negative")elif res==0:    print("Zero")else:    print("Positive")`

## Function video 2

list1 = []

class Book:

num_books = 0 #class level variable

# object level method
def say_hi(self,n):
self.name=n #self. indicates name is specific to object
print(“Hi…”)
Book.num_books+=1

# class level variable
# class level method
# object level variable

b1 = Book()
b2 = Book()
b1.say_hi(“Python”)
b2.say_hi(“Django”)
print(b1.num_books)
print(b2.num_books)
print(Book.num_books)
print(“b1.name = “,b1.name)
print(“b2.name = “,b2.name)
#Book.name

## Class Tutorial - Video 1

class Library:
def __init__(self, library):
self.library = library
def _method2(self): #declared as protected
return “I am in Library!!!”
def __method3(self): #private declaration – cant be accessed outside of this class
return “I am in Library by method 3!!!”
def get_libname(self):
return self.library
class Books(Library): #Books is a derived class of Library class (base class)
title_count = 0
#__init__ – this is automatically called when object is created
def __init__(self, title, author,libname=“XYZ Library”):
Library.__init__(self,libname)
self.title = title
self.author = author

Books.title_count+=1

#get author – object
def get_author(self):
return self.author
def get_title(self):
return self.title

#count of the book
@classmethod
def get_bookcount(cls):
return cls.title_count
class Sample:
def sample_method(self):
Library._method2(self) #protected will not show up but still callable
#protected concept exists but not strictly implemented

def sample_method3(self):
Library.__method3(self) #private members are not accessible

b1 = Books(“Python Programming”,“Swapnil”)
b2 = Books(“Data Science Programming”,“Snehil”,“PQR Library”)
b3 = Books(“Blockchain”,“Ojass”)
print(“Number of books in the library = “,b1.get_bookcount())
print(“Number of books in the library = “,b3.get_bookcount())
print(“Title of the book = “,b1.get_title())
print(“Title of the book = “,b2.get_title())
l1 = Library(“ABC Local Library”)
print(“Library name = “,l1.get_libname())
print(“B1 Library is: “,b1.get_libname())
print(“LIBNAME = “,b1.get_libname())
print(“Method2 by Books: “,b1._method2())
s1 = Sample()
print(“Call by Sample: “,s1.sample_method())
#print(“Call by Sample: “,s1.sample_method3()) – throws error
# as private members cant be accessed

#print(“Method2 by Books: “,b1.__method3())- throws error
# as private members cant be accessed

## Class Tutorial Video 2

MASTERLIST = [{“ItemCode”: 101,“Item”:“Shirt”,“Price”:28.2},
{“ItemCode”: 102,“Item”:“Bag”,“Price”:18.2},
{“ItemCode”: 103,“Item”:“Book1”,“Price”:38.2},
{“ItemCode”: 104,“Item”:“Watch”,“Price”:58.2},
{“ItemCode”: 105,“Item”:“Shoes”,“Price”:128.2},
{“ItemCode”: 106,“Item”:“Laptop”,“Price”:1028.2}]
class ShoppingCart:
def __init__(self):
self.myshoppingcart = []

each_item = {}
item_name = input(“Enter the product Name: “)
not_in_list = True
for items in MASTERLIST:
if item_name==items[“Item”]:
not_in_list = False
if not_in_list:
print(“Sorry, That Item is Out of Stock!”)
else:
item_size = input(“Enter the product Size: “)
item_color = input(“Enter the product Color: “)
item_quantity = int(input(“Enter the product Quantity: “))
each_item ={“Item”:item_name,“Size”:item_size,“Color”:item_color,“Quantity”:item_quantity}
self.myshoppingcart.append(each_item)
#print(self.myshoppingcart)
def display_prod(self):
print(“Item Size Color Quantity”)
for i in self.myshoppingcart:
for k,j in i.items():
print(f”{j:<10}, end=” “)
print()

def remove_prod(self):
item_name = input(“Enter the product name to remove: “)
not_in_list = True
for items in self.myshoppingcart:
if item_name == items[“Item”]:
self.myshoppingcart.remove(items)
not_in_list = False

if not_in_list:
print(“Sorry, That Item is not in your shopping cart!”)
else:
print(“Item is now removed from your shopping cart!”)

def generate_receipt(self):
print(“Item Size Color Quantity Price”)
print(“=======================================================”)
item_cost = 0
price = 0
grand_total = 0
for i in self.myshoppingcart:
for k,j in i.items():
for master_list in MASTERLIST:
if j==master_list[“Item”]:
price=master_list[“Price”]

print(f”{j:<10}, end=” “)
if k==“Quantity”:
item_cost = j*price
grand_total+=item_cost
print(f”{round(item_cost):<10}, end=” “)
print()
print(“——————————————————-“)

print(” TOTAL: \$”+str(round(grand_total)))
print(“=======================================================”)

if __name__==“__main__”:
sc1 = ShoppingCart()
sc2 = ShoppingCart()
while True:
print(“1. View my cart \n2. Add to my cart\n3. Remove from my cart\n4. Generate My Receipt\n5. Exit”)
if ch==“1”:
if len(sc1.myshoppingcart)==0:
else:
sc1.display_prod()
elif ch==“2”:
elif ch==“3”:
sc1.remove_prod()
elif ch==“4”:
if len(sc1.myshoppingcart)==0:
else:
sc1.generate_receipt()
elif ch==“5”:
break
else:
print(“Invalid option”)

## DESCRIPTIVE STATISTICS

Descriptive Statistics – Types of Data

Quantitative Data
Numeric Data
Continuous
(Weight, Temperature,
etc)
Ratio
Interval
Data
Discrete
Qualitative Data
Categorical
Nominal
(There is no order in the values): {M, F} {N,S,E,W}
Ordinal
(There is an order): {1,2,3,4,5} {Good, Average, Bad}
Text
Data
Audio

Video

UNIVARIATE – One Variable

## Day 1 Video   