Skip to content

Instantly share code, notes, and snippets.

View gr33ndata's full-sized avatar

Tarek Amr gr33ndata

View GitHub Profile
@gr33ndata
gr33ndata / Permutation Testing
Created June 14, 2020 07:13
Permutation Testing for my YouTube video about Hypothesis Testing
# 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)
# 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)
# 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,
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])
# 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)
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
@gr33ndata
gr33ndata / multiprocessing.py
Created January 18, 2014 07:58
Python Multiprocessing using Pool.map
from time import sleep
from multiprocessing import Pool
def fun(i):
if i % 2:
sleep(2)
print i
pool = Pool(4)
pool.map(fun,range(40))
@gr33ndata
gr33ndata / gist:8141155
Created December 27, 2013 01:25
This script adds a latlng() function to your Google Spreadsheets so you can easily convert addresses into latitudes and longitudes.
function latlng(address){
var response = Maps.newGeocoder().geocode(address);
if (response.status == "OK"){
var result = response.results[0];
return '' + result.geometry.location.lat + ',' + result.geometry.location.lat + '';
}
else{
return '0,0';
}
};
@gr33ndata
gr33ndata / gist:6096781
Created July 27, 2013 23:56
Quick Sort
def qsort(x):
if x == []:
return x
less = []
more = []
for item in x[1:]:
if item < x[0]:
less.append(item)
else:
more.append(item)
@gr33ndata
gr33ndata / gist:5657934
Created May 27, 2013 16:28
Code used to generate a heat map for the Egyptian textile industry. Google Geochart was used here, https://developers.google.com/chart/interactive/docs/gallery/geochart
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['City', 'Factories', 'Factories'],