Skip to content

Instantly share code, notes, and snippets.

datatypes <- function(dataframe){
types <- split(names(dataframe),sapply(dataframe, function(x) paste(class(x), collapse=" ")))
return(types)
}
factor_cols <- c()
raw_data[,factor_cols] <- lapply(raw_data[,factor_cols],
function(x) factor(x))
get_metrics <- function(model, test_data, truth, table = FALSE){
preds <- predict(model, test_data);
table_ <- table(truth, preds);
acc_ <- sum(diag(table_))/sum(table_);
rec_ <- table_[2,2]/sum(table_[,2]);
prec_ <- table_[2,2]/sum(table_[2,]);
f_ <- 2*rec_*prec_/(rec_+prec_)
if (table == FALSE){
cat('Accuracy:', acc_, '\nRecall:', rec_, '\nPrecision:', prec_, '\nF-Score:', f_);
} else {
test_train_split <- function(data, train_frac = 0.66){
library(caret)
inTrain <- createDataPartition(1:nrow(data), p = train_frac, list = FALSE)
training <- data[inTrain,]
testing <- data[-inTrain,]
return(list(train = training, test = testing))
}
@sizhky
sizhky / .inputrc
Last active May 22, 2017 11:51
Conditional history
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = 5, 10
%matplotlib inline
@sizhky
sizhky / basic_charts.py
Last active July 26, 2017 11:23
Matplotlib simple charts
########################################
'''Simple Bar Chart'''
x_axis=['a','b','c']
y_axis=[10,12,11]
fig, ax = plt.subplots(figsize=(20, 8))
ax.set_xticks(range(len(x_axis)))
ax.bar(range(len(x_axis)), y_axis, align='center')
ax.set_xticklabels(x_axis, rotation='vertical')
@sizhky
sizhky / .cvimrc
Last active November 24, 2017 06:26
My cVimrc
map h :help
let mapleader = ','
let blacklists = ["https://vim-adventures.com/*","http://localhost/*","https://youtube.com/*","http://www.kongregate.com/*"]
map <Leader>e :tabopen chrome://extensions<CR>
map <Leader>E :tabopen https://chrome.google.com/webstore/category/extensions?hl=en<CR>
map <Leader>H :tabopen chrome://history<CR>
map <Leader>gg :tabopen https://gist.github.com/sizhky/6ce05580f394742fcd45c4bf1f5c18d6<CR>
map <Leader>s :tabopen chrome://settings<CR>
" let searchalias g = "google"
map <Leader>m :tabopen https://mail.google.com/mail/#index<CR>
set number
@sizhky
sizhky / jupyter_hack.txt
Last active November 23, 2017 05:58
reduce margins in jupyter
.container { width:97.5% !important; }
~/.jupyter/custom/custom.css
https://stackoverflow.com/questions/21971449/how-do-i-increase-the-cell-width-of-the-jupyter-ipython-notebook-in-my-browser
@sizhky
sizhky / Bugs.R
Created December 16, 2017 11:54
By-passes installation error
trace(utils:::unpackPkgZip, edit=TRUE)