Skip to content

khiops.core.coclustering_results

Submodule of khiops.core

Classes to access Khiops Coclustering JSON reports

Class Overview

Below we describe with diagrams the relationships of the classes in this modules. They are mostly compositions (has-a relations) and we omit native attributes (str, int, float, etc).

The main class of this module is CoclusteringResults and it is largely a composition of sub-reports objects given by the following structure:

CoclusteringResults
|- coclustering_report -> CoclusteringReport

CoclusteringReport
|- dimensions -> list of CoclusteringDimension
|- cells      -> list of CoclusteringCell

CoclusteringDimension
|- parts                     -> list of CoclusteringDimensionPart
|- inner_variable_dimensions -> list of CoclusteringDimension
|- clusters                  -> list of CoclusteringCluster
|- root_cluster              -> CoclusteringCluster

CoclusteringDimensionPartValueGroup
|- values -> list of CoclusteringDimensionPartValue

CoclusteringCluster
|- leaf_part        -> CoclusteringDimensionPart or None
|- parent_cluster  |
|- child_cluster1  |-> CoclusteringCluster or None
|- child_cluster2  |

To have a complete illustration of the access to the information of all classes in this module look at their [to_dict][] methods which write Python dictionaries in the same format as the Khiops JSON reports.

CLASS DESCRIPTION
CoclusteringResults

Main class containing the information of a Khiops Coclustering JSON file

CoclusteringReport

Main coclustering report

CoclusteringDimension

A coclustering dimension (variable)

CoclusteringDimensionPart

An element of a partition of a dimension

CoclusteringDimensionPartInterval

An interval of a numerical partition

CoclusteringDimensionPartValueGroup

A value group of a categorical partition

CoclusteringDimensionPartValue

A specific value of a variable in a dimension value group.

CoclusteringCluster

A cluster in a coclustering dimension hierarchy

CoclusteringCell

A coclustering cell

FUNCTION DESCRIPTION
read_coclustering_results_file

Reads a Khiops Coclustering JSON report

Classes

CoclusteringResults(json_data=None)

Bases: KhiopsJSONObject

Main class containing the information of a Khiops Coclustering JSON file

PARAMETER DESCRIPTION
json_data

Python dictionary representing the data of a Khiops Coclustering JSON report file. If not specified it returns an empty instance.

Note

Prefer the read_coclustering_results_file function from the core API to obtain an instance of this class from a Khiops Coclustering JSON file.

TYPE: dict DEFAULT: None

ATTRIBUTE DESCRIPTION
tool

Name of the Khiops tool that generated the JSON file.

TYPE: str

version

Version of the Khiops tool that generated the JSON file.

TYPE: str

coclustering_report

Coclustering modeling report.

TYPE: CoclusteringReport

See class docstring

METHOD DESCRIPTION
to_dict

Transforms this instance to a dict with the Khiops JSON file structure

write_report_file

Writes a TSV report file with the object's information

write_report

Writes the instance's TSV report to a writer object

Methods:

to_dict()

Transforms this instance to a dict with the Khiops JSON file structure

write_report_file(report_file_path)

Writes a TSV report file with the object's information

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
report_file_path

Path of the output TSV report file.

TYPE: str

write_report(stream_or_writer)

Writes the instance's TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
stream_or_writer

Output stream or writer.

TYPE: IOBase or KhiopsOutputWriter

CoclusteringReport(json_data=None)

Main coclustering report

A coclustering is an unsupervised data grid equipped with additional structures to ease its exploration. In particular, it is a piecewise constant density estimator of the data distribution. The additional structures are the following:

  • A cluster hierarchy for each dimension
  • Indicators (such as the interest) for each variable, part and value.

A coclustering consists of one to many variables (dimensions), where each variable is partitioned as:

  • Intervals in the numerical case
  • Individual values or value groups in the categorical case.

The cross-product of the partitions forms a multivariate partition of cells and their frequencies allow to estimate the multivariate density.

In case of an unsupervised data grid, the cells are described by their index on the variable partitions, together with their frequencies.

