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
# Better run this in a Jupyter notebook | |
import numpy as np | |
import pandas as pd | |
green = [32, 34, 38, 28, 32, 34, 38, 28, 33, 50, 32, 39, 29] | |
red = [33, 32, 39, 29, 33, 32, 39, 29, 33, 8, 32, 39, 29] | |
green = pd.Series(green) | |
red = pd.Series(red) |
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
# Better run this in a Jupyer notebook | |
import numpy as np | |
p = 0.75 | |
passes = np.random.binomial(n=1, p=p, size=1000) | |
# Check Mean and Std for the generated data | |
passes.mean().round(3), passes.std().round(3) | |
# Take random 1000 x 10 passes (with replacement) |
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
# Bayesian Analysis for A/B Experiment with binart goals | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import scipy as sp | |
import pandas as pd | |
def bayesian_analysis(events_a, events_b, successes_a, successes_b, |
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 sklearn import svm | |
x = [[1],[4],[7],[13],[10]] | |
y1 = [16, 34, 52, 88, 70] | |
y2 = [1, 16, 49, 169, 100] | |
svm_regression_model = svm.SVR(kernel='poly') | |
svm_regression_model.fit(x,y1) | |
print svm_regression_model.predict([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
from sklearn.linear_model import LinearRegression | |
from sklearn.preprocessing import PolynomialFeatures | |
x = [[1],[4],[7],[13],[10]] | |
# Y1 = 10 + 6*x | |
y1 = [16, 34, 52, 88, 70] | |
# Y2 = x*x = x^2 | |
y2 = [1, 16, 49, 169, 100] | |
# This will convert X into |
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
# We are gonna use Scikit's LinearRegression model | |
from sklearn.linear_model import LinearRegression | |
# Your input data, X and Y are lists (or Numpy Arrays) | |
x = [[2,4],[3,6],[4,5],[6,7],[3,3],[2,5],[5,2]] | |
y = [14,21,22,32,15,16,19] | |
# Initialize the model then train it on the data | |
genius_regression_model = LinearRegression() | |
genius_regression_model.fit(x,y) |
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
def dict_load(s): | |
d = {} | |
for c in s: | |
if c == " ": | |
pass | |
else: | |
d[c] = d.get(c, 0) + 1 | |
return d | |
def dict_unload(s, d): |
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
# Let's have a list x = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]] | |
# How to convert it into x = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4] | |
x = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]] | |
# We thuse use reduce. | |
# When given a list, it goes throgu each pair of items from left to right, | |
# and applied some function on them. | |
# Remember, [1,3] + [2,4] => [1, 3, 2, 4] |
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
# Using Sieve of Eratosthenes | |
# https://en.wikipedia.org/wiki/Generating_primes | |
import sys | |
def main(): | |
num = int(sys.argv[1]) | |
num_list = [[i,True] for i in range(num)] | |
num_list[0][1] = False | |
num_list[1][1] = False |
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
# Solving this problem: | |
# http://projecteuler.net/problem=2 | |
# Sum: 4,613,732 | |
def fab(a,b, maxlimit): | |
while b < maxlimit: | |
yield b | |
a, b = b, a+b | |
NewerOlder