Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Ogaday / mlp.py
Last active October 30, 2020 12:34
Regression on toy data using Keras
# Python 3.5
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.optimizers import SGD
from sklearn.metrics import mean_squared_error
@Ogaday
Ogaday / unexpected_from_array.py
Created August 15, 2016 16:38
Unexpected behaviour when creating dependency lables from array as according the tutorial at http://spacy.io/docs/tutorials/byo-annotations.
# Python 3
# coding: utf-8
import spacy
from spacy.attrs import HEAD, DEP
from spacy.symbols import nsubj, root, dobj, punct
from numpy import ndarray
nlp = spacy.load('en')
@Ogaday
Ogaday / plot_lines.py
Last active September 4, 2017 13:46
Plot horizontal and vertical joining lines for coordinates described by arrays `x` & `y`.
# coding: utf-8
"""
Plot horizontal and vertical joining lines for coordinates described by
arrays `x` & `y`.
"""
import numpy as np
import matplotlib.pyplot as plt
def lines(x, y, first='x', ax=None, **kwargs):
"""
@Ogaday
Ogaday / connection_tools.py
Last active September 6, 2017 14:34
kbcstorage snippets
'''
Utilities for manipulating sqlalchemy connection to keboola workspace.
Example usage::
from getpass import getpass
from kbcstorage.client import Client
import sqlalchemy as sqa
@Ogaday
Ogaday / genesis_public_key
Created March 1, 2018 12:18
genesis_public_key
04c7074a2a2c094a81c8fb23c3766d17b162de6d09baaf1916544e35f8af30159c8d4da5ebcb14dc18b2c1e1ac30749a05a2a58169b9c933714376a6efa08ce53b;tinybot-ca
@Ogaday
Ogaday / Dockerfile
Created April 5, 2018 12:12
Minimal bokeh-stitch example
FROM continuumio/miniconda3:latest
RUN conda update conda -y
WORKDIR /opt/example/
COPY environment.yml /opt/example/
COPY ex_bokeh.ipymd /opt/example/
import numpy as np
def mae(y_true, y_pred):
'''
Caluclate mean absolute error between two vectors
'''
return np.mean(np.abs(y_pred - y_true))
@Ogaday
Ogaday / fib.py
Created July 1, 2019 16:50
Fibonacci Function
"""
Implementation of a function that returns elements from the Fibonacci sequence using DP
https://en.wikipedia.org/wiki/Fibonacci_number
https://en.wikipedia.org/wiki/Dynamic_programming
"""
import logging
logger = logging.getLogger(__name__)
@Ogaday
Ogaday / env.yml
Created July 11, 2019 16:25
Conda environment for PyDataLDn19 Workshop: Advanced Software Testing for Data Scientists
name: test4ds
dependencies:
- python>=3.7
- scikit-learn=0.21.2
- pandas=0.24.2
- numpy=1.16.4
- pip
- pip:
- pytest
- pytest-cov
@Ogaday
Ogaday / puzzle.py
Last active July 17, 2019 09:11
Expected updates when finding the max
#!/usr/bin/python3
"""
Simulation of the solution to a problem from a blog post by Nadbordrozd:
http://nadbordrozd.github.io/interviews/index.html
"""
from random import Random
def count_updates(x):
"""