PARAMETER DESCRIPTION
json_data

JSON data of the coclusteringReport field of a Khiops Coclustering JSON report file. If not specified it returns an empty instance.

TYPE: dict DEFAULT: None

ATTRIBUTE DESCRIPTION
instance_number

Number of individuals in the learning data table.

TYPE: int

cell_number

Number of coclustering cells.

TYPE: int

null_cost

Cost of the null model.

TYPE: float

level

Measure between 0 and 1 measuring the information gain over the null model.

TYPE: float

initial_dimension_number

Initial number of dimensions. The number of dimensions (len(dimensions)) may be less than this quantity after a simplification (see api.simplify_coclustering).

TYPE: int

frequency_variable

Name of the variable to be aggregated in the cells. By default is the number of individuals.

TYPE: str

dictionary

Name dictionary from which the model was learned.

TYPE: str

database

Path of the main training data table file.

TYPE: str

sample_percentage

Percentage of instances used in training.

TYPE: float

sampling_mode

Sampling mode used to split the train and datasets.

TYPE: 'Include sample' or 'Exclude samples'

selection_variable

Variable used to select instances for training.

TYPE: str

selection_value

Value of selection_variable to select instances for training.

TYPE: str

dimensions

Coclustering dimensions (variable).

TYPE: list of CoclusteringDimension

cells

Coclustering cells.

TYPE: list of CoclusteringCell

See class docstring

METHOD DESCRIPTION
get_dimension_names

Returns the names of the available dimensions

get_dimension

Returns the specified dimension

to_dict

Transforms this instance to a dict with the Khiops JSON file structure

write_report

Writes the instance's TSV report to a writer object

write_dimensions

Writes the "dimensions" section of the TSV report to a writer object

write_coclustering_stats

Writes the "stats" section of the TSV report to a writer object

write_bounds

Writes the "bounds" section of the TSV report to a writer object

write_hierarchies

Writes the dimension reports' "hierarchy" sections to a writer object

write_compositions

Writes the dimensions' "composition" sections to a writer object

write_cells

Writes the "cells" section of the TSV report to a writer object

write_annotations

Writes the dimensions' "annotation" sections to a writer object

Methods:

get_dimension_names()

Returns the names of the available dimensions

RETURNS DESCRIPTION
list of str

The names of the available dimensions.

get_dimension(dimension_name)

Returns the specified dimension

PARAMETER DESCRIPTION
dimension_name

Name of the dimension (variable).

TYPE: str

RETURNS DESCRIPTION
CoclusteringDimension

The specified dimension.

RAISES DESCRIPTION
KeyError

If no dimension with the specified names exist.

to_dict()

Transforms this instance to a dict with the Khiops JSON file structure

write_report(writer)

Writes the instance's TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output stream or writer.

TYPE: KhiopsOutputWriter

write_dimensions(writer)

Writes the "dimensions" section of the TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_coclustering_stats(writer)

Writes the "stats" section of the TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_bounds(writer)

Writes the "bounds" section of the TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_hierarchies(writer)

Writes the dimension reports' "hierarchy" sections to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_compositions(writer)

Writes the dimensions' "composition" sections to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_cells(writer)

Writes the "cells" section of the TSV report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_annotations(writer)

Writes the dimensions' "annotation" sections to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

CoclusteringDimension()

A coclustering dimension (variable)

A coclustering dimension is a hierarchical clustering of an input variable. The leaves of this hierarchy are linked to an element of a partition of the input variable. Leaf clusters have variable parts as their children.

It only has a no-parameter constructor.

Note

The instance information is initialized with the init_summary, init_partition and init_hierarchy methods. Its owner object (class CoclusteringReport) uses the information found in the fields dimensionSummaries, dimensionPartitions and dimensionHierarchies to coherently initialize the all dimensions with these methods.

ATTRIBUTE DESCRIPTION
name

Name of the variable associated to this dimension.

TYPE: str

is_variable_part

True if the dimension is a part of a variable in an instance-variable coclustering.

TYPE: bool

type

Dimension type.

