0% found this document useful (0 votes)
36 views

ML Assignment Last

This document outlines tasks for a Python assignment that is due on December 20, 2021. It includes 5 tasks: 1. Complete a free online Python course and submit the certificate. Perform exercises with lists, dictionaries, tuples, and Numpy. 2. Define functions for calculating velocity and summing even numbers. Create Matplotlib plots of sine/cosine curves. 3. Work with a Pandas DataFrame, printing rows/columns, renaming a column, and adding a column of row sums. 4. Classify data using Naive Bayes classifier based on a table of features for playing football.

Uploaded by

Usama Dayal
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)
36 views

ML Assignment Last

This document outlines tasks for a Python assignment that is due on December 20, 2021. It includes 5 tasks: 1. Complete a free online Python course and submit the certificate. Perform exercises with lists, dictionaries, tuples, and Numpy. 2. Define functions for calculating velocity and summing even numbers. Create Matplotlib plots of sine/cosine curves. 3. Work with a Pandas DataFrame, printing rows/columns, renaming a column, and adding a column of row sums. 4. Classify data using Naive Bayes classifier based on a table of features for playing football.

Uploaded by

Usama Dayal
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/ 4

Assignment

(Last)

Note:
 Submit assignment in group (3-4 Students).
 Submission of all tasks of assignment should be in hard form and each group
member should attach certificates of task 1 individually.
 Task # 3 should be written on plain white A4 page.
 Assignment submission deadline is Dec 20, 2021. Failing to submit on time
will result in the reduction of marks.

Task # 1
 Enrol in the following course https://www.udemy.com/course/free-python/
 Watch and complete above free python course and attach hard copy of
course certificate with your assignment.

Task # 2
Perform following tasks using Python
1: Lists, Dictionaries, Tuples (10 Marks)
Lists
Given a list:
nums = [3, 4, 7, 8, 15]
Make another list named cubes and append the cubes of the given list in this list and print it.
Dictionaries
You are given an empty dictionary: dic = {}
 Add the following data to the dictionary: ‘person’: 2, ‘cat’: 4, ‘spider’: 8, ‘horse’: 4 as key
value pairs.
 Use the ‘items’ method to loop over the dictionary and print the animals and their
corresponding legs.
 Sum the legs of each animal, and print the total at the end.
Tuples
Given the following tuple:
D = (1,15,4,[5,10])

 Change the value in the list from ‘5’ to ‘3’.


 Delete the tuple D.
 Given another tuple:
E = (‘a’,‘p’,‘p’,‘l’,‘e’)

 Print the number of occurrences of ‘p’ in tuple E.


 Print the index of ‘l’ in tuple E.
2: Numpy
You should use all built in functions of numpy in this task, a list is available here

 Convert matrix M into numpy array


 Use slicing to pull out the subarray consisting of the first 2 rows and columns 1 and 2.
Store it in b which is a numpy array of shape (2, 2).
 Create an empty matrix ‘y’ with the same shape as ‘M’.
 Add the vector z to each column of the matrix M with an explicit loop and store it in y.
Given:
A = np.array([[1,2],[3,4]])

B = np.array([[5,6],[7,8]])
v = np.array([9,10])

 Add the two matrices A and B.


 Multiply the two matrices A and B.
 Take the element wise square root of matrix A.
 Take the dot product of the matrix A and vector v.
 Compute sum of each column of A.
 Print the transpose of B.
3: Functions and For Loops
Function
Declare a function Compute that takes two arguments: distance and time, and use it to calculate
velocity.
Forloop
Declare a list even that contains all even numbers up till 16. Declare a function sum that takes
the list as an argument and calculates the sum of all entries using a for loop.
4: Matplotlib
Import the plotting function by the command:
import matplotlib.pyplot as plt
Plotting a single line
Compute the x and y coordinates for points on a sine curve and plot the points using matplotlib.
Use the function plt.show()
Plotting multiple lines
Compute the x and y coordinates for points on sine and cosine curves and plot them on the
same graph using matplotlib. Add x and y labels to the graph as well.
Subplots
Compute the x and y coordinates for points on sine and cosine curves. Set up a subplot grid that
has height 2 and width 1, and set the first such subplot as active. Plot the sine and cosine graphs.
Hint: Use the plt.subplot()function
5: Pandas Data Frame
Making a Data Frame
Create a data frame pd that contains 5 rows and 4 columns, similar to the one given below:
 Print only the first two rows of the data frame.
 Print the second column.
 Change the name of the third column from “Col3” to “XYZ”.
 Add a new column to the data frame and name it “Sum”.
 Sum the entries of each row and add the result in the column “Sum”.

Task # 3
Consider the table given below and classify X and X’ to find out the possibility of
Playing Football by using Naïve Bayes Classifier.

You might also like