Question
Object Oriented Programming Here, you will be creating a class CustomData that can be used to create an instance as follows: dataset = CustomData([1,3,5,7, ...])
Object Oriented Programming
Here, you will be creating a class CustomData that can be used to create an instance as follows:
dataset = CustomData([1,3,5,7, ...])
Do NOT use ANY library or package for this part. Use built-in Python operations only.
Tasks 1: Parent Class
Complete the constructor, which takes in a data_list
Complete method 1: calculate_mean that calculates the unweighted mean or average
Complete method 2: calculate_sd that calculates Population Standard Deviation
Hint: Each item here can be implemented in just 1 line of code!
class CustomData: def __init__(self, data_list): """ Constructor """ # YOUR CODE HERE # DO NOT USE ANY PACKGE
def calculate_mean(self): """ Calculates the mean of the data """ # YOUR CODE HERE # DO NOT USE ANY PACKGE
def calculate_sd(self): """ Computes Population Standard Deviation """ # YOUR CODE HERE # DO NOT USE ANY PACKGE
Task 2: Test the Parent Class
You must test the class by calling the method on the instantiated population_data object.
########################## DO NOT EDIT ########################## DATA = np.random.normal(0, 1, 1000) population_data = CustomData(DATA) #################################################################
# Calcuate the mean of population_data object # YOUR CODE HERE
# Calcuate the Population Standard Deviation of population_data object # YOUR CODE HERE
Task 3: Child Class and Override Method
Now, create a child class CustomSample. All attributes and methods should be the same. However, change (override) the calculate_sd method such that it now computes Sample Standard Deviation instead.
## Create the CustomSample class ## DO NOT USE ANY PACKAGE # YOUR CODE HERE
Task 4 Test the Child Class
You must test the class by calling the method on the instantiated sample_data object.
########################## DO NOT EDIT ########################## sample_data = CustomSample(DATA) #################################################################
# Calcuate the mean of sample_data object # YOUR CODE HERE
# Calcuate the Sample Standard Deviation of sample_data object # YOUR CODE HERE
Task 5
Compare the mean and standard deviation between population_data and sample_data objects. Describe how they are similar (same) and how they are different.
YOUR ANSWER HERE:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started