Question

Can you write the function in python? def remove_outliers(data, num_outliers): # When analyzing data collected as...

Can you write the function in python?

def remove_outliers(data, num_outliers):
# When analyzing data collected as a part of a science experiment it
# may be desriable to remove the most extreme values before performing
# other calculations. Complete this function which takes a list of
# values and an non-negative integer, num_outliers, as its parameters.
# The function should create a new copy of the list with the num_outliers
# largest elements and the num_outliers smallest elements removed.
# Then it should return teh new copy of the list as the function's only
# result. The order of the elements in the returned list does not have to
# match the order of the lemetns in the original list.
# input1: data (list)
# input2: num_outliers (int)

# output: list

It has to pass this test.

import random
random.seed(1234)
data = [random.randint(50, 150) for ele in range(100)]
data[45] = 1
data[46] = 2
data[90] = 250
data[34] = 300

result = [50, 50, 51, 52, 52, 52, 53, 53, 54,
55, 55, 55, 55, 56, 58, 58, 59, 59, 59, 60, 61, 61,
61, 62, 64, 64, 64, 68, 68, 68, 69, 69, 69, 70, 71,
72, 73, 75, 77, 80, 81, 81, 84, 84, 84, 85, 88, 88, 89,
92, 94, 94, 95, 95, 98, 103, 106, 108, 108, 109, 109, 109,
110, 111, 111, 112, 113, 114, 115, 115, 117, 117, 119, 121,
124, 124, 125, 126, 128, 129, 132, 132, 133, 134, 135, 135,
135, 136, 138, 140, 141, 148, 148, 149, 149, 150]

assert remove_outliers(data, 2) == result

Homework Answers

Answer #1

def remove_outliers(data, num_outliers):
copy = data[:]
copy=sorted(copy)
copy=copy[num_outliers:len(data)-num_outliers]
return copy

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What can we say about Company's current financial condition with below data between the tears 2009...
What can we say about Company's current financial condition with below data between the tears 2009 to 2015? Company A 2009 2010 2011 2012 2013 2014 2015 Collection period 51 76 59 64 70 52 67 Inventory period 47 52 55 56 62 59 56 Payment period 36 49 46 50 59 56 92 Cashtocashperiod 62 79 68 70 73 55 31 Company B 2009 2010 2011 2012 2013 2014 2015 Collection period 66 82 90 110 111 115 154...
You want to see if there is a statistical difference between the two groups. Run descriptives...
You want to see if there is a statistical difference between the two groups. Run descriptives and a two-tailed, two sample assuming equal variance t-test. Here's your data: Weight of Apples in Grams Apple ID Farm A Farm B 1 131 151 2 147 159 3 134 162 4 134 158 5 136 159 6 137 160 7 140 150 8 134 160 9 136 160 10 133 160 11 134 160 12 132 158 13 139 162 14 136...
The following data represent trunk circumferences (in mm) for a random sample of 60 four-year-old apple...
The following data represent trunk circumferences (in mm) for a random sample of 60 four-year-old apple trees at East Malling Agriculture Research Station in England.† 108 99 106 102 115 120 120 117 122 142 106 111 119 109 125 108 116 105 117 123 103 114 101 99 112 120 108 91 115 109 114 105 99 122 106 113 114 75 96 124 91 102 108 110 83 90 69 117 84 142 122 113 105 112 117...
Many standard statistical methods that you will study in Part II of this book are intended...
Many standard statistical methods that you will study in Part II of this book are intended for use with distributions that are symmetric and have no outliers. These methods start with the mean and standard deviation, x and s. For example, standard methods would typically be used for the IQ and GPA data here data215.dat. (a) Find x and s for the IQ data. (Round your answers to two decimal places.) s= Here are the numbers obs gpa iq gender...
Refer to the accompanying data set and construct a 95​% confidence interval estimate of the mean...
Refer to the accompanying data set and construct a 95​% confidence interval estimate of the mean pulse rate of adult​ females; then do the same for adult males. Compare the results. Males    Females 81           82 72           94 52           57 59           66 51           54 62           80 52           77 74           85 51           89 62           57 73           35 61           64 62           87 80           74 80           79 63           62 63           67 97           76 43           60 85           65 72           86 66           85 73           69 72          ...
A business analyst wants to know if a new website design compared to an old website...
A business analyst wants to know if a new website design compared to an old website design is showing increased page views per visit. Two different samples of customers are randomly sent to one of two different websites, offering the same products, but with different designs. Is there a difference in average page views between the new and old website design? Use data from "website" sheet in excel. Which of the following was the p-value you used for this statistical...
Open Three Hospitals data. SETUP: It is believed that the number of injuries recorded in hospital...
Open Three Hospitals data. SETUP: It is believed that the number of injuries recorded in hospital 1 is different from the number of injuries recorded in hospital 2. Given the data your job is to confirm or disprove this assertion. 10. What test/procedure did you perform? (4 points) a. Regression b. Two sided t-test c. One sided t-test d. Confidence Interval 11. What is the statistical interpretation? (4 points) a. Average of data is inconsistent with the claim b. P-value...
A business analyst wants to know if a new website design compared to an old website...
A business analyst wants to know if a new website design compared to an old website design is showing increased page views per visit. Two different samples of customers are randomly sent to one of two different websites, offering the same products, but with different designs. Is there a difference in average page views between the new and old website design? Use data from "website" sheet in excel. Run the appropriate statistical test using α=0.01 . Which of the following...
Taxpayer Form 1 Form 2 Form 3 Form 4 1 109 115 126 120 2 98...
Taxpayer Form 1 Form 2 Form 3 Form 4 1 109 115 126 120 2 98 103 107 108 3 29 27 53 38 4 93 95 103 109 5 62 65 67 64 6 103 107 111 128 7 83 82 101 116 8 122 119 141 143 9 92 101 105 108 10 107 113 127 113 11 103 111 111 108 12 54 64 67 62 13 141 145 142 160 14 92 94 95 102 15...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that inserts 20 random integers from 0 to 100 in order in a linked list object. The program will create another linked list, but with 15 random integers from 0 – 100 in order. The program then will merge those two ordered linked list into a single ordered list. The function merge should receive references to each of the list objects to be merged and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT