Skip to content

Instantly share code, notes, and snippets.

Joel Nothman jnothman

View GitHub Profile
@jnothman
jnothman / paramfunc.py
Last active Nov 15, 2018
A wrapper for functions so that they can be parametrized with get_params and set_params in scikit-learn: proof of concept
View paramfunc.py
from collections import defaultdict
import pandas as pd
class parametrized_function:
def __init__(self, _func, **kwargs):
self._func = _func
self.__doc__ = self._func.__doc__
self.__name__ = self._func.__name__
# TODO use inspect to automatically find parameters with defaults
@jnothman
jnothman / script.js
Created Aug 28, 2018
Stoichiometry widget for LabArchives
View script.js
/* Stoichiometry Widget implemented by Joel Nothman at the Sydney Informatics Hub
Copyright (c) 2018, The University of Sydney
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@jnothman
jnothman / docxtables.py
Created Aug 27, 2018
Load tables from Word docx to pandas dataframe
View docxtables.py
import zipfile
from lxml import etree
import pandas as pd
def read_docx(docx_file, **kwargs):
"""Read tables as DataFrames from a Word document
"""
ns = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}
with zipfile.ZipFile(docx_file).open('word/document.xml') as f:
root = etree.parse(f)
@jnothman
jnothman / get-pr-modified-lines.sh
Created Jun 21, 2018
Identify which lines in master are modified by open pull requests
View get-pr-modified-lines.sh
#!/bin/bash
# requires curl, jq, python
# set these variables
repo=scikit-learn/scikit-learn
remote=upstream
token= # GitHub personal access token goes here
list_open_prs() {
@jnothman
jnothman / memoryfit.py
Created Mar 6, 2018
Scikit-learn: Cache an estimator's fit with a mixin
View memoryfit.py
from sklearn.externals import joblib
from sklearn.linear_model import LogisticRegression
from sklearn.feature_selection import RFE
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_classification
memory = joblib.Memory('/tmp')
View bench_working_memory.csv
elapsed n_features n_samples_Y working_memory
0 37.13675403594971 1000 100 1
1 36.132298946380615 1000 100 1
2 38.42840266227722 1000 100 1
3 37.29706525802612 1000 1000 1
4 34.58624744415283 1000 1000 1
5 36.96818971633911 1000 1000 1
6 38.077014684677124 1000 5000 1
7 36.49429655075073 1000 5000 1
8 39.22079372406006 1000 5000 1
View bench_working_memory.csv
elapsed n_features n_samples working_memory
0 259.7408814430237 100 40000 1
1 263.6345293521881 100 40000 1
2 263.4755172729492 100 40000 1
3 32.214531898498535 100 20000 1
4 32.38340449333191 100 20000 1
5 32.6368203163147 100 20000 1
6 4.7826080322265625 100 10000 1
7 4.722550392150879 100 10000 1
8 4.735676050186157 100 10000 1
@jnothman
jnothman / plotview.py
Last active Dec 6, 2017
Generic Django plot view for matplotlib plot rendering and serving
View plotview.py
from django.views import View
from django.http import HttpResponse
MIMETYPES = {
'ps': 'application/postscript',
'eps': 'application/postscript',
'pdf': 'application/pdf',
'svg': 'image/svg+xml',
'png': 'image/png',
'jpeg': 'image/jpeg',
@jnothman
jnothman / auspoliticians-wikidata.rq
Created Oct 23, 2017
Get Australian/COAG parliamentarians' Positions, Party Memberships and Awards from WikiData.
View auspoliticians-wikidata.rq
SELECT
?subj
?subjLabel
?prop
?position
?positionLabel
?start
?end
?district
?districtLabel
@jnothman
jnothman / deprecdict.py
Last active Oct 10, 2017
A dict which raises a warning when some keys are looked up
View deprecdict.py
import warnings
from sklearn.utils.testing import assert_warns_message, assert_no_warnings
class DeprecationDict(dict):
"""A dict which raises a warning when some keys are looked up
Note, this does not raise a warning for __contains__ and iteration.
It also will raise a warning even after the key has been manually set by
You can’t perform that action at this time.