Skip to content

Instantly share code, notes, and snippets.

View pratos's full-sized avatar
🎯
Focusing

prthamesh pratos

🎯
Focusing
View GitHub Profile
@pratos
pratos / meeseeks.ex
Created September 27, 2020 11:05
Meeseeks <link> tag problem
import Meeseeks.XPath
HTTPoison.start()
{:ok, response} = HTTPoison.get("feeds.megaphone.fm/tamc1029044713")
doc = Meeseeks.parse(response.body)
[first, second | rest] = Meeseeks.all(doc, xpath("item"))
IO.puts Meeseeks.tree(first)
IO.puts Meeseeks.all(doc, xpath("item//link"))
IO.puts Meeseeks.all(doc, xpath("item//link/text()")) |> Enum.map(&Meeseeks.text/1)
@pratos
pratos / timeit.py
Created October 14, 2018 03:01
Decorator: TImeit
def timeit(method):
def timing(*args, **kwargs):
timings = []
print("Running this 1000 loops, for benchmarking")
for i in range(1000):
start = time.time()
result = method(*args, **kwargs)
end = time.time()
@pratos
pratos / Dockerfile
Created August 2, 2018 12:09
Dockerfile : Docker for Data Science Blogpost series
FROM rocker/r-base
RUN apt-get update && apt-get -y upgrade && apt-get install -y \
build-essential libssl-dev libffi-dev libxml2-dev libcurl4-openssl-dev
RUN Rscript -e "install.packages(c('caret', 'tidyverse', 'gbm', 'pROC', 'corrplot', 'doParallel', 'dummies', 'futile.logger'), dependencies=TRUE)"
ENV INSTALL_PATH /germancc
RUN mkdir -p $INSTALL_PATH
@pratos
pratos / Dockerfile
Created August 2, 2018 12:08
Custom Dockerfile
FROM rocker/tidyverse
RUN apt-get update && apt-get -y upgrade && apt-get install -y \
build-essential libssl-dev libffi-dev libxml2-dev libcurl4-openssl-dev
RUN mkdir /home/rstudio/data /home/rstudio/models
VOLUME ['/home/rstudio/data', '/home/rstudio/models']
RUN Rscript -e "install.packages(c('dummy', 'corrplot', 'pROC'), dependencies=TRUE)"
@pratos
pratos / modelling.R
Last active August 2, 2018 11:59
Model Training R File : Docker For Data Science Blogpost
#setwd("~/difference-engine/docker-for-data-science-r/")
source("./src/fe-train.R")
set.seed(42)
# Parallelizing the modelling
# NOTE: Try not to use all the cores
doParallel::registerDoParallel(parallel::detectCores() - 2)
# Write the ML Code here
@pratos
pratos / fe-train.R
Last active August 2, 2018 11:58
Feature Engineering R File : Docker For Data Science Blogpost
source("./src/eda.R")
# Importing the intermediate data
flog.info("Loading the intermediate data")
german_credit <- readRDS("./assets/intermediate-files/intermediate_german_data.rds")
german_credit$rating <- ifelse(german_credit$rating == 1, "good", "bad")
# Checking for missing values
# unlist(lapply(german_credit, function(x) sum(is.na(x))))
@pratos
pratos / eda.R
Last active August 2, 2018 11:57
Doing EDA R File : Docker For Data Science Blogpost
source("./src/load_package.R")
flog.info("Loading the German Credit Card Dataset")
# Load Dataset
german_credit <- read.table("./assets/data/german.data", fileEncoding="UTF-8" , dec = ",")
head(german_credit)
flog.info("Renaming the Columns")
colnames(german_credit) <- c('status', 'duration', 'credit_history', 'purpose', 'credit_amount', 'savings_account', 'employment', 'installment_rate','status_sex', 'guarantors', 'residence', 'property', 'age', 'other_installment', 'housing', 'existing_credits', 'job', 'maintainence_people','telephone', 'foreign', 'rating')
@pratos
pratos / loading-packages.R
Created August 2, 2018 07:22
Loading Packages R File : Docker For Data Science Blogpost
list.of.packages <- c("ggplot2", "parallel", "tidyverse", "pROC", "caret", "corrplot", "doParallel", "dummies", "futile.logger")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
# Check whether the packages listed are installed or not
# If not then they are installed
if(length(new.packages)) {
print("Installing new packages")
install.packages(new.packages, repos = "http://cran.us.r-project.org")
}
require(GGally)
lm.plt <- function(data, mapping, ...){
plt <- ggplot(data = data, mapping = mapping) +
geom_point(shape = 20, alpha = 0.7, color = 'darkseagreen') +
geom_smooth(method=loess, fill="red", color="red") +
geom_smooth(method=lm, fill="blue", color="blue") +
theme_minimal()
return(plt)
}
@pratos
pratos / matplotlib.md
Last active December 28, 2017 10:36
Matplotlib Helper Functions

Creating multiple subplots to display numpy images:

def create_subplots(images, labels):
    plt.subplot()
    for _ in range(0, len(images)):
        
        plt.rcParams["figure.figsize"] = [10,20]
        plt.subplot(len(images)/2,len(images)/5, _+1)
        plt.xticks([]), plt.yticks([])
        plt.imshow(npimg, cmap = 'gray')