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
# Load the dataset | |
x,y = load_iris(return_X_y=True) | |
# Split it in training and validation | |
x_t, x_v, y_t, y_v = train_test_split(x, y, test_size=0.2, shuffle=True, random_state=42) | |
# Build a representation of the problem | |
arg = {'threads': cpu_count(), 'weights': False} | |
prb = Prototype(x_t, x_v, y_t, y_v, 'ETS', 'classification', 'acc', **arg) | |
# Instantiate and run a one-shot learning based on the given configuration | |
exp = Experiment() | |
exp.single(prb, random_state=42) |
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.metrics import confusion_matrix | |
def kappa_score(y_true, y_pred): | |
cfm = confusion_matrix(y_true, y_pred) | |
n_c = len(np.unique(y_true)) | |
s_0 = np.sum(cfm, axis=0) | |
s_1 = np.sum(cfm, axis=1) | |
exp = np.outer(s_0, s_1).astype(np.double) / np.sum(s_0) | |
mat = np.ones([n_c, n_c], dtype=np.int) |
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
def define_clusters(lst, fil, neighbors): | |
# lst -> ordered list of indexes | |
# fil -> mapped dictionnary of filtration values with indexes | |
# neighbors -> number of closest elements to consider per query | |
unf = UnionFind() | |
for idx in lst: | |
grp, srt = [], np.where(lst == idx)[0][0] |
NewerOlder