Skip to content

Instantly share code, notes, and snippets.

View dyerrington's full-sized avatar
💭
I may be slow to respond.

David Yerrington dyerrington

💭
I may be slow to respond.
View GitHub Profile
@dyerrington
dyerrington / linear_regression_kfold_cross_validation.py
Created May 5, 2016 00:01
Basic end-to-end example for doing linear regression with sklearn with cross_validation / k-fold and Pandas
# k-fold regression
# we need our modules for this:
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import cross_val_score, cross_val_predict
from matplotlib import pyplot as plt
from sklearn import metrics
# Make the plots bigger
plt.rcParams['figure.figsize'] = 10, 10
@dyerrington
dyerrington / pearson_pandas_heatmap.py
Created May 5, 2016 06:33
Plotting pearson coeficients with pandas and seaborn
import seaborn as sns
import matplotlib, matplotlib.pyplot as plt
# initializing subplots allows changing of font size
fig, ax = plt.subplots()
fig.set_size_inches(12, 8)
# Change font size
matplotlib.rcParams.update({'font.size': 12})
class usajobs:
total_pages = 0
total_results = 0
per_page = 25
verify_ssl = False
search_term = ""
mined_jobs = []
headers = {
columns = ["col1", "col2", "col3", "col4"]
joined_columns = ") + c(".join(columns)
"target ~ c(" + joined_columns[0:len(joined_columns) - 1] + ")"
@dyerrington
dyerrington / 0_reuse_code.js
Created June 1, 2016 05:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dyerrington
dyerrington / foursquare.py
Created June 1, 2016 05:23
Foursquare Example, which is not the most exciting of API's these days but here is a basic example of using Foursquare and dataframes provided by Pandas
# !pip install foursquare
import foursquare
import pandas as pd
CLIENT_ID = '' # Input your client id/ client secret here
CLIENT_SECRET = ''
client = foursquare.Foursquare(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
# grab from bounding box (raw csv): http://boundingbox.klokantech.com/
@dyerrington
dyerrington / pandas_stateful_logger.py
Created June 3, 2016 02:08
This is a very basic logger that can be used between any instance, maintaining consistent grouping between events.
from sqlalchemy import create_engine
import pandas as pd
class sql_logger:
sql_file = False
engine = False
last_game_id = 0
def __init__(self, sql_file="crap.db"):
@dyerrington
dyerrington / pandas_select_numeric_objects.py
Created June 23, 2016 21:54
Should help remove / select only items that are convertable to INT or FLOAT
team['game_id'] = team[team['Gm#'].apply(lambda val: val.isdigit())]['Gm#'].map(int)
@dyerrington
dyerrington / init.sh
Created July 11, 2016 20:14
Setup Jupyter on AWS
# Basic system updates
sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-virtualenv
sudo apt-get install python-dev
# Create a directory for our virtualenvs
mkdir virtualenvs
virtualenv data
cd data
var newwin;
var tabs=[];
function close_win() {
win = tabs.pop();
win.close();
}
jQuery( document ).ajaxComplete(function( event,request, settings ) {