Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Prthamesh pratos

🎯
Focusing
View GitHub Profile
@pratos
pratos / meeseeks.ex
Created Sep 27, 2020
Meeseeks <link> tag problem
View meeseeks.ex
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 Oct 14, 2018
Decorator: TImeit
View timeit.py
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 Aug 2, 2018
Dockerfile : Docker for Data Science Blogpost series
View Dockerfile
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 Aug 2, 2018
Custom Dockerfile
View 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 Aug 2, 2018
Model Training R File : Docker For Data Science Blogpost
View modelling.R
#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 Aug 2, 2018
Feature Engineering R File : Docker For Data Science Blogpost
View fe-train.R
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 Aug 2, 2018
Doing EDA R File : Docker For Data Science Blogpost
View eda.R
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 Aug 2, 2018
Loading Packages R File : Docker For Data Science Blogpost
View loading-packages.R
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")
}
View ggplot.R
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 Dec 28, 2017
Matplotlib Helper Functions
View matplotlib.md

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')
You can’t perform that action at this time.