Skip to content

Instantly share code, notes, and snippets.

View erykml's full-sized avatar

Eryk Lewinson erykml

View GitHub Profile
@erykml
erykml / download_video.py
Created July 22, 2018 11:09
downloading youtube video with pytube
# library
from pytube import YouTube
mario_video = YouTube('https://www.youtube.com/watch?v=lXMJt5PP3kM')
# viewing available video formats
print('Title:', mario_video.title, '---')
stream = mario_video.streams.filter(file_extension = "mp4").all()
for i in stream:
print(i)
import quandl
# authentication ----
quandl_key = 'key' # paste your own API key here :)
quandl.ApiConfig.api_key = quandl_key
df = quandl.get('WIKI/MSFT', start_date="2000-01-01", end_date="2017-12-31")
df = df.loc[:, ['Adj. Close']]
df.columns = ['adj_close']
# create simple and log returns, multiplied by 100 for convenience
# parameters for the analysis
effect_size = 0.8
alpha = 0.05 # significance level
power = 0.8
power_analysis = TTestIndPower()
sample_size = power_analysis.solve_power(effect_size = effect_size,
power = power,
alpha = alpha)
# power vs. number of observations
fig = plt.figure()
ax = fig.add_subplot(2,1,1)
fig = TTestIndPower().plot_power(dep_var='nobs',
nobs= np.arange(2, 200),
effect_size=np.array([0.2, 0.5, 0.8]),
alpha=0.01,
ax=ax, title='Power of t-Test' + '\n' + r'$\alpha = 0.01$')
ax.get_legend().remove()
# for this part I assume significance level of 0.05
@np.vectorize
def power_grid(x,y):
power = TTestIndPower().solve_power(effect_size = x,
nobs1 = y,
alpha = 0.05)
return power
X,Y = np.meshgrid(np.linspace(0.01, 1, 51),
# connect to Google Drive
from google.colab import drive
drive.mount('/content/gdrive')
!pip install gdown
# create directory for storing data
!mkdir -p data
# download zip file with training set
!gdown https://drive.google.com/uc?id=1z_vO2muBgzNGIa7JtY8OPmaeUC348jj4 && unzip -qq training_set.zip -d data/training_set
!rm training_set.zip
# download zip with test set
# 1. defining parameters ----
# number of subprocesses to use for data loading
num_workers = 0
# number of samples to load per batch
batch_size = 32
# % of training set to use as validation
valid_size = 0.2
# define transformations that will be applied to images
# inspect loaded images ----
# obtain one batch of training images
dataiter = iter(train_loader)
data, target = dataiter.next()
data = data.numpy() # convert images to numpy for display
# plot the images in the batch, along with the corresponding labels
fig = plt.figure(figsize=(20, 10))
# display 10 images
# create the class containing the architecture of the network (inherits from nn.Module)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
# define the layers
# cheatsheet
# nn.Conv2d(in_channels, out_channels, kernel_size, stride=1,