Created
October 16, 2018 06:53
-
-
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).
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 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