This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the function formate only to calculate mean on given data set | |
price = [500,1800,4600,1200,2000] | |
def mean(x): | |
return sum(x) / len(x) | |
mean(price) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is sample code,function to calculate the median of given dataset | |
data = [2,3,4,5,6,8,9] | |
def median(value): | |
# find middle most value for even or odd data set | |
n = len(value) # find out the length | |
sorted_value = sorted(value) #sort the value | |
mid_p = n // 2 # find out the mid point | |
if n % 2 == True: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sample code to calculate the mode of given data set | |
from collections import Counter | |
d_set = [1,3,3,4,5,7,8,9] | |
def mode(data): | |
# return a list might be more than one mode | |
c = Counter(data) # count occurance of the each item | |
max_count = max (c.values()) # find out max value in data | |
return [x_i for x_i , count in c.iteritems() if count == max_count ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create the data | |
d_data = [1,3,4,5,6,7,8] | |
# Define a function | |
def data_range(data): | |
return max(data) - min(data) | |
print(data_range(d_data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generalization of median is quantile. Which represent the value less than which a certain percentile of the data lies. | |
num = [100, 49, 41, 40, 25] | |
def quantile(x, p): | |
"""returns the pth-percentile value in x data list""" | |
p_index = int(p * len(x)) | |
return sorted(x)[p_index] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
data_input = [5,6,8,12,15,18,10] | |
def mean(x): | |
return sum(x)/len(x) | |
def sum_of_squares(v): | |
"""v_1*v_1 +... +v_n*v_n""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
data_input = [5,6,8,12,15,18,10] | |
def mean(x): | |
return sum(x)/len(x) | |
def sum_of_squares(v): | |
"""v_1*v_1 +... +v_n*v_n""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
data_X = [5,6,8,12,15,18,10] | |
data_Y = [1,4,6,8,10,12,14] | |
def mean(x): | |
return sum(x)/len(x) | |
def de_mean(data): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
data_X = [5,6,8,12,15,18,10] | |
data_Y = [1,4,6,8,10,12,14] | |
def mean(x): | |
return sum(x)/len(x) | |
def de_mean(data): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def bernoulli_trial(p): | |
return 1 if random.random() < p else 0 | |
def binomial(n,p): | |
return sum(bernoulli_trial(p) for _ in range(n)) | |
# Suppose this problem, there are 9 people selected (n = number of trials = 9). The probability of success is 0.62. |
OlderNewer