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:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
tool |
Name of the Khiops tool that generated the JSON file.
TYPE:
|
version |
Version of the Khiops tool that generated the JSON file.
TYPE:
|
coclustering_report |
Coclustering modeling report.
TYPE:
|
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)
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:
|
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
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
instance_number |
Number of individuals in the learning data table.
TYPE:
|
cell_number |
Number of coclustering cells.
TYPE:
|
null_cost |
Cost of the null model.
TYPE:
|
level |
Measure between 0 and 1 measuring the information gain over the null model.
TYPE:
|
initial_dimension_number |
Initial number of dimensions. The number of dimensions (
TYPE:
|
frequency_variable |
Name of the variable to be aggregated in the cells. By default is the number of individuals.
TYPE:
|
dictionary |
Name dictionary from which the model was learned.
TYPE:
|
database |
Path of the main training data table file.
TYPE:
|
sample_percentage |
Percentage of instances used in training.
TYPE:
|
sampling_mode |
Sampling mode used to split the train and datasets.
TYPE:
|
selection_variable |
Variable used to select instances for training.
TYPE:
|
selection_value |
Value of
TYPE:
|
dimensions |
Coclustering dimensions (variable).
TYPE:
|
cells |
Coclustering cells.
TYPE:
|
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:
|
| 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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
is_variable_part |
TYPE:
|
type |
Dimension type.
TYPE:
|
part_number |
Number of parts of the variable associated to this dimension.
TYPE:
|
initial_part_number |
Number of initial parts. Note that
TYPE:
|
value_number |
Number of values of the dimension's variable.
TYPE:
|
interest |
Interest of the dimension with respect to the other coclustering dimensions.
TYPE:
|
description |
Description of the dimension/variable.
TYPE:
|
min |
Minimum value of a numerical dimension/variable.
TYPE:
|
max |
Maximum value of a numerical dimension/variable.
TYPE:
|
parts |
Partition of this dimension.
TYPE:
|
inner_variable_dimensions |
Variable part instance-variable coclustering dimensions.
TYPE:
|
clusters |
Clusters of this dimension's hierarchy. Note that includes intermediary clusters.
TYPE:
|
root_cluster |
Root cluster of the hierarchy.
TYPE:
|
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
TYPE:
|
| 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
TYPE:
|
| 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
TYPE:
|
| 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:
|
| 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:
|
| 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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
cluster_name |
Name of the cluster to which this part belongs.
TYPE:
|
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
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KhiopsJSONError
|
If |
| ATTRIBUTE | DESCRIPTION |
|---|---|
cluster_name |
Name of the cluster containing this interval.
TYPE:
|
lower_bound |
Lower bound of the interval.
TYPE:
|
upper_bound |
Upper bound of the interval.
TYPE:
|
is_missing |
True if the instance's represent the missing values. In this case
TYPE:
|
is_left_open |
True if the interval is unbounded below
TYPE:
|
is_right_open |
True if the interval is unbounded above
TYPE:
|
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
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KhiopsJSONError
|
If |
| ATTRIBUTE | DESCRIPTION |
|---|---|
cluster_name |
Name of the cluster containing this group.
TYPE:
|
values |
The singleton parts composing this group part.
TYPE:
|
is_default_part |
True if the instance represents the "unknown values" group.
TYPE:
|
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:
|
frequency |
Number of individuals having this value.
TYPE:
|
typicality |
Indicates how much the value is representative of the cluster. Ranges from 0 to 1, 1 being completely representative.
TYPE:
|
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
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Name of the cluster.
TYPE:
|
parent_cluster_name |
Name of the parent cluster.
TYPE:
|
frequency |
Number of individuals in the cluster.
TYPE:
|
interest |
The cluster's interest/informativeness.
TYPE:
|
hierarchical_level |
A measure interpretable as the distance of the cluster to the root. Between 0 and 1.
TYPE:
|
rank |
Rank of clusters in the top-down list of clusters, with the smallest ranks at the top.
TYPE:
|
hierarchical_rank |
Rank of clusters in the hierarchy, with the smallest ranks being the closest from the root of the hierarchy.
TYPE:
|
is_leaf |
TYPE:
|
short_description |
Succinct cluster description.
TYPE:
|
description |
Cluster description.
TYPE:
|
leaf_part |
On a leaf cluster: Its unique associated partition element. Otherwise |
parent_cluster |
On a non-root cluster: Its unique parent cluster. Otherwise
TYPE:
|
child_cluster1 |
On a non-leaf cluster : The first child cluster. Otherwise
TYPE:
|
child_cluster2 |
On a non-leaf cluster : The second child cluster. Otherwise
TYPE:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
part_indexes |
Part indexes for each coclustering dimension.
TYPE:
|
frequency |
Frequency of this cell.
TYPE:
|
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:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
CoclusteringResults
|
An instance of CoclusteringResults containing the report's information. |