TYPE: Numerical or Categorical

part_number

Number of parts of the variable associated to this dimension.

TYPE: int

initial_part_number

Number of initial parts. Note that part_number <= initial_part_number after a coclustering simplification (see api.simplify_coclustering).

TYPE: int

value_number

Number of values of the dimension's variable.

TYPE: int

interest

Interest of the dimension with respect to the other coclustering dimensions.

TYPE: float

description

Description of the dimension/variable.

TYPE: str

min

Minimum value of a numerical dimension/variable.

TYPE: float

max

Maximum value of a numerical dimension/variable.

TYPE: float

parts

Partition of this dimension.

TYPE: list of CoclusteringDimensionPart

inner_variable_dimensions

Variable part instance-variable coclustering dimensions. None for variable-variable clustering. Contains the dimensions of the variables involved in the instances x variables coclustering model. This model includes two dimensions: one for instances and one for variable parts (isVarPart set to True for this dimension).

TYPE: list of CoclusteringDimension

clusters

Clusters of this dimension's hierarchy. Note that includes intermediary clusters.

TYPE: list of CoclusteringCluster

root_cluster

Root cluster of the hierarchy.

TYPE: CoclusteringCluster

See class docstring

METHOD DESCRIPTION
init_summary

Initializes the summary attributes from a Python JSON object

init_partition

Initializes the partition attributes from a Python JSON object

init_hierarchy

Initializes the hierarchy attributes from a Python JSON object

get_part

Returns a part of the dimension given the part's name

get_cluster

Returns the specified cluster

to_dict

Transforms this instance to a dict with the Khiops JSON file structure

write_dimension_header_line

Writes the "dimensions" section header to a writer object

write_dimension_line

Writes the "dimensions" section line to a writer object

write_hierarchy

Writes the "hierarchy" section to a writer object

write_composition

Writes the "composition" section to a writer object

write_annotation

Writes the "annotation" section to a writer object

needs_annotation_report

Status about the annotation report

write_hierarchy_structure_report_file

Writes the hierarchical structure of the clusters to a file

Methods:

init_summary(json_data=None)

Initializes the summary attributes from a Python JSON object

PARAMETER DESCRIPTION
json_data

Dictionary representing the data of an element of the list found at the dimensionSummaries field of a Khiops Coclustering JSON report file. If not specified it leaves the object as-is.

TYPE: dict DEFAULT: None

RETURNS DESCRIPTION
self

A reference to the caller instance.

init_partition(json_data=None)

Initializes the partition attributes from a Python JSON object

PARAMETER DESCRIPTION
json_data

Python dictionary representing the data of an element of the list found at the dimensionPartitions field of a Khiops Coclustering JSON report file. If not specified it leaves the object as-is.

TYPE: dict DEFAULT: None

RETURNS DESCRIPTION
self

A reference to the caller instance.

init_hierarchy(json_data)

Initializes the hierarchy attributes from a Python JSON object

PARAMETER DESCRIPTION
json_data

Python dictionary representing the data of an element of the list found at the dimensionHierarchies field of a Khiops Coclustering JSON report file. If not specified it leaves the object as-is.

TYPE: dict

RETURNS DESCRIPTION
self

A reference to the caller instance.

get_part(part_name)

Returns a part of the dimension given the part's name

PARAMETER DESCRIPTION
part_name

Name of the part.

TYPE: str

RETURNS DESCRIPTION
CoclusteringDimensionPart

The part with the specified name.

RAISES DESCRIPTION
KeyError

If there is no part with the specified name.

get_cluster(cluster_name)

Returns the specified cluster

PARAMETER DESCRIPTION
cluster_name

Name of the cluster.

TYPE: str

RETURNS DESCRIPTION
CoclusteringCluster

The specified cluster.

RAISES DESCRIPTION
KeyError

If there is no cluster with the specified name.

to_dict(report_type)

Transforms this instance to a dict with the Khiops JSON file structure

PARAMETER DESCRIPTION
report_type

Type of the report. Can be either one of "summary", "dimension", and "hierarchy".

