View interface-slice.go
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: https://stackoverflow.com/questions/12753805/type-converting-slices-of-interfaces | |
// make any slice to interface{} slice | |
func InterfaceSlice(slice interface{}) []interface{} { | |
s := reflect.ValueOf(slice) | |
if s.Kind() != reflect.Slice { | |
panic("InterfaceSlice() given a non-slice type") | |
} | |
ret := make([]interface{}, s.Len()) |
View python-pipe-functions.py
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
class Pipe(object): | |
def __init__(self, func): | |
self.func = func | |
def __ror__(self, other): | |
def generator(): | |
for obj in other: | |
if obj is not None: | |
yield self.func(obj) | |
return generator() |
View exponential-probability-demo.py
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: https://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb | |
import scipy.stats as stats | |
from matplotlib import pyplot as plt | |
import numpy as np | |
a = np.linspace(0, 4, 100) | |
expo = stats.expon | |
lambda_ = [0.5, 1] | |
for l, c in zip(lambda_, colours): |
View svm-demo.py
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 numpy as np | |
import matplotlib.pyplot as plt | |
import ipywidgets as widget | |
from sklearn.datasets import make_blobs | |
from sklearn.svm import SVC | |
def plot_svc_decision_function(model, ax=None, plot_support=True): | |
"""Plot the decision function for a 2D SVC""" | |
ax = ax or plt.gca() |
View linked-brush-selection.py
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
# load an example dataset | |
from vega_datasets import data | |
cars = data.cars() | |
import altair as alt | |
interval = alt.selection_interval() | |
base = alt.Chart(cars).mark_point().encode( | |
y='Miles_per_Gallon', |
View circle-with-auto-color.py
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 numpy as np | |
from bokeh.plotting import figure, show | |
from bokeh.io import output_notebook | |
# Call once to configure Bokeh to display plots inline in the notebook. | |
output_notebook() | |
N = 4000 | |
x = np.random.random(size=N) * 100 | |
y = np.random.random(size=N) * 100 |
View heatmap-witth-rotation.py
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 sklearn.datasets import load_digits | |
digits = load_digits() | |
# split data | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target, shuffle=True) | |
# use Gaussian Naive Bayes | |
from sklearn.naive_bayes import GaussianNB | |
model = GaussianNB() |
View contour-example.py
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
def f(x, y): | |
return np.sin(x) ** 10 + np.cos(10+x*y) + np.cos(x) | |
x = np.linspace(0, 5, 50) | |
y = np.linspace(0, 5, 50) | |
X, Y = np.meshgrid(x, y) | |
Z = f(X, Y) | |
# draw contour | |
contour = plt.contour(X, Y, Z, 3, colors='black') |
View data-reader.py
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 pandas_datareader import data | |
goog = data.DataReader('GOOG', start='2014', end='2020', data_source='yahoo') | |
goog.columns = goog.columns.str.lower() | |
goog = goog.asfreq('D', method='bfill') |
View memo.py
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 functools import wraps | |
def memoize(function): | |
memo = {} | |
@wraps(function) | |
def wrapper(*args): | |
try: | |
return memo[args] | |
except KeyError: | |
rv = function(*args) |
NewerOlder