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
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 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 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 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
function snotebook () | |
{ | |
#Spark path (based on your computer) | |
SPARK_PATH=~/spark-2.0.0-bin-hadoop2.7 | |
export PYSPARK_DRIVER_PYTHON="jupyter" | |
export PYSPARK_DRIVER_PYTHON_OPTS="notebook" | |
# For python 3 users, you have to add the line below or you will get an error | |
#export PYSPARK_PYTHON=python3 |
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
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 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
#!/bin/bash | |
# stop on error | |
set -e | |
# install the required packages | |
sudo apt-get update && sudo apt-get -y upgrade | |
sudo apt-get -y install linux-headers-$(uname -r) linux-image-extra-`uname -r` | |
# install cuda 7.5 |
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
#!/bin/bash | |
# stop on error | |
set -e | |
# install the required packages | |
sudo apt-get update && sudo apt-get -y upgrade | |
sudo apt-get -y install linux-headers-$(uname -r) linux-image-extra-`uname -r` | |
# install cuda |
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
# http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/ | |
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb | |
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb | |
rm cuda-repo-ubuntu1404_7.5-18_amd64.deb | |
echo 'export CUDA_HOME=/usr/local/cuda | |
export CUDA_ROOT=/usr/local/cuda | |
export PATH=$PATH:$CUDA_ROOT/bin:$HOME/bin | |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64 | |
' >> ~/.bashrc |
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 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 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 | |
import pandas as pd | |
from sklearn.linear_model import LinearRegression | |
import matplotlib.pyplot as plt | |
# Read in csv file | |
# File: https://github.com/mGalarnyk/Python_Tutorials/blob/master/Python_Basics/Linear_Regression/linear.csv | |
raw_data = pd.read_csv("linear.csv") | |
# Removes rows with NaN in them |