TYPE: str

write_dimension_header_line(writer)

Writes the "dimensions" section header to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_dimension_line(writer)

Writes the "dimensions" section line to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_hierarchy(writer)

Writes the "hierarchy" section to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_composition(writer)

Writes the "composition" section to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_annotation(writer)

Writes the "annotation" section to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

needs_annotation_report()

Status about the annotation report

RETURNS DESCRIPTION
bool

True if the "annotation" section is reported

write_hierarchy_structure_report_file(report_file_path)

Writes the hierarchical structure of the clusters to a file

This method is mainly a test of the encoding of the cluster hierarchy.

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
report_file_path

Path of the output file.

TYPE: str

CoclusteringDimensionPart(json_data=None)

An element of a partition of a dimension

Abstract class.

PARAMETER DESCRIPTION
json_data

See child classes for specific information about this parameter.

DEFAULT: None

ATTRIBUTE DESCRIPTION
cluster_name

Name of the cluster to which this part belongs.

TYPE: str

See class docstring

Methods:

CoclusteringDimensionPartInterval(json_data=None)

Bases: CoclusteringDimensionPart

An interval of a numerical partition

PARAMETER DESCRIPTION
json_data

Python dictionary representing an element of type "Numerical" of the list at the dimensionPartitions field of a Khiops Coclustering JSON report file. If not specified it returns an empty instance.

TYPE: dict DEFAULT: None

RAISES DESCRIPTION
KhiopsJSONError

If json_data does not contain a "cluster" key.

ATTRIBUTE DESCRIPTION
cluster_name

Name of the cluster containing this interval.

TYPE: str

lower_bound

Lower bound of the interval.

TYPE: float

upper_bound

Upper bound of the interval.

TYPE: float

is_missing

True if the instance's represent the missing values. In this case lower_bound and upper_bound are set to None.

TYPE: bool

is_left_open

True if the interval is unbounded below lower_bound may contain the minimum value of the training data.

TYPE: bool

is_right_open

True if the interval is unbounded above upper_bound may contain the maximum value of training data.

TYPE: bool

See class docstring

METHOD DESCRIPTION
to_dict

Transforms this instance to a dict with the Khiops JSON file structure

__str__

Returns a human-readable string representation

part_type

Part type of this instance

Methods:

to_dict()

Transforms this instance to a dict with the Khiops JSON file structure

__str__()

Returns a human-readable string representation

part_type()

Part type of this instance

RETURNS DESCRIPTION
str

Only possible value: "Interval".

CoclusteringDimensionPartValueGroup(json_data=None)

Bases: CoclusteringDimensionPart

A value group of a categorical partition

PARAMETER DESCRIPTION
json_data

Python dictionary representing an element of type "Categorical" of the list at the dimensionPartitions field of a Khiops Coclustering JSON report file. If None it returns an empty instance.

TYPE: dict DEFAULT: None

RAISES DESCRIPTION
KhiopsJSONError

If json_data does not contain a "cluster" key.

ATTRIBUTE DESCRIPTION
cluster_name

Name of the cluster containing this group.

TYPE: str

values

The singleton parts composing this group part.

TYPE: list of CoclusteringDimensionPartValue

is_default_part

True if the instance represents the "unknown values" group.

TYPE: bool

Constructs an instance from a python JSON object

METHOD DESCRIPTION
__str__

Returns a human-readable string representation

to_dict

Transforms this instance to a dict with the Khiops JSON file structure

part_type

Part type of this instance

Methods:

__str__()

Returns a human-readable string representation

to_dict()

Transforms this instance to a dict with the Khiops JSON file structure

part_type()

Part type of this instance

RETURNS DESCRIPTION
str

Only possible value: "Value group".

CoclusteringDimensionPartValue()

A specific value of a variable in a dimension value group.

Note

This class has only a no-parameter constructor initializing an instance with the default values.

ATTRIBUTE DESCRIPTION
value

String representation of the value.

TYPE: str

frequency

Number of individuals having this value.

TYPE: int

typicality

