Q1)#write a function to compute the median of a vector #Example:…
Question Answered step-by-step Q1)#write a function to compute the median of a vector #Example:… Q1)#write a function to compute the median of a vector#Example: median([4,3,1,5,2]) returns 3; median([4, 3, 1, 5, 2, 6]) gives 3.5#Your code:print(median([4,3,1,5,2]), median([4,3,1,5,2,6])) Q2)#write a function called variance that takes a vector of numbers and#returns the dispersion/variance of the data#Your code:print(variance([21, 34, 11, 8, 5, 32, 12, 15, 33, 16, 18, 20]))print(np.var([21, 34, 11, 8, 5, 32, 12, 15, 33, 16, 18, 20], ddof = 1)) #verify with numpy Q3)#write a function called covariance that takes two vectors as arguments#and returns the covariance of the two#Your code:x = [1, 2, 3, 4, 5, 6, 7, 8, 9]y = [1, 2, 3, 1, 2, 3, 1, 2, 3]print(“My Function: “, covariance(x,y))print(np.cov(x,y,ddof = 1)) #returns a covariance matrix Q4)##write a function called correlation that takes two vectors as arguments#and returns the correlation of the two – this will use the function#called covariance#Your code:x = [1, 2, 3, 4, 5, 6, 7, 8, 9]y = [1, 2, 3, 1, 2, 3, 1, 2, 3]print(“My Function: “, correlation(x,y))print(np.corrcoef(x,y)) #returns a correlation matrix Q5)#Use Pandas to read data from the file iris.csv.import pandas as pd#Your code:df.head() #display first 5 records Q6)#Note that “variety” is the column to be predicted – it contains 3 unique species (Setosa, Versicolor, and Virginica)#Display the 3 species in the “variety” column?#Your code: OUT : array([‘Setosa’, ‘Versicolor’, ‘Virginica’], dtype=object) Q7)#What is the frequency of each of the species in the variety column?#Your code: OUT: Setosa 50 Versicolor 50 Virginica 50 Name: variety, dtype: int64 Q8)#provide descriptive statistics for each of the numeric columns in the dataframe#Your code: sepal.lengthsepal.widthpetal.lengthpetal.widthcount150.000000150.000000150.000000mean5.8433333.0573333.758000std0.8280660.4358661.765298min4.3000002.0000001.00000025%5.1000002.8000001.60000050%5.8000003.0000004.35000075%6.4000003.3000005.100000max7.9000004.4000006.900000 Q9)#what are the data types of the columns in the dataframe?#Your code: sepal.length float64sepal.width float64petal.length float64petal.width float64variety objectdtype: object Q10)#find the correlation among the numeric columns in the dataframe#Your code: sepal.lengthsepal.widthpetal.lengthpetal.widthsepal.length1.000000-0.1175700.871754sepal.width-0.1175701.000000-0.428440petal.length0.871754-0.4284401.000000petal.width0.817941-0.3661260.962865 Q11)#use the correlation function that you created to verify the correlation between petal.length and petal.width#Your code: Computer Science Engineering & Technology Python Programming Share QuestionEmailCopy link Comments (0)


