Skip to content

Instantly share code, notes, and snippets.

@rsivapr
rsivapr / data.json
Last active August 29, 2015 14:18 — forked from d3noob/.block
[
{
"date":"1-May-12",
"close":58.13
},
{
"date":"30-Apr-12",
"close":53.98
},
{
@rsivapr
rsivapr / map.py
Created June 23, 2012 03:47 — forked from ajschumacher/map.py
Calculates the Mean Average Precision, as in: http://www.kaggle.com/c/FacebookRecruiting/details/Evaluation
#!/usr/bin/env python
import sys
import csv
def MeanAveragePrecision(valid_filename, attempt_filename, at=10):
at = int(at)
valid = dict()
for line in csv.DictReader(open(valid_filename,'r')):
valid.setdefault(line['source_node'],set()).update(line['destination_nodes'].split(" "))
@rsivapr
rsivapr / make_completer.py
Created June 25, 2012 15:20 — forked from ajschumacher/make_completer.py
This code generates a file that gets a score of 0.61758 at http://www.kaggle.com/c/FacebookRecruiting/
import csv
r = csv.reader(open('train.csv','r'))
r.next()
edges = set()
#commutative_graph = dict()
for edge in r:
edges.add((edge[0], edge[1]))
# commutative_graph.setdefault(edge[0], set()).add(edge[1])
@rsivapr
rsivapr / game.js
Last active December 20, 2015 09:39
Influence
gameGrid = function(gridSize) {
var i;
window.a = [];
this.size = gridSize;
this.map = [];
for (i = 0; i < this.size; i++) {
this.map[i] = [];
}
};
@rsivapr
rsivapr / problem1.py
Created August 5, 2013 23:10
Challenge
import pandas as pd
import statsmodels.api as sm
import pylab as pl
import numpy as np
import sklearn.metrics
print "Reading DATA.CSV ... \n"
df = pd.read_csv('data.csv')
df.columns = ["numb", "age","frailty","sex","val"]
for i in range(df.shape[0]):
@rsivapr
rsivapr / problem2.py
Created August 6, 2013 06:06
run $python problem2.py > avgclaims.csv
import numpy as np
from datetime import date
claimsdata = np.genfromtxt('claims.csv', dtype = (int, object, object, int, object), delimiter=',', names = True)
poldata = np.genfromtxt('policies.csv', dtype = (int, object, object, object, object), delimiter=',', names = True)
f = open('categories')
f.readline()
dict1 = {}
for i in f.readlines():
colorVal = i.split(',')
colorVal[1]=colorVal[1][:-1]

What

Roll your own iPython Notebook server with Amazon Web Services (EC2) using their Free Tier.

What are we using? What do you need?

  • An active AWS account. First time sign-ups are eligible for the free tier for a year
  • One Micro Tier EC2 Instance
  • With AWS we will use the stock Ubuntu Server AMI and customize it.
  • Anaconda for Python.
  • Coffee/Beer/Time
We can't make this file beautiful and searchable because it's too large.
300,100006
300,100011
300,100012
300,100033
300,100044
300,100053
300,100059
300,100072
300,100104
300,100111
@rsivapr
rsivapr / renewBot.py
Created August 17, 2013 00:27
To run the code, $ pip install selenium then, $ python renewBot.py
from selenium import webdriver
import getpass
driver = webdriver.Firefox()
driver.get('https://myaccount.lib.ncsu.edu/')
user = driver.find_element_by_name('user_idp')
for option in user.find_elements_by_tag_name('option'):
if option.text == 'NC State Unity Users':
awk 'BEGIN { srand(systime()); } {if (rand() < 0.25) { print $0; } }' Train.csv > sampled_train.csv