Distance Matrix (distmatrix)

class Orange.misc.distmatrix.DistMatrix[source]

Distance matrix. Extends numpy.ndarray.

row_items

Items corresponding to matrix rows.

col_items

Items corresponding to matrix columns.

axis

If axis=1 we calculate distances between rows, if axis=0 we calculate distances between columns.

dim

Returns the single dimension of the symmetric square matrix.

submatrix(row_items, col_items=None)[source]

Return a submatrix

Args:
row_items: indices of rows col_items: incides of columns
classmethod from_file(filename)[source]

Load distance matrix from a file

The file should be preferrably encoded in ascii/utf-8. White space at the beginning and end of lines is ignored.

The first line of the file starts with the matrix dimension. It can be followed by a list flags

  • axis=<number>: the axis number
  • symmetric: the matrix is symmetric; when reading the element (i, j) it’s value is also assigned to (j, i)
  • asymmetric: the matrix is asymmetric
  • row_labels: the file contains row labels
  • col_labels: the file contains column labels

By default, matrices are symmetric, have axis 1 and no labels are given. Flags labeled and labelled are obsolete aliases for row_labels.

If the file has column labels, they follow in the second line. Row labels appear at the beginning of each row. Labels are arbitrary strings that cannot contain newlines and tabulators. Labels are stored as instances of Table with a single meta attribute named “label”.

The remaining lines contain tab-separated numbers, preceded with labels, if present. Lines are padded with zeros if necessary. If the matrix is symmetric, the file contains the lower triangle; any data above the diagonal is ignored.

Args:
filename: file name
has_row_labels()[source]

Returns True if row labels can be automatically determined from data

For this, the row_items must be an instance of Orange.data.Table whose domain contains a single meta attribute, which has to be a string. The domain may contain other variables, but not meta attributes.

has_col_labels()[source]

Returns True if column labels can be automatically determined from data

For this, the col_items must be an instance of Orange.data.Table whose domain contains a single meta attribute, which has to be a string. The domain may contain other variables, but not meta attributes.

save(filename)[source]

Save the distance matrix to a file in the file format described at from_file.

Args:
filename: file name