Skip to content

Instantly share code, notes, and snippets.

View pavlin-policar's full-sized avatar

Pavlin Poličar pavlin-policar

View GitHub Profile
def confidence_histogram(y_true, y_probs, n_bins=10, ax=None):
if ax is None:
fig, ax = plt.subplots(figsize=(4, 4))
confidences = np.max(y_probs, axis=1)
predictions = np.argmax(y_probs, axis=1)
accuracies = predictions == y_true
bins = np.linspace(0, 1 - 1 / n_bins, n_bins)
bin_indices = np.digitize(confidences, bins=bins[1:])
import scipy.sparse as sp
import numpy as np
def plot_marker(
marker,
dataset,
embedding: np.ndarray,
binary=True,
s=1,
from sklearn.base import BaseEstimator
from sklearn.neighbors import NearestNeighbors
import numpy as np
import networkx as nx
from community import best_partition
def jaccard(x: set, y: set) -> float:
return len(x & y) / len(x | y)
from collections import OrderedDict
from typing import Iterable
import numpy as np
import scipy.sparse as sp
import scipy.stats as stats
import pandas as pd
def FDR(p_values: Iterable, dependent=False, m=None, ordered=False) -> Iterable:
def _get_required_decimals(x: np.ndarray) -> int:
"""Determine the number of decimals needed to nicely show the data."""
req_decimals = np.floor(np.log10(x))
dec = np.percentile(req_decimals, [5])
return abs(int(dec))
def smooth_line(x, y, sigma=5, interp_points=300):
from scipy.ndimage import gaussian_filter1d
x_interp = np.linspace(x.min(), x.max(), interp_points)
# The gaussian filter assumes spacing 1, so we have to adjust sigma
interp_diff = x_interp[1] - x_interp[0]
effective_sigma = sigma / interp_diff
y_interp = np.interp(x_interp, x, y)