Skip to content

Instantly share code, notes, and snippets.

View nborwankar's full-sized avatar

Nitin Borwankar nborwankar

View GitHub Profile
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
app = dash.Dash()
df = pd.read_csv(
'https://gist.githubusercontent.com/chriddyp/'
@nborwankar
nborwankar / freebasicsInIndia.md
Last active December 30, 2015 04:46
Free Basics in India - some links (started Dec 2015)
@nborwankar
nborwankar / gist:5208953
Created March 20, 2013 22:04
two files needed for %pg magic in IPython - pgdb.py and pgmagic.py, this is pgmagic.py
__author__ = 'nitin'
# -*- coding: utf-8 -*-
"""
===========
pgmagic
===========
Magics for interacting with Postgres database server via psycopg2.
@nborwankar
nborwankar / gist:5208931
Created March 20, 2013 22:02
two python files needed for %pg magic in IPython pgdb.py and pgmagic.py. This is pgdb.py
# pgdb.py
__author__ = 'nitin'
import psycopg2 as pspg2
import sys
# import pandas as pd, then use pandas.io.sql
db_data = {
'host':'localhost',
'dbname': 'nitin',
# compute error measures for predictive model for activity (act) as dependent variable
# note this is computed for all 6 activities and a total computed which is an aggregate value
errormeasures <- function(orig, pred, act) {
N <- length(orig)
origtrue <-as.vector(NULL)
origfalse <-as.vector(NULL)
predtrue <-as.vector(NULL)
predfalse <-as.vector(NULL)
@nborwankar
nborwankar / RSessionToMADlibPG.txt
Created July 13, 2012 00:15
RSessionToMADlibPG
===
> rs <- dbSendQuery(con, statement = paste(
+ "SELECT * FROM", +"MADlib.c45_train('infogain','public.golf_data','trained_tree_infogain',null,'temperature,humidity','outlook,temperature,humidity,windy','id','class',100,'explicit', 5,0.001,0.001,0)"));
> df <- fetch(rs, n = -1)
> df
training_set_size tree_nodes tree_depth training_time split_criterion
14 8 3 00:00:00.311362 infogain
Here's an R session mimicking the steps in the doc for decision trees. At this point not meant to show anything like the final result just a probe of the R<->Pg semantics.
Note that the driver seems to create a result set in a format that the data frame constructor in R understands.
Not only that but the equivalent of "to_string" for df seems to output it in the familiar tabular format by default.
So the happy result to report here is that the native impedance mismatch is small.
We'll need some validation tests to identify R<-->GP issues if any.
Right now I am using an R<-->Postgres driver (MADlib 0.4 on Pg 9.1 on MacOSX Lion., RStudio 0.9.4, R 2.13.2).
@nborwankar
nborwankar / MLBootcampOct2015
Last active October 6, 2015 20:41
Notes and links for ML Bootcamp at UCB Oct 2015
Session 1
---------
* Intro
* Motivation
* Installation
* Overview of Material
@nborwankar
nborwankar / couchdb-ec2-install.sh
Created August 26, 2011 00:21 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
curl -X PUT http://your:credentials@localhost:5984/profiles
curl -X POST -d '{"source":"http://couchcamp.couchone.com/profiles","target":"http://localhost:5984/profiles","continuous":true}' -H "Content-type: application/json" http://localhost:5984/_replicate
curl -X POST -d '{"target":"http://couchcamp.couchone.com/profiles","source":"http://localhost:5984/profiles","continuous":true}' -H "Content-type: application/json" http://localhost:5984/_replicate