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 needed libraries | |
import statsmodels.api as sm | |
import numpy as np | |
import matplotlib.pyplot as plt | |
#set hypothesis parameters | |
n = 1018 | |
pnull = .52 | |
phat = .56 | |
#apply z test | |
sm.stats.proportions_ztest(phat * n, n, pnull, alternative='larger') |
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 needed libraries | |
import numpy as np | |
import scipy.stats | |
#build a function that calculates the confidence interval | |
def mean_confidence_interval(data, confidence=0.95): | |
a = 1.0 * np.array(data) | |
n = len(a) | |
m, se = np.mean(a), scipy.stats.sem(a) | |
h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1) | |
return m, m-h, m+h |
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
# for inline plots in jupyter | |
%matplotlib inline | |
# import matplotlib | |
import matplotlib.pyplot as plt | |
# import seaborn | |
import seaborn as sns | |
# settings for seaborn plotting style | |
sns.set(color_codes=True) | |
# settings for seaborn plot sizes | |
sns.set(rc={'figure.figsize':(5,5)}) |
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 Pnadas to deal with datasets | |
import pandas as pd | |
#Dataset source | |
#https://www.kaggle.com/dipam7/student-grade-prediction | |
df = pd.read_csv('student-mat.csv') | |
df.head(3) | |
#student achieved 80% or higher as a final score | |
df['grade_A'] = np.where(df['G3']*5 >= 80, 1, 0) | |
#value of 1 if a student missed 10 or more classes | |
df['high_absenses'] = np.where(df['absences'] >= 10, 1, 0) |
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 needed libraries | |
import random | |
N = int(input("How many times do you want to play?")) # no of times you will play the game | |
start_money= 10 | |
money = start_money | |
for i in range(N): | |
money -= 1 # pay for the game | |
black = random.randint(1, 6) # throw black | |
green = random.randint(1, 6) # throw green | |
if black > green: # success? |
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
from itertools import permutations, combination | |
#Getting all permutations of a particular length. | |
seq = permutations(['b','i','r', 't', 'h'], 5) | |
#print list of permutations | |
for p in list(seq): | |
print(p) | |
#Getting all combination of a particular length. | |
combi = combinations(['b','i','r', 't', 'h'], 5) | |
#Print the list of combinations |
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 libraries to help simulate experimental probabilities | |
import random | |
from collections import Counter | |
#A function to genrate randome experiments | |
def gen(x): | |
expResults = [] | |
for i in range(x): | |
expResults.append(random.randint(1,6)) | |
return expResults | |
#An experiment with 100 events |
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 autoscraper | |
from autoscraper import AutoScraper | |
#A stackoverflow question we want to find questions related to | |
url = 'https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console' | |
#A list of a related thread to use as a guide to find similar questions | |
wanted_list = ["Assign one struct to another in C"] | |
#Collect similiar threads | |
scraper = AutoScraper() | |
result = scraper.build(url, wanted_list) | |
print(*result, sep="\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 needed libraries | |
import theano | |
from theano import tensor | |
#Define sigmoid function | |
def sigmoid(x): | |
return 1 / (1 + tensor.exp(-x)) | |
#Creating a symbolic variable | |
a = tensor.dmatrix('a') | |
#Get sigmoid of a | |
sig_a = sigmoid(a) |
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
#Example from LightGBM documentation | |
#Import needed libraries | |
import lightgbm as lgb | |
import pandas as pd | |
from sklearn.metrics import mean_squared_error | |
print('Loading data...') | |
# load or create your dataset | |
df_train = pd.read_csv('../regression/regression.train', header=None, sep='\t') | |
df_test = pd.read_csv('../regression/regression.test', header=None, sep='\t') |