Skip to content

Instantly share code, notes, and snippets.

@brooksandrew
brooksandrew / shiny_arules.R
Last active May 19, 2022 08:14
Launches a Shiny App that provides an interactive interface to the arules and arulesViz package which train and visualize association rules
#' @title Assocation Rules Visualization Shiny App
#' @description Launches a Shiny App that provides an interactive interface to the visualizations of the \code{arulesViz} package.
#' The app allows users to mine rules based on all or just subsets of features, sort by criteria (lift, support, confidence) and visualize
#' using network graph, grouped bubble and scatter plots. \cr
#' Users filter rules to target only those with a certain variable on the RHS or LHS of the rule.
#' Rule mining is computed using the \link{apriori} algorithm from \code{arules}.
#'
#' @param dataset data.frame, this is the dataset that association rules will be mined from. Each row is treated as a transaction. Seems to work
#' OK when a the S4 transactions class from \code{arules} is used, however this is not thoroughly tested.
#' @param bin logical, \code{TRUE} will automatically discretize/bin numerical data into categorical features that can be used for association analysis.
@brooksandrew
brooksandrew / makeGray.scala
Created April 12, 2016 16:52
Example of color to grayscale conversion with ImageIO in Scala.
import java.io.File
import javax.imageio.ImageIO
import java.awt.Color
object makegray extends App {
def pixels2gray(red: Int, green: Int, blue: Int): Int = (red + green + blue) / 3
def makeGray(img: java.awt.image.BufferedImage): java.awt.image.BufferedImage = {
val w = img.getWidth
@brooksandrew
brooksandrew / resize.scala
Last active April 12, 2016 19:31
Re-size images using ImageIO and imgscalr in Scala and save output as a new jpgs
import org.imgscalr._
import java.io.File
import javax.imageio.ImageIO
object resize extends App {
def resizeImg(img: java.awt.image.BufferedImage, width: Int, height: Int) = {
Scalr.resize(img, Scalr.Method.BALANCED, width, height)
}
@brooksandrew
brooksandrew / makeSquare.scala
Created April 12, 2016 19:26
Square rectangular images and center as much as possible using ImageIO and imgscalr in Scala. Save output as new jpg.
import org.imgscalr._
import java.io.File
import javax.imageio.ImageIO
object makeSqaure extends App {
def makeSquare(img: java.awt.image.BufferedImage): java.awt.image.BufferedImage = {
val w = img.getWidth
val h = img.getHeight
val dim = List(w, h).min
{
"tcount": "123,456",
"datime": "July 31st 2016"
}
@brooksandrew
brooksandrew / edgelist_sleeping_giant.csv
Created August 30, 2017 03:32
Edge list for network of Sleeping Giant State Park trail map. Used for Datacamp blog post: Intro to Graph Optimization
node1 node2 trail distance color estimate
rs_end_north v_rs rs 0.3 red 0
v_rs b_rs rs 0.21 red 0
b_rs g_rs rs 0.11 red 0
g_rs w_rs rs 0.18 red 0
w_rs o_rs rs 0.21 red 0
o_rs y_rs rs 0.12 red 0
y_rs rs_end_south rs 0.39 red 0
rc_end_north v_rc rc 0.7 red 0
v_rc b_rc rc 0.04 red 0
@brooksandrew
brooksandrew / nodelist_sleeping_giant.csv
Created August 30, 2017 03:33
Node list for network of Sleeping Giant State Park trail map. Used for Datacamp blog post: Intro to Graph Optimization Raw
id X Y
b_bv 1486 732
b_bw 716 1357
b_end_east 3164 1111
b_end_west 141 1938
b_g 1725 771
b_gy2 2000 983
b_o 2039 1012
b_rc 1311 979
b_rd 268 1744
@brooksandrew
brooksandrew / sleeping_giant_cpp_route_animation.gif
Last active July 29, 2019 20:30
CPP solution for Sleeping Giant network. Used for Datacamp blog post: Intro to Graph Optimization
sleeping_giant_cpp_route_animation.gif
@brooksandrew
brooksandrew / sleeping_giant_cpp_route_animation_using_graphviz.gif
Last active September 16, 2017 17:14
CPP solution using graphviz for postman_problems package
sleeping_giant_cpp_route_animation_using_graphviz.gif