Skip to content

Instantly share code, notes, and snippets.

@ZeccaLehn
ZeccaLehn / condaRandPython.txt
Last active May 22, 2019 08:50
GCP/GCloud VM setup running R/Python using Anaconda
####### GCP/GCloud VM setup running R/Python using Anaconda ########
# Prepared as part of a guest lecture series in parallel programming and GCloud setup
# at Pepperdine University for their inaugural ML class on 3/16/2018.
# Rights: MIT Licence
## 10 easy steps: Running R/Python in the cloud
1) Log into GCP
2) Create a project (if not done already), and log into <your project> from top of screen
@ZeccaLehn
ZeccaLehn / pythonActualPrice.ipynb
Last active July 10, 2023 10:10
Py: Adjust Splits and Dividends from Real Prices using Quandl Finance Data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZeccaLehn
ZeccaLehn / downloadTree.md
Last active November 17, 2017 02:16
Download all files within directory tree in Python

Creating Zips

import shutil
import os

cwd = os.getcwd()
@ZeccaLehn
ZeccaLehn / binomialCoins
Created October 19, 2017 08:26
Likelihood and coin-flips (Combinatorics and Likelihood Connection using #rstats)
### Likelihood of getting 3 heads out of 8 flips given a fair coin
n = 8
k = 3
steps = 10001 # Non zero ending to get likelihood; best if > 10000
p_grid = seq(0,1,length.out = steps)
prior = rep(1, steps)
likelihood = dbinom(k, n, prob = p_grid)
# unstd.posterior = likelihood*prior
# posterior = unstd.posterior/sum(unstd.posterior)
# plot(p_grid, posterior)
@ZeccaLehn
ZeccaLehn / constrainedR.md
Created October 12, 2017 09:27
Constrained Optimization in R
library(mosaic)

f <- makeFun(x^2 + y ~ x & y)
g <- makeFun(x^2 - y^2 ~ x & y)

  # levelset <- 10
  # plotFun(f(x,y) ~ x & y, xlim = range(-10, 10),
  #         levels = levelset, ylim = range(-10, 10), filled = F)
  # plotFun(g(x,y) ~ x & y, levels = levelset,  xlim = range(-10, 10),
@ZeccaLehn
ZeccaLehn / installR
Created October 11, 2017 04:55
Install and Load Multiple Packages R
packages <- c("twitteR", "dismo", "maps", "ggplot2")
installAll <- packageList[!packages %in% rownames(installed.packages())]
if(installAll){install.packages(installAll, repos = "http://cran.us.r-project.org")} else {print("No Packages Installed")}
lapply(packages, library, character.only = TRUE)
@ZeccaLehn
ZeccaLehn / dynamicProbability.md
Created October 1, 2017 21:19
Binomial Probabilities in R using Manipulate Package
binomProbs <- function(w, n, propStep){

  # print(w)
  # print(n)
  # print(propStep)
  
  plot(seq(0, 1, propStep), dbinom(w, n, prob = seq(0,1, propStep)), xlim = c(0, 1),
       xlab = "", ylab = "")
 points(seq(0, 1, propStep), 
@ZeccaLehn
ZeccaLehn / monteHall.md
Last active October 1, 2017 04:48
Monte Hall Simulation -- Goat or Ferrari?
@ZeccaLehn
ZeccaLehn / returnList.md
Last active September 29, 2017 17:57
Function Returning List of Multiple Objects in R
# Function
xylist <- function(start, finish){
  
  x <- seq(start, finish)
  y <- seq(start, finish)^2
  
  return(list("x" = x, "y" = y))
  
}
@ZeccaLehn
ZeccaLehn / mtcars.csv
Last active July 7, 2023 05:53
Python Download CSV from Gist (MTCARS DataSet)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
Duster 360 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2