This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import numpy as np | |
from sklearn.metrics import precision_recall_fscore_support as prfs, confusion_matrix | |
from sklearn.preprocessing import label_binarize | |
true = [0, 0, 0, 1, 1, 2] | |
preds = [('under-generate 1', [0, 0, 0, 0, 1, 2]), | |
('under-generate 2', [0, 0, 0, 1, 1, 0]), | |
('over-generate 1', [0, 1, 1, 1, 1, 2]), | |
('confuse 1 and 2', [0, 0, 0, 1, 2, 1])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Faced with a collection of JSON blobs, this script lists what | |
paths (i.e. sequences of nested keys) exist in the data from | |
root to leaf. | |
For example: | |
$ echo '[{"a": {"a1": 124}, "b": 111}, {"a": {"a2": 111}, "c": null}]' \ | |
| list-json-paths.py | |
will output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABCMeta, abstractmethod | |
from .base import BaseEstimator | |
from .externals.six import iteritems, with_metaclass | |
class BaseParameterTranslator(with_metaclass(ABCMeta, BaseEstimator)): | |
@property | |
def fit(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, division | |
import numpy as np | |
from sklearn.base import BaseEstimator | |
from sklearn.cluster import MiniBatchKMeans, SpectralClustering | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.utils.random import sample_without_replacement | |
from sklearn.svm import OneClassSVM | |
from sklearn.linear_model import LogisticRegression | |
from sklearn import datasets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Count or sum, while uniquing rows, without full sort of data | |
By using --key-fields, can also show example row that has some particular fields. | |
(This was much simpler when it just counted!) | |
""" | |
import sys | |
import argparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
On the coursera lecture index, execute this Javascript (via greasemonkey script, bookmarklet, etc) to show 'quizzes' links next to each lecture. Clicking it will open the lecture, but instead of showing the video, will: | |
1. Pause it | |
2. Show the first quiz | |
3. Upon clicking "skip" or "continue" on the quiz, proceed to the next | |
4. Repeat from 3. | |
5. Continue showing the video | |
Having watched a downloaded video, you can now easily do the in-lecture quizzes separately. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! SourceGitVimrc(dir) | |
let gitroot = system("cd " . fnameescape(a:dir) . "; git rev-parse --show-toplevel 2>/dev/null") | |
" Strip trailing newline and escape | |
let gitroot = substitute(gitroot, "\\n*$","","") | |
if strlen(gitroot) && filereadable(gitroot . '/.vimrc') | |
execute "source " . fnameescape(gitroot) . '/.vimrc' | |
endif | |
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, sys | |
num_re = re.compile(r'(?<=^\[)[0-9]+') | |
in_n = '' | |
out_n = 0 | |
def sub_cb(match): | |
global in_n, out_n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from abc import ABCMeta, abstractmethod | |
from functools import partial | |
import numpy as np | |
from sklearn.metrics import precision_recall_fscore_support | |
from sklearn.base import BaseEstimator | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Tool to examine the output of model selection search results from scikit-learn (assuming #1787). | |
Pandas might be more appropriate, but I haven't worked out how to do group_best there... | |
For example: | |
>>> my_search = GridSearchCV(est, param_dict={'a': [...], 'b': [...], 'c': [...]}) | |
>>> my_search.fit(X, y) | |
>>> rw = ResultsWrangler(my_search.grid_results_, my_search.fold_results_) | |
>>> grouped = rw.group_best(['a', 'b']) | |
>>> print(zip(grouped.parameters, grouped.scores)) |
OlderNewer