Skip to content

Instantly share code, notes, and snippets.

View eLtronicsVilla's full-sized avatar
💭
love to write code

eLtronicsVilla eLtronicsVilla

💭
love to write code
View GitHub Profile
@eLtronicsVilla
eLtronicsVilla / mean_calculation.py
Last active February 27, 2019 12:23
mean calculation on given data set
# 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)
@eLtronicsVilla
eLtronicsVilla / median.py
Created February 27, 2019 12:38
Calculate the median of the given data set
# 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:
@eLtronicsVilla
eLtronicsVilla / mode.py
Created February 28, 2019 13:40
Calculation of mode on given data set
# 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 ]
# 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))
# 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]
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"""
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"""
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):
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):
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.