This file contains hidden or 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 | |
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], |
This file contains hidden or 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 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]. |
This file contains hidden or 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 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 |