Indicates how much the value is representative of the cluster. Ranges from 0 to 1, 1 being completely representative.

TYPE: float

See class doctstring

Methods:

CoclusteringCluster(json_data=None)

A cluster in a coclustering dimension hierarchy

PARAMETER DESCRIPTION
json_data

JSON data of an element of the list at the dimensionHierarchies field within the coclusteringReport field of a Khiops Coclustering JSON report file. If not specified it returns an empty instance.

TYPE: dict DEFAULT: None

ATTRIBUTE DESCRIPTION
name

Name of the cluster.

TYPE: str

parent_cluster_name

Name of the parent cluster.

TYPE: str

frequency

Number of individuals in the cluster.

TYPE: int

interest

The cluster's interest/informativeness.

TYPE: float

hierarchical_level

A measure interpretable as the distance of the cluster to the root. Between 0 and 1.

TYPE: float

rank

Rank of clusters in the top-down list of clusters, with the smallest ranks at the top.

TYPE: int

hierarchical_rank

Rank of clusters in the hierarchy, with the smallest ranks being the closest from the root of the hierarchy.

TYPE: int

is_leaf

True if the cluster is a leaf of the hierarchy.

TYPE: bool

short_description

Succinct cluster description.

TYPE: str

description

Cluster description.

TYPE: str

leaf_part

On a leaf cluster: Its unique associated partition element. Otherwise None.

TYPE: CoclusteringDimensionPart

parent_cluster

On a non-root cluster: Its unique parent cluster. Otherwise None.

TYPE: CoclusteringCluster

child_cluster1

On a non-leaf cluster : The first child cluster. Otherwise None.

TYPE: CoclusteringCluster

child_cluster2

On a non-leaf cluster : The second child cluster. Otherwise None.

TYPE: CoclusteringCluster

See class docstring

METHOD DESCRIPTION
to_dict

Transforms this instance to a dict with the Khiops JSON file structure

write_hierarchy_header_line

Writes the "hierarchy" section's header to a writer object

write_hierarchy_line

Writes a line of the "hierarchy" section to a writer object

write_annotation_header_line

Writes the "annotation" section's header to a writer object

write_annotation_line

Writes a line of the "annotation" section to a writer object

write_hierarchy_structure_report

Writes the hierarchical structure from this instance to a writer object

Methods:

to_dict()

Transforms this instance to a dict with the Khiops JSON file structure

write_hierarchy_header_line(writer)

Writes the "hierarchy" section's header to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_hierarchy_line(writer)

Writes a line of the "hierarchy" section to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_annotation_header_line(writer)

Writes the "annotation" section's header to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_annotation_line(writer)

Writes a line of the "annotation" section to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

write_hierarchy_structure_report(writer)

Writes the hierarchical structure from this instance to a writer object

This method is mainly a test of the encoding of the cluster hierarchy.

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12. Use the to_dict method instead.

PARAMETER DESCRIPTION
writer

Output writer for the report file.

TYPE: KhiopsOutputWriter

CoclusteringCell()

A coclustering cell

Note

This class has only a no-parameter constructor initializing an instance with the default values.

ATTRIBUTE DESCRIPTION
parts

Parts for each coclustering dimension.

TYPE: list of CoclusteringDimensionPart

part_indexes

Part indexes for each coclustering dimension.

TYPE: list of int

frequency

Frequency of this cell.

TYPE: int

Constructs an instance with default attribute values

METHOD DESCRIPTION
write_line

Writes a line of the instance's report to a writer object

Methods:

write_line(writer)

Writes a line of the instance's report to a writer object

Warning

This method is deprecated since Khiops 11.0.0 and will be removed in Khiops 12.

PARAMETER DESCRIPTION
writer

Output writer.

TYPE: KhiopsOutputWriter

Functions:

read_coclustering_results_file(json_file_path)

Reads a Khiops Coclustering JSON report

PARAMETER DESCRIPTION
json_file_path

Path of the JSON report file.

TYPE: str

RETURNS DESCRIPTION
CoclusteringResults

An instance of CoclusteringResults containing the report's information.