Skip to content

Instantly share code, notes, and snippets.

@sinhrks
sinhrks / squarify_plot.py
Created March 16, 2014 06:29
Squarify plot example
import squarify
import matplotlib.pyplot as plt
from numpy.random import rand
fig, axes = plt.subplots(2, 3, figsize=(14, 8))
plt.subplots_adjust(top=0.95, bottom=0.05, left=0.05, right=0.95, hspace=0.35)
sq = 8
def random_colors(n):
@sinhrks
sinhrks / df_plot_table.py
Created March 18, 2014 14:26
Pandas dataframe with table plotting.
from pandas import Series, DataFrame
import numpy as np
from numpy.random import randn, rand
import pandas.tools.plotting as plotting
import matplotlib.pyplot as plt
s = Series(randn(6), index=range(6))
@sinhrks
sinhrks / vis_ml2.py
Created November 30, 2014 08:40
Animate Multilayer Perceptron using 2D XOR Data
# -*- coding: utf-8 -*-
"""
This code uses "MLP" class defined in:
http://deeplearning.net/tutorial/mlp.html#tips-and-tricks-for-training-mlps
"""
import os
import sys
import time
@sinhrks
sinhrks / dtw.R
Created November 14, 2014 13:36
Dynamic Time Warping
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(animation)
plot_dtw_matrix <- function(ts_a, ts_b, i, j, cost, dist) {
.plot_matrix <- function(m, title, low, high) {
d <- dplyr::tbl_df(data.frame(m))
@sinhrks
sinhrks / MRF.py
Last active July 29, 2019 06:35
Markov Random Field
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from collections import defaultdict
import numpy as np
np.random.seed(1)
import networkx as nx
class MRF(object):
@sinhrks
sinhrks / fortify_survfit.R
Created October 4, 2014 10:53
Allow ggplot2 to handle survival::survfit result
library(survival)
library(ggplot2)
library(scales)
d.survfit <- survival::survfit(survival::Surv(time, status) ~ sex,
data = lung)
fortify.survfit <- function(survfit.data) {
data.frame(time = survfit.data$time,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sinhrks
sinhrks / sprint.md
Last active October 23, 2017 10:21
PyCon JP 2017 pandas sprint
@sinhrks
sinhrks / df_plot_bar.py
Created March 16, 2014 03:42
Pandas dataframe bar plot sample with flexible bar width and position
import string
from pandas import DataFrame
import numpy as np
from numpy.random import randn
import pandas.tools.plotting as plotting
from matplotlib.pylab import close
@sinhrks
sinhrks / environment_setup.sh
Last active June 27, 2017 03:57
EC2 g2.xlarge with NVIDIA GRID Environment Setup
#!/bin/bash
# --------------------------------------------------------------------------------------
# Preparation
# To execute this script, please follow:
# wget https://gist.github.com/sinhrks/ba9876e7aa2a18a601f8/raw/environment_setup.sh
# chmod +x environment_setup.sh
# ./environment_setup.sh
# --------------------------------------------------------------------------------------