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 numpy import array | |
from keras.preprocessing.text import one_hot | |
from keras.preprocessing.sequence import pad_sequences | |
from keras.models import Sequential | |
from keras.layers import Dense | |
from keras.layers import Flatten | |
from keras.layers.embeddings import Embedding | |
# see also: https://machinelearningmastery.com/use-word-embedding-layers-deep-learning-keras/ |
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
# Define the sim_integrate function | |
def sim_integrate(func, xmin, xmax, sims): | |
x = np.random.uniform(xmin, xmax, sims) | |
y = np.random.uniform(min(min(func(x)), 0), max(func(x)), sims) | |
area = (max(y) - min(y))*(xmax-xmin) | |
result = area * sum(abs(y) < abs(func(x)))/sims | |
return result | |
# Call the sim_integrate function and print results | |
result = sim_integrate(func = lambda x: x*np.exp(x), xmin = 0, xmax = 1, sims = 50) |
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
# Leave one observation out to get the jackknife sample and store the median length | |
median_lengths = [] | |
for i in range(n): | |
jk_sample = wrench_lengths[index != i] | |
median_lengths.append(np.median(jk_sample)) | |
median_lengths = np.array(median_lengths) | |
# Calculate jackknife estimate and it's variance | |
jk_median_length = np.mean(median_lengths) |
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
rsquared_boot, coefs_boot, sims = [], [], 1000 | |
reg_fit = sm.OLS(df['y'], df.iloc[:,1:]).fit() | |
# Run 1K iterations | |
for i in range(sims): | |
# First create a bootstrap sample with replacement with n=df.shape[0] | |
bootstrap = df.sample(n=df.shape[0], replace=True) | |
# Fit the regression and append the r square to rsquared_boot | |
rsquared_boot.append(sm.OLS(bootstrap['y'],bootstrap.iloc[:,1:]).fit().rsquared) |
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
library(dplyr) | |
library(ggplot2) | |
setwd('D:\\ToyData') | |
OrginalData <- read.table("https://s3.amazonaws.com/christiandata887342ac-a3ce-4600-94d0-9092f4a6bd20/IrisTabSepData/IrisData.txt", | |
header = TRUE, sep = "\t") | |
head(OrginalData) |
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
library(dplyr) | |
library(ggplot2) | |
setwd('D:\\ToyData') | |
OrginalData <- read.table("IrisData.txt", | |
header = TRUE, sep = "\t") | |
SubsetData <- subset(OrginalData, select = c( | |
#"SepalLength" |
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 os | |
from scipy.misc import imread | |
from scipy.linalg import norm | |
from scipy import sum, average | |
def compare_images(img1, img2): | |
# normalize to compensate for exposure difference, this may be unnecessary | |
# consider disabling it | |
img1 = normalize(img1) |
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 numpy | |
import pandas | |
from keras.models import Sequential | |
from keras.layers import Dense | |
from keras.wrappers.scikit_learn import KerasRegressor | |
from sklearn.model_selection import cross_val_score | |
from sklearn.model_selection import KFold | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.pipeline import Pipeline |
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 pandas as pd | |
from fbprophet import Prophet | |
import matplotlib.pyplot as plt | |
plt.style.use('fivethirtyeight') | |
df = pd.read_csv('D:/PyCharmProjects/Prophet/Data/AirPassengers.csv') | |
df['Month'] = pd.DatetimeIndex(df['Month']) | |
#Prophet also imposes the strict condition that the input columns be named ds (the time column) and y (the metric column) | |
df = df.rename(columns={'Month': 'ds', |
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
library(dplyr) | |
library(kohonen) | |
setwd('C:\\Users\\Christian\\Source\\Repos\\RClusteringMixedDataPam') | |
OrginalData <- read.table("IrisData.txt", | |
header = TRUE, sep = "\t") | |
SubsetData <- subset(OrginalData, select = c("SepalLength", "SepalWidth", "PetalLength", "PetalWidth")) | |
#TrainingMatrix <- as.matrix(scale(SubsetData)) |
NewerOlder