itca package

Submodules

itca.metrics module

itca.metrics.adjusted_accuracy_score(y_true, y_pred, mapping, adjust_by='cardinal')

Adjusted accuracy is an adjustment for accuracy.

Parameters
  • y_true (int array, shape = [n_samples, ]) – A clustering of the data into disjoint subsets.

  • y_pred (int array, shape = [n_samples, ]) – A clustering of the data into disjoint subsets.

  • mapping (bidict, size = n_classes_ori) – transform the original labels to the merged labels.

  • adjust_by (str, "cardinal" or "size") –

Returns

aac

Return type

float ( 0 <= acc <= 1)

itca.metrics.class_accuracy(y_true, y_pred)
itca.metrics.itca(y_true, y_pred, mapping, y_dist=None)

Sample-level information-theoretic classification accuracy (s-ITCA)

Parameters
  • y_true (int array, shape = [n_samples, ]) – A clustering of the data into disjoint subsets.

  • y_pred (int array, shape = [n_samples, ]) – A clustering of the data into disjoint subsets.

  • mapping (bidict, size = n_classes_ori) – Transform the original labels to the merged labels.

  • y_dist (dict of length n_classes) – Distribution of the original classes.

Returns

itca_score

Return type

float

itca.metrics.prediction_entropy(y_true, y_pred, mapping, y_dist=None)

Compute the entropy of H(mapping(y_true), y_pred).

Parameters
  • y_true (numpy array, (n_samples, )) – True labels.

  • y_pred (numpy array, (n_samples, )) – Prediction labels.

  • mapping (bidict of size n_classes) – Class mapping.

Returns

The value of the prediction entropy

Return type

float

itca.search module

itca.simulator module

class itca.simulator.SimData(generator, X, y, centroids=None, probs=None)

Bases: object

Simulated data.

concat(sim_data)
shuffle()

Shuffle the simulated data

class itca.simulator.SimLDA(centroids, covariance)

Bases: object

gen(n_samples, seed=None)

Sampling.

Parameters

n_samples (int, total number of samples; array-like, shape = [n_classes, ]) –

Returns

probs: None y: class labels, integer array X: covairates, shape = [n_features, n_samples]

Return type

SimData(None, y, X)

class itca.simulator.SimOrdLogit(n_classes, coeff, intercepts)

Bases: object

Generate simulation objects from ordinal logistic regression model.

gen(n_samples, X=None, seed=None)

Generate data.

Returns

probs: probability distribution, shape = [n_classes, n_samples] y: class labels, integer array X: covairates, shape = [n_features, n_samples]

Return type

SimData(probs, y, X)

logodds_to_probs(logodds)

Compute probablilities by logodds.

probs_to_logodds(probs)
probs_to_x(probs)

Compute the covariates x by probability.

Parameters

probs (shape = [n_classes, n_samples]) –

x_to_logodds(x)

Compute log odds from covariates.

itca.simulator.sim_merged_y(y_ori, transform, accuracy=0.9, seed=None, p=None)

Generate the merged clustering given the original labels y_ori, transform and accuracy.

itca.simulator.sim_y(n_samples, n_classes, accuracy=0.9, seed=None, p=None)

Generate ground truth of labels and the prediction labels

itca.utils module

class itca.utils.bidict(*args, **kwargs)

Bases: dict

Bidirectional dictionary inherited from the built-in dict to represent the class combination map. bidict is initialized. The methods of bidict are consistent with those of the built-in class dict.

inverse: dict

Inverse of the class combination map.

map(arr)

Map the original labels to the combined labels.

map_reverse(arr)

Reverse map the combined labels to the original labels.

Examples

>>> bd = bidict({0:0, 1:0, 2:1}) # a class combination map that combines class 0 and 1 into one.
... {0:0, 1:0, 2:1}
>>> bd.inverse
... {0: [0, 1], 1: [2]}
>>> y1 = np.array([0, 0, 1, 1, 2, 2])
>>> bd.map(y1)
... array([0, 0, 0, 0, 1, 1])
>>> y2 = array([0, 0, 0, 0, 1, 1])
>>> bd.reverse_map(y2)
... array([0, 1, 0, 1, 2, 2]) # randomly assign labels with equal probability
>>> bd.reverse_map(y2)
... array([0, 0, 1, 0, 2, 2])
map(arr)

Map the original labels to the combined labels.

reverse_map(arr)

Reverse map the combined labels to the original labels.

itca.utils.bv2transformation(v)

Convert binary vector to transformation.

itca.utils.bvstr2bv(bvstr)
itca.utils.compute_hamming_distance(v1, v2)

Compute the Hamming distance between two binary strings or binary vector

Parameters
  • v1 (str or binary array) – A binary vector or string.

  • v2 (str or binary array) – The compared binary vector or string.

Returns

The Hamming distance between the two vectors.

Return type

int

itca.utils.compute_y_dist(y)

Compute the distribution of labels given the label vectors.

Parameters

y (numpy array) – Class labels vector whose values range from 0 to K - 1

Returns

A dictionary whose keys indicate the class labels and values indicate the corresponding proportions.

Return type

dict

Examples

>>> y = np.array([0, 0, 1, 1])
>>> y = compute_y_dist(y)
...   {0: 0.5, 1:0.5}
itca.utils.enumerate_transforms(n_classes_ori, n_classes_mer)

Enumerate all

itca.utils.eval_metrics(X, y, mapping, clf, metrics, kfolds=5)

Compute metrics.

itca.utils.extend_classes(y_ori, transform)

Extend the original labels y_ori to the extended labels by transform.

itca.utils.int2bvstr(classes_num, a)
itca.utils.int2mapping(observed_classes, i)
itca.utils.inv_logit(x)

Inverse logit function.

itca.utils.perm_labels(y_true, n_samples, accuracy)
itca.utils.prob_support(labels)

Convert array-like labels to (n_samples, n_classes) probility support.

Module contents