Skip to content

Instantly share code, notes, and snippets.

@Jarino
Created October 16, 2018 06:53
Show Gist options
  • Select an option

  • Save Jarino/b116234252379cffc789a602963262ce to your computer and use it in GitHub Desktop.

Select an option

Save Jarino/b116234252379cffc789a602963262ce to your computer and use it in GitHub Desktop.
Compute the sum of pairwise distances between points of one class and rest of the data (i.e. inter-class distance).
from sklearn.datasets import make_blobs
x_train, y_train = make_blobs(100, 2, 3)
# import matplotlib.pyplot as plt
# plt.scatter(x_train[:,0], x_train[:,1], c=y_train);
from sklearn.metrics import pairwise_distances
p_dist = pairwise_distances(x_train)
# sum of distances between points from class 0 and points from all other classes
import numpy as np
np.sum(p_dist[np.ix_(y_train ==0, y_train!=0)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment