Skip to content

Instantly share code, notes, and snippets.

from sklearn.cross_validation import train_test_split
df = pd.DataFrame(np.random.randn(100, 2), columns=['x1', 'x2'])
df['y'] = np.random.choice([0, 1], size=len(df), p=[0.1, 0.9])
train, test = train_test_split(df, test_size=0.2, stratify=df.y)
train.y.value_counts()
test.y.value_counts()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
for file in *.json
do
cat "$file" | python -m json.tool > "$file.new"
mv -f "$file.new" "$file"
done
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import bokeh.charts
from bokeh.models import HoverTool, ColumnDataSource
from bokeh.plotting import figure
def plot_interactive_timeseries(df, col):
# https://github.com/bokeh/bokeh/pull/3883
hover = HoverTool(tooltips=[
("y (%s)" % col, "$y{1.11}"),
@AlJohri
AlJohri / colourised_log_example.py
Created May 6, 2016 21:13 — forked from exhuma/colourised_log_example.py
Simple python log formatter for colourised terminal output.
"""
Example for a colourised logging output.
This example uses "blessings" to handle console escape sequences. ``blessings``
itself is a very harmless package in that it does not have any external
dependencies. And it's code-base is very clean and small.
The example extends the core logging formatter (logging.Formatter) and
colourises the complete line. This takes advantage of any upstream updates
related to logging. When writing this against Python 2.7, the parent code
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{"gold_medal_winners": [{"player": "Victoria Azarenka"}], "silver_medal_winners": [{"player": "Maria Kirilenko"}], "medal": "Bronze", "discipline": "Tennis", "event": "Women's Singles Bronze Medal Match"}
{"gold_medal_winners": [{"player": "Serena Williams"}], "silver_medal_winners": [{"player": "Maria Sharapova"}], "medal": "Gold", "discipline": "Tennis", "event": "Women's Singles Gold Medal Match"}
{"gold_medal_winners": [{"country": "France"}], "silver_medal_winners": [{"country": "Spain"}], "medal": "Bronze", "discipline": "Tennis", "event": "Men's Doubles Bronze Medal Match"}
{"gold_medal_winners": [{"country": "United States"}], "silver_medal_winners": [{"country": "France"}], "medal": "Gold", "discipline": "Tennis", "event": "Men's Doubles Gold Medal Match"}
{"gold_medal_winners": [{"player": "Juan Martin del Potro"}], "silver_medal_winners": [{"player": "Novak Djokovic"}], "medal": "Bronze", "discipline": "Tennis", "event": "Men's Singles Bronze Medal Match"}
{"gold_medal_winners": [{"country": "Unite