3 12 Points A Given The Following Program After You Load A Inis Dataset Which Has Four Numeric Features Sepal Leng 1 (25.88 KiB) Viewed 30 times
3 12 Points A Given The Following Program After You Load A Inis Dataset Which Has Four Numeric Features Sepal Leng 2 (30.33 KiB) Viewed 30 times
3. (12 points) a. Given the following program, after you load a inis dataset which has four numeric features: sepal length, sepal_width, petal_length, petal_width, the target feature is "class", complete the followings: (1) Fill the missing value of petal length with the feature's median value: (2) Drop all data with sepel length greater than 5.0 (3) Calculate the correlations between spal length and petal_length (4) Plot petal length and sepal length in the x y coordinate: (5) Print all data with class value being Iris-setosa and sepal-length less than 2. import pandas as pd import matplotlib pyplot as pit data-pd.read_csviris.csv") b. Define a class MyClass and implement the following functions: (1) iter() and next(). In the ter_(). define an object property counter (e.g.. self.conter-0) and another object property in which is a list, using assign n with 20 random integers between 0 and 100 using a loop or list comprehension: In the next(), each time the function is called, randomly sample a number from the list, return the value if it is odd and self.counter is <= 10: otherwise, stop and make the object no longer iterable. (2) One class method which takes one argument, in the function, check if the argument is in dictionary type. If not, prompt type error and stop (eg.. using try/except or raise error); if yes, print all the dictionary elements sorted by values. import math import random class MyClass:
b. Define a class MyClass and implement the following functions: (1) iter_() and _next_(). In the__iter_(), define an object property counter (e.g., self.conter = 0) and another object property n which is a list, using assign n with 20 random integers between 0 and 100 using a loop or list comprehension; In the next_(), each time the function is called, randomly sample a number from the list, return the value if it is odd and self.counter is <= 10; otherwise, stop and make the object no longer iterable, (2) One class method which takes one argument, in the function, check if the argument is in dictionary type. If not, prompt type error and stop (e.g., using try/except or raise error); if yes, print all the dictionary elements sorted by values. import math import random class MyClass: 3
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!