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
######################################## | |
'''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') |
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 matplotlib.pyplot as plt | |
plt.rcParams['figure.figsize'] = 5, 10 | |
%matplotlib inline |
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
## arrow up | |
"\e[A":history-search-backward | |
## arrow down | |
"\e[B":history-search-forward |
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
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)) | |
} |
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
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 { |
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
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)) |
NewerOlder