Skip to content

Instantly share code, notes, and snippets.

@earino
earino / foo.py
Created March 27, 2015 01:48
categorical data encoding example
import pandas as pd
from sklearn.ensemble import RandomForestClassifier.
df = pd.read_csv('train.csv', header=1)
categorical = pd.concat([pd.get_dummies(df.ix[:, col]) for col in [4]],axis=1 )
numeric = df.ix[:, 5:41]
all_data = pd.concat([categorical, numeric], axis=1)
forest = RandomForestClassifier(n_estimators = 10)
forest = forest.fit(all_data,df.ix[0::,42])
@earino
earino / remap.R
Created February 25, 2015 01:54
column remapper
library(dplyr)
library(gdata)
sample1 <- data.frame(A=1:10, B=letters[1:10])
sample2 <- data.frame(B=11:20, C=letters[11:20])
rename_map <- list("A"="var1",
"B"="var2",
"C"="var3")
@earino
earino / test.R
Created December 29, 2014 02:56
using rvest
library(rvest)
tables <- html("http://www.sherdog.com/stats/fightfinder?SearchTxt=anderson+silva") %>%
html_table(fill = FALSE, header = TRUE)
fighters <- tables[[2]]
names(fighters) <- c("pic", "name", "nickname", "height", "weight", "association")
fighters$name # contains just the names, I really want the links also so i can get their detail data.
@earino
earino / requirements.txt
Created December 29, 2014 00:33
requirements.txt
blaze
bokeh
@earino
earino / drops.R
Created November 18, 2014 01:46
tbl_df drops?
> tbl_df(iris) %>% class()
[1] "tbl_df" "tbl" "data.frame"
> tbl_df(iris) %>% filter(Species == "setosa") %>% class()
[1] "tbl_df" "tbl" "data.frame"
> tbl_df(iris) %>% filter(Species == "setosa") %>% .[,"Species"] %>% class()
[1] "factor"
> tbl_df(iris) %>% filter(Species == "setosa") %>% .[,"Species"] %>% str()
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
@earino
earino / foo.R
Created November 18, 2014 01:36
is this not the same thing? I didn't understand your comment
> iris %>% filter(Species == "setosa") %>% .[,"Species"] %>% str()
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
> iris %>% filter(Species == "setosa") %>% `[[`("Species") %>% str()
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
> iris %>% filter(Species == "setosa") %>% .[,"Species"] %>% class()
[1] "factor"
> iris %>% filter(Species == "setosa") %>% `[[`("Species") %>% class()
[1] "factor"
@earino
earino / vertica.sh
Last active August 29, 2023 01:55
vertica on digitalocean
#!/bin/bash
echo deadline > /sys/block/vda/queue/scheduler
echo deadline > /sys/block/vda/queue/scheduler
echo 'echo deadline > /sys/block/vda/queue/scheduler' >> /etc/rc.local
/sbin/blockdev --setra 2048 /dev/vda
echo '/sbin/blockdev --setra 2048 /dev/vda' >> /etc/rc.local
sudo dd if=/dev/zero of=/swapfile bs=1k count=2048k
@earino
earino / keybase.md
Created September 22, 2014 17:10
keybase.md

Keybase proof

I hereby claim:

  • I am earino on github.
  • I am earino (https://keybase.io/earino) on keybase.
  • I have a public key whose fingerprint is EC06 4396 DCB2 701F 2747 9DD5 32A3 4E21 1D49 484A

To claim this, I am signing this object:

@earino
earino / bluest.R
Created August 3, 2014 20:41
bluest
map <- joke_map(states_to_highlight = c("WY"), title = "Squarest, Bluest State", highlight_colors=c("#aaaaaa", "#0000ee"))
@earino
earino / calling.R
Created August 3, 2014 20:39
calling joke_map
map <- joke_map(states_to_highlight = c("AK", "AZ", "CA", "CT", "DE", "HI", "IA", "MA", "NE", "NH", "NJ", "NY", "NV", "OR", "PA", "RI", "VT", "VA", "WA"), title = "States That Hate Freedom (and wildfires)")