Skip to content

Instantly share code, notes, and snippets.

@JanSellner
JanSellner / LDA.py
Created May 2, 2021 20:34
Fisher's Linear Discriminant Analysis (LDA)
import numpy as np
def LDA(data: np.ndarray, labels: np.ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Performs Fisher's Linear Discriminant Analysis. See https://en.wikipedia.org/wiki/Linear_discriminant_analysis#Fisher's_linear_discriminant and http://www.facweb.iitkgp.ac.in/~sudeshna/courses/ml08/lda.pdf for descriptions of the method.
>>> data = np.array([# First class
... [1, 2],
... [1.5, 2.7],
@JanSellner
JanSellner / iou.py
Last active June 24, 2020 16:00 — forked from meyerjo/iou.py
Python code to compute the intersection of two boundingboxes
from typing import Tuple
def intersection_over_union(boxA: Tuple[float, float, float, float], boxB: Tuple[float, float, float, float]) -> float:
"""Calculates the intersection of union between two rectangles/bounding boxes.
See https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/ for more information about IOU.
Args:
boxA: First bounding box with coordinates in the format [xmin, ymin, xmax, ymax].
@JanSellner
JanSellner / MeasureTime.py
Last active January 13, 2023 21:57
Measure Time in Python
from timeit import default_timer
class MeasureTime(object):
"""
Easily measure the time of a Python code block.
>>> import time
>>> with MeasureTime() as m:
... time.sleep(1)
Elapsed time: 0 m and 1.00 s