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()) |
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() |
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): |
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() |
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', |
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 |
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() |
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') |
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') |
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