Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_cond_prob/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_cond_prob/__pycache__/build.cpython-36.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions q01_cond_prob/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q01_cond_prob/build.py
# So that float division is by default in python 2.7
from __future__ import division

Expand All @@ -7,6 +8,16 @@


# Enter Code Here
def cond_prob(data):
all_houses = data.shape[0]
houses_in_OldTown = data[data['Neighborhood'] =='OldTown'].shape[0]
conditional_prob =(houses_in_OldTown/all_houses)*(houses_in_OldTown - 1)/(all_houses - 1)*((houses_in_OldTown - 2)/(all_houses - 2))
return float(conditional_prob)

cond_prob(df)






Binary file modified q01_cond_prob/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file modified q02_confidence_interval/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_confidence_interval/__pycache__/build.cpython-36.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions q02_confidence_interval/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q02_confidence_interval/build.py
# Default imports
import math
import scipy.stats as stats
Expand All @@ -10,4 +11,23 @@
# Write your solution here :


def confidence_interval(sample):
sample_size= sample.size
pop_mean=sample.mean()
z_critical = stats.norm.ppf(q = 0.95) # Get the z-critical value*

# print('z-critical value:') # Check the z-critical value
# print(z_critical)

pop_stdev = sample.std() # Get the population standard deviation

margin_of_error = z_critical * (pop_stdev/math.sqrt(sample_size))

lower_limit = pop_mean - margin_of_error
upper_limit = pop_mean + margin_of_error
return float(lower_limit),float(upper_limit)
confidence_interval(sample)




Binary file not shown.
Binary file not shown.
Binary file modified q03_t_test/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_t_test/__pycache__/build.cpython-36.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions q03_t_test/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q03_t_test/build.py
# Default imports
import scipy.stats as stats
import pandas as pd
Expand All @@ -6,4 +7,18 @@


# Enter Code Here
from statsmodels.stats.weightstats import ztest
def t_statistic(df):
deg_freedom = df['Neighborhood'].value_counts()['OldTown']-1
p=0.90
value = t.ppf(p, deg_freedom)
# result=t_statistics(0.90,deg_freedom)
result,p_value =stats.ttest_1samp(a= df[df['Neighborhood'] == 'OldTown']['GrLivArea'], popmean= df['GrLivArea'].mean())
test_result=result>value
return float(p_value),test_result

t_statistic(df)




Binary file modified q03_t_test/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_t_test/tests/__pycache__/test_q03_t_test.cpython-36.pyc
Binary file not shown.
Binary file modified q04_chi2_test/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q04_chi2_test/__pycache__/build.cpython-36.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions q04_chi2_test/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q04_chi2_test/build.py
# Default imports
import scipy.stats as stats
import pandas as pd
Expand All @@ -8,3 +9,18 @@
# Enter Code Here


def chi_square(data):
x = data.LandSlope
y = pd.qcut(data['SalePrice'], 3, labels = ['High', 'Medium', 'Low'])

freqtable = pd.crosstab(x,y)
chi2,pval,dof,expected = stats.chi2_contingency(freqtable)
crit = stats.chi2.ppf(q = 0.95, df = dof)
test_result = crit < chi2

return pval , test_result

chi_square(df)



Binary file modified q04_chi2_test/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.