Skip to content

Instantly share code, notes, and snippets.

@aficionado
aficionado / browser_train.csv
Last active August 29, 2015 13:57
Mini App
user_agent wants_api
Mozilla/5.0 (Windows NT 6.1; WOW64; rv no
Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36 no
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 no
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 no
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv no
Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36 no
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 no
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36 no
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36 no
build

This variation of a clustered force layout uses an entry transition and careful initialization to minimize distracting jitter as the force simulation converges on a stable layout.

By default, D3’s force layout randomly initializes node positions. You can prevent this by setting each node’s x and y properties before starting the layout. In this example, because custom forces cluster nodes by color, most of the initial jitter is caused by the initial random placement overlapping clusters. We can reduce the jitter by initially placing nodes of the same color near other.

The number of clusters in this example is defined by the variable m; the local variable i is the node’s cluster number. To initialize clusters in a circle of radius 200px around the canvas center, we can define x and y like so:

x: Math.cos(i / m * 2 * Math.PI) * 200 + width / 2 + Math.random(),
y: Math.sin(i / m * 2 * Math.PI) * 200 + height / 2 + Math.r

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

{"fields": [{"optype": "numeric", "name": "pregnancies", "datatype": "int8", "preferred": true, "summary": {"sum_squares": 20063, "missing_count": 0, "sum": 2953, "median": 2.96687, "maximum": 17, "minimum": 0, "standard_deviation": 3.36958, "variance": 11.35406, "counts": [[0, 111], [1, 135], [2, 103], [3, 75], [4, 68], [5, 57], [6, 50], [7, 45], [8, 38], [9, 28], [10, 24], [11, 11], [12, 9], [13, 10], [14, 2], [15, 1], [17, 1]], "population": 768, "mean": 3.84505}, "column_number": 0, "id": "000000", "order": 0}, {"optype": "numeric", "name": "plasma glucose", "datatype": "int16", "preferred": true, "summary": {"sum_squares": 12008759, "splits": [73.40028, 80.70976, 84.56046, 88.29697, 91.0653, 94.02324, 96.37393, 99.15167, 100.81422, 102.99865, 105.47912, 107.37394, 109.45106, 111.68975, 114.22117, 116.8391, 119.5, 122.06267, 124.31608, 126.65592, 129.19127, 132.64738, 136.8101, 140.43237, 144.72673, 148.62092, 155.01649, 161.85305, 168.92, 178.9276, 187.59806], "missing_count": 0, "sum": 92847, "median":
@aficionado
aficionado / 5400ebc59841fa7f50000811.json
Last active August 29, 2015 14:05
Psychsignal - APPL - Anomalies
{"fields": [{"optype": "categorical", "name": "Symbol", "datatype": "string", "preferred": false, "summary": {"missing_count": 0, "categories": [["AAPL", 911]]}, "term_analysis": {"enabled": true}, "column_number": 0, "id": "000000", "order": 0}, {"optype": "numeric", "name": "Open", "datatype": "double", "preferred": true, "summary": {"sum_squares": 4538487.31442, "splits": [47.73657, 48.60528, 49.42383, 50.32761, 51.74761, 54.02171, 55.52738, 56.79641, 57.76227, 59.9516, 61.06254, 62.37242, 63.80142, 65.21705, 66.59425, 69.96617, 71.737, 73.4288, 74.5442, 75.40514, 76.37247, 77.41663, 78.94439, 80.4674, 81.69666, 83.33576, 85.10045, 86.52656, 88.70865, 91.0064, 94.91478], "missing_count": 0, "sum": 62989.7769, "median": 69.96617, "maximum": 100.3443, "minimum": 45.24, "standard_deviation": 14.18676, "variance": 201.2641, "population": 911, "bins": [[45.38, 3], [47.65305, 53], [49.44396, 58], [51.25244, 38], [53.27143, 16], [54.46864, 20], [55.68153, 32], [57.46563, 54], [60.00132, 26], [61.1975, 32], [62.94
from pymongo.son_manipulator import SONManipulator
class KeyTransform(SONManipulator):
"""Transforms keys going to database and restores them coming out.
This allows keys with dots in them to be used (but does break searching on
them unless the find command also uses the transform.
Example & test:
# To allow `.` (dots) in keys
@aficionado
aficionado / confidence_roc.py
Last active August 29, 2015 14:17
Confidence Threshold Evaluation Comparison
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Uses multiple confidence thresholds to evaluate a model.
"""
##############################################################################
# Copyright (c) 2015 BigML, Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Moves a resource to a project
"""
##############################################################################
# Copyright (c) 2015 BigML, Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
@aficionado
aficionado / README.rst
Created August 27, 2012 20:11 — forked from njwilson/README.rst
Machine Learning Throwdown

Services and Algorithms

This section describes each of the services compared in the throwdown and the algorithms/models used.

BigML

Decision trees.