Skip to content

Instantly share code, notes, and snippets.

View tommct's full-sized avatar

Tom McTavish tommct

View GitHub Profile
@tommct
tommct / Matrix Multiplication Review.ipynb
Last active May 13, 2023 00:25
Intuitions into what matrix multiplications are really and why we employ them in machine learning.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / interactive_display_pandas.ipynb
Created June 11, 2022 22:32
Update the display of a Pandas DataFrame interactively in a Jupyter Notebook using Jupyter Widgets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / transformercontext.py
Created July 2, 2021 17:18
Allows for the retrieval of all or parts of the transformations in a sklearn Pipeline, as well as the ability to dynamically bypass parts of the pipeline.
import contextlib
from functools import partial
from sklearn.pipeline import Pipeline
@contextlib.contextmanager
def intermediate_transforms(pipe: Pipeline, keys: list=[], bypass_list: list=[]):
"""Allows for the retrieval of all or parts of the transformations in a
sklearn Pipeline, as well as the ability to dynamically bypass parts of
the pipeline.
@tommct
tommct / Install_Python.md
Last active April 29, 2024 18:29
Install Python MacOS 14, Pyenv
@tommct
tommct / MNIST_PCA.ipynb
Created April 30, 2021 23:30
PCA exploration in Python with the MNIST database
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / dijkstra.ipynb
Last active April 30, 2021 17:06
Generic Dijkstra's shortest paths implementation in Python using a priority queue with callback functionality as it visits nodes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / walkcollection.py
Created April 30, 2021 16:39
Walk a collection, like a JSON object, using a callback.
import logging
from collections.abc import Iterable
def is_container(obj):
return isinstance(obj, Iterable) and not isinstance(obj, (str, bytes, bytearray))
# https://stackoverflow.com/a/54000999/394430
def walk_collection(obj, callback=None, _path: list=[], **kwargs):
"""Walk an arbitrarily nested structure of lists and/or dicts such as would be made when
reading JSON as an object. Walking is performed in a depth-first search manner.
@tommct
tommct / jupyterthemes.ipynb
Last active December 23, 2020 17:27
Jupyter Themes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / README.md
Created August 28, 2018 23:02
MongoDB from Tableau

To get use MongoDB from Tableau, start a mongosqld instance...

mongosqld --mongo-uri "mongodb://<host>:<port>/?connect=direct"

Then from Tableau, select Servers->MongoDB BI Connector with 127.0.0.1 and 3307 as connection details.

@tommct
tommct / README.md
Last active January 10, 2018 18:48
Matplotlib normalized histograms

This creates a normalized mass density histogram in matplotlib

bins = np.linspace(-1, 1, 101)
# To get a normalized mass density histogram, we have to do it this way...
hist, bins = np.histogram(df['some_column'], bins=bins, density=True)
hist /= len(bins)
width = bins[1]-bins[0]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([.15, .15, .75, .75])

plt.bar(left=bins[:-1], height=hist, width=width)