This file contains hidden or 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
| jupyter notebook --generate-config | |
| mkdir certs | |
| cd certs | |
| sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem | |
| cd ~/.jupyter/ | |
| nano jupyter_notebook_config.py |
This file contains hidden or 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
| c = get_config() | |
| c.IPKernelApp.pylab = 'inline' | |
| c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem' | |
| c.NotebookApp.ip = '*' | |
| c.NotebookApp.open_browser = False | |
| # Your password below will be whatever you copied earlier | |
| c.NotebookApp.password = u'sha1:941c93244463:0a28b4a9a472da0dc28e79351660964ab81605ae' | |
| c.NotebookApp.port = 8888 |
This file contains hidden or 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
| # Install R + RStudio on Ubuntu 12.04 | |
| sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9 | |
| # Ubuntu 12.04: precise | |
| # Ubuntu 14.04: trusty | |
| # Ubuntu 16.04: xenial | |
| # Basic format of next line deb https://<my.favorite.cran.mirror>/bin/linux/ubuntu <enter your ubuntu version>/ | |
| sudo add-apt-repository 'deb https://ftp.ussg.iu.edu/CRAN/bin/linux/ubuntu precise/' | |
| sudo apt-get update |
This file contains hidden or 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
| # Reading in data | |
| quiz_data <- fread('hw1_data.csv') | |
| # Column names of the dataset | |
| names(quiz_data) | |
| # First two rows | |
| quiz_data[c(1,2)] | |
| # Number of rows in data.table |
This file contains hidden or 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
| pollutantmean <- function(directory, pollutant, id = 1:332) { | |
| # Format number with fixed width and then append .csv to number | |
| fileNames <- paste0(directory, '/', formatC(id, width=3, flag="0"), ".csv" ) | |
| # Reading in all files and making a large data.table | |
| lst <- lapply(fileNames, data.table::fread) | |
| dt <- rbindlist(lst) | |
| if (c(pollutant) %in% names(dt)){ |
This file contains hidden or 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
| complete <- function(directory, id = 1:332) { | |
| # Format number with fixed width and then append .csv to number | |
| fileNames <- paste0(directory, '/', formatC(id, width=3, flag="0"), ".csv" ) | |
| # Reading in all files and making a large data.table | |
| lst <- lapply(fileNames, data.table::fread) | |
| dt <- rbindlist(lst) | |
| return(dt[complete.cases(dt), .(nobs = .N), by = ID]) |
This file contains hidden or 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
| corr <- function(directory, threshold = 0) { | |
| # Reading in all files and making a large data.table | |
| lst <- lapply(file.path(directory, list.files(path = directory, pattern="*.csv")), data.table::fread) | |
| dt <- rbindlist(lst) | |
| # Only keep completely observed cases | |
| dt <- dt[complete.cases(dt),] | |
| # Apply threshold |
This file contains hidden or 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
| export SPARK_PATH=~/spark-1.6.0-bin-hadoop2.6 | |
| export PYSPARK_DRIVER_PYTHON="jupyter" | |
| export PYSPARK_DRIVER_PYTHON_OPTS="notebook" | |
| #For python 3, You have to add the line below or you will get an error | |
| # export PYSPARK_PYTHON=python3 | |
| alias snotebook='$SPARK_PATH/bin/pyspark --master local[2]' |
This file contains hidden or 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 as np | |
| # Solving following system of linear equation | |
| # 1a + 1b = 35 | |
| # 2a + 4b = 94 | |
| a = np.array([[1, 1],[2,4]]) | |
| b = np.array([35, 94]) | |
| print(np.linalg.solve(a,b)) |
This file contains hidden or 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(datasets) | |
| library(data.table) | |
| iris_dt <- as.data.table(iris) | |
| # 1 There will be an object called 'iris' in your workspace. | |
| # In this dataset, what is the mean of 'Sepal.Length' for the species virginica? Please round your answer to the nearest whole number. | |
| # Basic data.table syntax below . | |
| #iris_dt[ essentially SQL Where class, select statement, groupby] | |
| iris_dt[Species == "virginica",round(mean(Sepal.Length)) ] |
OlderNewer