Skip to content

Instantly share code, notes, and snippets.

@padamson
padamson / PyQuante Testing.ipynb
Created July 8, 2021 00:53 — forked from rpmuller/PyQuante Testing.ipynb
Notes, timings, and additional tests for the development of pyquante2 by comparing to to PyQuante (1.6.??).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@padamson
padamson / acronymTable.R
Created December 28, 2016 13:13
Reactive acronym list with renderDataTable, timevis, and Shiny
output$acronyms <- DT::renderDataTable({
firstDate <- input$timelineGroups_window[1]
lastDate <- input$timelineGroups_window[2]
data <- input$timelineGroups_data %>%
select(label,start,end) %>%
filter((is.na(end) & (start > firstDate & start < lastDate)) |
(!is.na(end) & (start < lastDate & end > firstDate)))
acronyms %>%
filter(grepl(
paste(unlist(str_split(data$label,pattern=" ")),collapse="|"),
@padamson
padamson / rwml-R_listing4_3.R
Created December 28, 2016 10:54
ROC curve calculation for Listing 4.3 of Real-World Machine Learning
# Returns the false-positive and true-positive rates at nPoints thresholds for
# the given true and predicted labels
# trueLabels: 0=FALSE; 1=TRUE
rocCurve <- function(trueLabels, predictedProbs, nPoints=100, posClass=1){
# Allocates the threshold and ROC lists
thr <- seq(0,1,length=nPoints)
tpr <- numeric(nPoints)
fpr <- numeric(nPoints)
# Precalculates values for the positive and negative cases, used in the loop
@padamson
padamson / rwml-R_figure4_20.R
Created October 23, 2016 07:19
ROC curves for each class of the MNIST 10-class classifier
library(ROCR)
library(dplyr)
mnistResultsDF <- data.frame(actual = mnistTest$label,
fit = mnist.kknn$fit,
as.data.frame(mnist.kknn$prob))
plotROCs <- function(df, digitList) {
firstPlot <- TRUE
legendList <- NULL
@padamson
padamson / rwml-R_figure4_19.R
Created October 23, 2016 07:04
Plot the confusion matrix for a 10-class MNIST handwritten digit classification problem
library(caret)
library(kknn)
library(RColorBrewer)
library(cowplot)
mnist <- read.csv("data/mnist_small.csv",
colClasses = c(label = "factor"))
trainIndex <- createDataPartition(mnist$label, p = .8,
list = FALSE,
@padamson
padamson / rwml-R_figure3_10.R
Created October 16, 2016 00:14
Display four random digits from MNIST database
mnist <- read.csv("data/mnist_small.csv",
colClasses = c(label = "factor"))
displayMnistSamples <- function(x) {
for(i in x){
y = as.matrix(mnist[i, 2:785])
dim(y) = c(28, 28)
image( y[,nrow(y):1], axes = FALSE, col = gray(0:255 / 255))
text( 0.2, 0, mnist[i,1], cex = 3, col = 2, pos = c(3,4))
}
}
@padamson
padamson / rwml-R_figure2_12.R
Last active October 1, 2016 13:37
Create mosaic plot for Real-World Machine Learning Figure 2.12
library(vcd)
mosaic(
~ Sex + Survived,
data = titanic,
main = "Mosaic plot for Titanic data: Gender vs. survival",
shade = TRUE,
split_vertical = TRUE,
labeling_args = list(
set_varnames = c(
Survived = "Survived?")
@padamson
padamson / installAllRPackages.bash
Last active March 22, 2021 15:54
Bash script to install all R packages required by an R program
#!/bin/bash
#Install any packages required by an R file that aren't already installed
if [ $# -ne 1 ]; then
echo $0: usage: installAllRPackages.bash file
exit 1
fi
file=$1
@padamson
padamson / multi_smooth_ggpairs.R
Created February 17, 2016 02:07
Add two regression lines to plots in ggpairs
require(datasets)
data("swiss")
require(GGally)
require(ggplot2)
my_fn <- function(data, mapping, ...){
p <- ggplot(data = data, mapping = mapping) +
geom_point() +
geom_smooth(method=loess, fill="red", color="red", ...) +
geom_smooth(method=lm, fill="blue", color="blue", ...)