Question: ) Creates a function called outlier that has as parameters the list of numbers x, the number K, and the number u. List x contains
) Creates a function called outlier that has as parameters the list of numbers x, the number K, and the number u. List x contains observations of vehicle speeds in a road lane. The function must be return a list of all x-observations that are atypical. An observation is atypical if it falls outside the interval defined by: [q1 x K , q3 + K ] where q1 and q3 refer to the first and third percentiles, respectively, K is the number in parameter K and is refers to the standard deviation of the data in x. For example, if q1 = 50, q3 = 70, K =1 and =10, the interval is equal to: [50 x 1 10, 70 + 1 10] = [40, 80] In this example, all x-observations that are less than 40 or greater than 80 are atypical. The outlier function has to calculate the standard deviation of the data in x. The standard deviation is calculated with the expression: where n is the number of numbers in x and u is the average of the values in x (this value is a parameter of the function). The q1 and q3 percentiles have to be calculated using the following function: The percentile function has as a parameter a list of numbers x y returns the first and third percentile (q1 and q3) x. Assume that the percentile function is defined and can be used within the outlier function.
2 Problema 2 (15 puntos) Crea una funcin llamada outlier que tenga como parmetros la lista de nmeros x, el nmero K, y el nmero u. La lista x contiene observaciones de velocidades de vehculos en un carril de carretera. La funcin debe devolver una lista con todas las observaciones en x que sean atpicas. Una observacin es atpica si cae fuera del intervalo definido por: [91 - Kxo, 93 +K xo] donde 91 y 93 se refieren al primer y tercer percentil, respectivamente, K es el nmero en el parmetro Ky o se refiere a la desviacin estndar de los datos en x. Por ejemplo, si q = 50,93 = 70, K = 1 yo = 10, el intervalo es igual a: [50 - 1x10, 70 + 1 x 10] = [40, 80] En este ejemplo, todas las observaciones en x que sean menores de 40 o mayores de 80 son atpicas. La funcin outlier tiene que calcular la desviacin estndar de los datos en x. La desviacin estndar es calculada con la expresin: = (x - 1)^ n i=1 donde n es la cantidad de nmeros en x y u es el promedio de los valores en x (este valor es un parmetro de la funcin) Los percentiles q y 93 se tienen que calcular usando la siguiente funcin: def percentil(x): import numpy as np ql = np.percentile(x,25) q3 = np.percentile(x,75) return qi, q3 La funcin percentil tiene como parmetro una lista de nmeros x y devuelve el primer y tercer percentil (21 y 93) de x. Suponga que la funcin percentil est definida y que se puede usar dentro de la funcin outlier
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
