Skip to content

khiops.core.api

Submodule of khiops.core

API for the execution of the Khiops AutoML suite

The methods in this module allow to execute all Khiops and Khiops Coclustering tasks.

See Also
FUNCTION DESCRIPTION
get_khiops_version

Returns the Khiops version

get_samples_dir

Returns the Khiops' samples directory path

export_dictionary_as_json

Exports a Khiops dictionary file to JSON format (.kdicj)

build_dictionary_from_data_table

Builds a dictionary file by analyzing a data table file

check_database

Checks if a data table is compatible with a dictionary file

train_predictor

Trains a model from a data table

interpret_predictor

Builds an interpretation dictionary from a predictor

reinforce_predictor

Builds a reinforced predictor from a predictor

evaluate_predictor

Evaluates the predictors in a dictionary file on a database

train_recoder

Trains a recoding model from a data table

deploy_model

Deploys a model on a data table

build_deployed_dictionary

Builds a dictionary file to read the output table of a deployed model

sort_data_table

Sorts a data table

extract_keys_from_data_table

Extracts from data table unique occurrences of a key variable

train_coclustering

Trains a coclustering model from a data table

train_instance_variable_coclustering

Trains an instance-variable coclustering model from a data table

simplify_coclustering

Simplifies a coclustering model

prepare_coclustering_deployment

Prepares a individual-variable coclustering deployment

extract_clusters

Extracts clusters to a tab separated (TSV) file

detect_data_table_format

Detects the format of a data table

ATTRIBUTE DESCRIPTION
DEFAULT_CONSTRUCTION_RULES

List of construction rules that Khiops uses by default

CALENDRICAL_CONSTRUCTION_RULES

List of calendrical construction rules

Attributes

DEFAULT_CONSTRUCTION_RULES = ['GetValue', 'GetValueC', 'TableCount', 'TableCountDistinct', 'TableMax', 'TableMean', 'TableMedian', 'TableMin', 'TableMode', 'TableSelection', 'TableStdDev', 'TableSum'] module-attribute

List of construction rules that Khiops uses by default

Note

These are all the multi-table rules.

CALENDRICAL_CONSTRUCTION_RULES = ['Day', 'DecimalTime', 'DecimalWeekDay', 'DecimalYear', 'DecimalYearTS', 'GetDate', 'GetTime', 'LocalTimestamp', 'WeekDay', 'YearDay'] module-attribute

List of calendrical construction rules

These rules include: date, time and timestamp rules.

Note

These rules are not enabled by default. The user needs to explicitly select each of them via the construction_rules parameter of the relevant Core API functions.

Classes

Functions:

get_khiops_version()

Returns the Khiops version

RETURNS DESCRIPTION
str

The Khiops version of the current KhiopsRunner backend.

get_samples_dir()

Returns the Khiops' samples directory path

RETURNS DESCRIPTION
str

The path of the Khiops samples directory.

export_dictionary_as_json(dictionary_file_path_or_domain, json_dictionary_file_path, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='')

Exports a Khiops dictionary file to JSON format (.kdicj)

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

json_dictionary_file_path

Path (absolute path recommended) to the output dictionary file, in the JSON format. Note that a relative path will produce a file in the current working directory.

TYPE: str

See Also

Examples:

See the following function of the samples.py documentation script: - samples.export_dictionary_files()

build_dictionary_from_data_table(data_table_path, output_dictionary_name, output_dictionary_file_path, detect_format=True, header_line=None, field_separator=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Builds a dictionary file by analyzing a data table file

PARAMETER DESCRIPTION
data_table_path

Path of the data table file.

TYPE: str

output_dictionary_name

Name dictionary to be created.

TYPE: str

output_dictionary_file_path

Path (absolute path recommended) of the output dictionary file. Note that a relative path will produce a file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

See Also

check_database(dictionary_file_path_or_domain, dictionary_name, data_table_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, max_messages=20, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Checks if a data table is compatible with a dictionary file

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary of the table to be checked.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See the sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it checks sample_percentage percent of the data; if equal to "Exclude sample" it checks the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It checks only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

max_messages

Maximum number of error messages to write in the log file.

TYPE: int DEFAULT: 20

See Also

Examples:

See the following function of the samples.py documentation script: - samples.check_database()

train_predictor(dictionary_file_path_or_domain, dictionary_name, data_table_path, target_variable, analysis_report_file_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=70.0, sampling_mode='Include sample', use_complement_as_test=True, selection_variable='', selection_value='', additional_data_tables=None, do_data_preparation_only=False, main_target_value='', keep_selected_variables_only=True, max_evaluated_variables=0, max_selected_variables=0, max_constructed_variables=1000, construction_rules=None, max_text_features=10000, text_features='words', max_trees=10, max_pairs=0, all_possible_pairs=True, specific_pairs=None, group_target_value=False, discretization_method='MODL', grouping_method='MODL', max_parts=0, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Trains a model from a data table

Note

For all input dictionaries, this function creates model dictionaries whose names are prefixed with SNB_. For regression models, additional dictionaries are created and their names are prefixed with Baseline_.

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

target_variable

Name of the target variable. If the specified variable is categorical it constructs a classifier and if it is numerical a regressor. If equal to "" it performs an unsupervised analysis.

TYPE: str

analysis_report_file_path

Path (absolute path recommended) to the analysis report file, in the JSON format. An additional dictionary file with the same name and extension .model.kdic is built, which contains the trained models. Note that a relative path will produce a report file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See the sampling_mode option below.

TYPE: float DEFAULT: 70.0

sampling_mode

If equal to "Include sample" it trains the predictor on sample_percentage percent of the data and tests the model on the remainder of the data if use_complement_as_test is set to True. If equal to "Exclude sample" the train and test datasets above are exchanged. See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

use_complement_as_test

Uses the complement of the sampled database as test database for computing the model's performance metrics.

TYPE: bool DEFAULT: `True`

selection_variable

It trains with only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

do_data_preparation_only

If True it only does data preparation via MODL preprocessing without training a Selective Naive Bayes Predictor.

TYPE: bool DEFAULT: `False`

main_target_value

If this target value is specified then it guarantees the calculation of lift curves for it.

TYPE: str DEFAULT: ""

keep_selected_variables_only

Keeps only predictor-selected variables in the supervised analysis report.

TYPE: bool DEFAULT: `True`

max_evaluated_variables

Maximum number of variables to be evaluated in the SNB predictor training. If equal to 0 it evaluates all informative variables.

TYPE: int DEFAULT: 0

max_selected_variables

Maximum number of variables to be selected in the SNB predictor. If equal to 0 it selects all the variables kept in the training.

TYPE: int DEFAULT: 0

max_constructed_variables

Maximum number of variables to construct.

TYPE: int DEFAULT: 1000

construction_rules

Allowed rules for the automatic variable construction. If not set, Khiops uses the multi-table construction rules listed in DEFAULT_CONSTRUCTION_RULES.

TYPE: list of str DEFAULT: None

max_text_features

Maximum number of text features to construct.

TYPE: int DEFAULT: 10000

text_features

Type of the text features. Can be either one of:

- "words": sequences of non-space characters
- "ngrams": sequences of bytes
- "tokens": user-defined

TYPE: str DEFAULT: "words"

max_trees

Maximum number of trees to construct.

TYPE: int DEFAULT: 10

max_pairs

Maximum number of variable pairs to construct.

TYPE: int DEFAULT: 0

specific_pairs

User-specified pairs as a list of 2-tuples of feature names. If a given tuple contains only one non-empty feature name, then it generates all the pairs containing it (within the maximum limit max_pairs). These pairs have top priority: they are constructed first.

TYPE: list of tuple DEFAULT: None

all_possible_pairs

If True tries to create all possible pairs within the limit max_pairs. Pairs specified with specific_pairs have top priority: they are constructed first.

TYPE: bool DEFAULT: `True`

group_target_value

Allows grouping of the target variable values in classification. It can substantially increase the training time.

TYPE: bool DEFAULT: `False`

discretization_method

Name of the discretization method in case of unsupervised analysis. Its valid values are: "MODL", "EqualWidth", "EqualFrequency" or "none". Ignored for supervised analysis.

TYPE: str DEFAULT: "MODL"

grouping_method

Name of the grouping method in case of unsupervised analysis. Its valid values are: "MODL", "BasicGrouping" or "none". Ignored for supervised analysis.

TYPE: str DEFAULT: "MODL"

max_parts

Maximum number of variable parts produced by preprocessing methods. If equal to 0 it is automatically calculated. Special default values for unsupervised analysis:

- If `discretization_method` is "EqualWidth" or "EqualFrequency": 10
- If `grouping_method` is "BasicGrouping": 10

TYPE: int DEFAULT: 0

See Also
RETURNS DESCRIPTION
tuple

A 2-tuple containing: - The reports file path - The modeling dictionary file path in the supervised case.

RAISES DESCRIPTION
ValueError

Invalid values of an argument

TypeError

Invalid type of an argument

Examples:

See the following functions of the samples.py documentation script: - samples.train_predictor() - samples.train_predictor_file_paths() - samples.train_predictor_error_handling() - samples.train_predictor_mt() - samples.train_predictor_mt_with_specific_rules() - samples.train_predictor_with_train_percentage() - samples.train_predictor_with_trees() - samples.train_predictor_with_pairs() - samples.train_predictor_with_multiple_parameters() - samples.train_predictor_detect_format() - samples.train_predictor_with_cross_validation() - samples.multiple_train_predictor()

interpret_predictor(dictionary_file_path_or_domain, predictor_dictionary_name, interpretor_file_path, max_variable_importances=100, importance_ranking='Global', log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Builds an interpretation dictionary from a predictor

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

predictor_dictionary_name

Name of the predictor dictionary used while building the interpretation model.

TYPE: str

interpretor_file_path

Path to the interpretor dictionary file.

TYPE: str

max_variable_importances

Maximum number of variable importances to be selected in the interpretation model. If the predictor contains fewer variables than this number, then all the variables of the predictor are considered.

TYPE: int DEFAULT: 100

importance_ranking

Ranking of the Shapley values produced by the interpretor. Ca be one of: - "Global": predictor variables are ranked by decreasing global importance. - "Individual": predictor variables are ranked by decreasing individual Shapley value.

TYPE: str DEFAULT: "Global"

See Also
RAISES DESCRIPTION
ValueError

Invalid values of an argument

TypeError

Invalid type of an argument

Examples:

See the following functions of the samples.py documentation script: - samples.interpret_predictor() - samples.deploy_model_mt_with_interpretation()

reinforce_predictor(dictionary_file_path_or_domain, predictor_dictionary_name, reinforced_predictor_file_path, reinforcement_target_value='', reinforcement_lever_variables=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Builds a reinforced predictor from a predictor

A reinforced predictor is a model which increases the importance of specified lever variables in order to increase the probability of occurrence of the specified target value.

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

predictor_dictionary_name

Name of the predictor dictionary used while building the reinforced predictor.

TYPE: str

reinforced_predictor_file_path

Path to the reinforced predictor dictionary file.

TYPE: str

reinforcement_target_value

If this target value is specified, then its probability of occurrence is tentatively increased.

TYPE: str DEFAULT: ""

reinforcement_lever_variables

The names of variables to use as lever variables while building the reinforced predictor. Min length: 1. Max length: the total number of variables in the prediction model.

TYPE: list of str DEFAULT: None

See Also
RAISES DESCRIPTION
ValueError

Invalid values of an argument

TypeError

Invalid type of an argument

Examples:

See the following functions of the samples.py documentation script: - samples.reinforce_predictor() - samples.deploy_reinforced_model_mt()

evaluate_predictor(dictionary_file_path_or_domain, train_dictionary_name, data_table_path, evaluation_report_file_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, main_target_value='', log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Evaluates the predictors in a dictionary file on a database

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

train_dictionary_name

Name of the main dictionary used while training the models.

TYPE: str

data_table_path

Path of the evaluation data table file.

TYPE: str

evaluation_report_file_path

Path (absolute path recommended) to the evaluation report file, in the JSON format. Note that a relative path will produce a report file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it evaluates the predictor on sample_percentage percent of the data. If equal to "Exclude sample" it evaluates the predictor on the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It trains with only the records such that the value of selection_variable is equal to selection_value. Ignored if equal "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

Note

For external tables, use the initial dictionary name in the data paths, which is the same as the one used for training the predictor.

TYPE: dict DEFAULT: None

main_target_value

If this target value is specified then it guarantees the calculation of lift curves for it.

TYPE: str DEFAULT: ""

See Also
RETURNS DESCRIPTION
str

The path of the JSON evaluation report (extension .khj).

RAISES DESCRIPTION
TypeError

Invalid type of an argument.

Examples:

See the following functions of the samples.py documentation script: - samples.evaluate_predictor() - samples.access_predictor_evaluation_report() - samples.train_predictor_with_cross_validation()

train_recoder(dictionary_file_path_or_domain, dictionary_name, data_table_path, target_variable, analysis_report_file_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, max_constructed_variables=100, construction_rules=None, max_text_features=10000, text_features='words', max_trees=10, max_pairs=0, all_possible_pairs=True, specific_pairs=None, informative_variables_only=True, max_variables=0, keep_initial_categorical_variables=False, keep_initial_numerical_variables=False, categorical_recoding_method='part Id', numerical_recoding_method='part Id', pairs_recoding_method='part Id', group_target_value=False, discretization_method='MODL', grouping_method='MODL', max_parts=0, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Trains a recoding model from a data table

A recoding model consists in the discretization of numerical variables and the grouping of categorical variables.

If the target_variable is specified these partitions are constructed in supervised mode, meaning that each resulting discretizations/groupings best separates the target variable while maintaining a simple interval/group model of the data. Different recoding methods can be specified via the numerical_recoding_method, categorical_recoding_method and pairs_recoding_method options.

The output files of this process contain a dictionary file (.kdic) that can be used to recode databases with the deploy_model function.

Note

For all input dictionaries, this function creates model dictionaries whose names are prefixed with R_.

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be recoded.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

target_variable

Name of the target variable. If equal to "" it trains an unsupervised recoder.

TYPE: str

analysis_report_file_path

Path (absolute path recommended) to the analysis report file, in the JSON format. An additional dictionary file with the same name and extension .model.kdic is built, which contains the trained recoding model. Note that a relative path will produce a report file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it trains the recoder on sample_percentage percent of the data. If equal to "Exclude sample" it trains the recoder on the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It trains with only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

max_constructed_variables

Maximum number of variables to construct.

TYPE: int DEFAULT: 100

construction_rules

Allowed rules for the automatic variable construction. If not set, Khiops uses the multi-table construction rules listed in DEFAULT_CONSTRUCTION_RULES.

TYPE: list of str DEFAULT: None

max_text_features

Maximum number of text features to construct.

TYPE: int DEFAULT: 10000

text_features

Type of the text features. Can be either one of:

- "words": sequences of non-space characters
- "ngrams": sequences of bytes
- "tokens": user-defined

TYPE: str DEFAULT: "words"

max_trees

Maximum number of trees to construct.

TYPE: int DEFAULT: 10

max_pairs

Maximum number of variable pairs to construct.

TYPE: int DEFAULT: 0

specific_pairs

User-specified pairs as a list of 2-tuples of feature names. If a given tuple contains only one non-empty feature name, then it generates all the pairs containing it (within the maximum limit max_pairs). These pairs have top priority: they are constructed first.

TYPE: list of tuple DEFAULT: None

all_possible_pairs

If True tries to create all possible pairs within the limit max_pairs. Pairs specified with specific_pairs have top priority: they are constructed first.

TYPE: bool DEFAULT: `True`

group_target_value

Allows grouping of the target variable values in classification. It can substantially increase the training time.

TYPE: bool DEFAULT: `False`

informative_variables_only

If True keeps only informative variables.

TYPE: bool DEFAULT: `True`

max_variables

Maximum number of variables to keep. If equal to 0 keeps all variables.

TYPE: int DEFAULT: 0

keep_initial_categorical_variables

If True keeps the initial categorical variables.

TYPE: bool DEFAULT: `False`

keep_initial_numerical_variables

If True keeps initial numerical variables.

TYPE: bool DEFAULT: `False`

categorical_recoding_method

Type of recoding for categorical variables. Types available:

- "part Id" (default): An id for the interval/group
- "part label": A label for the interval/group
- "0-1 binarization": A 0's and 1's coding the interval/group id
- "conditional info": Conditional information of the interval/group
- "none": Keeps the variable as-is

TYPE: str DEFAULT: 'part Id'

numerical_recoding_method

Type of recoding recoding for numerical variables. Types available:

- "part Id" (default): An id for the interval/group
- "part label": A label for the interval/group
- "0-1 binarization": A 0's and 1's coding the interval/group id
- "conditional info": Conditional information of the interval/group
- "center-reduction": "(X - Mean(X)) / StdDev(X)"
- "0-1 normalization": "(X - Min(X)) / (Max(X) - Min(X))"
- "rank normalization": mean normalized rank (between 0 and 1) of the
  instances
- "none": Keeps the variable as-is

TYPE: str DEFAULT: 'part Id'

pairs_recoding_method

Type of recoding for bivariate variables. Types available:

- "part Id" (default): An id for the interval/group
- "part label": A label for the interval/group
- "0-1 binarization": A 0's and 1's coding the interval/group id
- "conditional info": Conditional information of the interval/group
- "none": Keeps the variable as-is

TYPE: str DEFAULT: 'part Id'

discretization_method

Name of the discretization method in case of unsupervised analysis. Its valid values are: "MODL", "EqualWidth", "EqualFrequency" or "none". Ignored for supervised analysis.

TYPE: str DEFAULT: "MODL"

grouping_method

Name of the grouping method in case of unsupervised analysis. Its valid values are: "MODL", "BasicGrouping" or "none". Ignored for supervised analysis.

TYPE: str DEFAULT: "MODL"

max_parts

Maximum number of variable parts produced by preprocessing methods. If equal to 0 it is automatically calculated. Special default values for unsupervised analysis:

- If `discretization_method` is "EqualWidth" or "EqualFrequency": 10
- If `grouping_method` is "BasicGrouping": 10

TYPE: int DEFAULT: 0

See Also
RETURNS DESCRIPTION
tuple

A 2-tuple containing:

- The path of the JSON file report of the process
- The path of the dictionary containing the recoding model

Examples:

See the following functions of the samples.py documentation script: - samples.train_recoder() - samples.train_recoder_with_multiple_parameters() - samples.train_recoder_mt_flatten()

deploy_model(dictionary_file_path_or_domain, dictionary_name, data_table_path, output_data_table_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, output_header_line=True, output_field_separator='\t', output_additional_data_tables=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Deploys a model on a data table

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object. This file/object defines the model to be deployed. Note that this model is not necessarily a predictor, it can be a generic table transformation.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

output_data_table_path

Path (absolute path recommended) of the output data file. Note that a relative path will produce a file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it deploys the model on sample_percentage percent of the data. If equal to "Exclude sample" it deploys the model on the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It deploys only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

Note

Use model dictionary data paths for external tables.

TYPE: dict DEFAULT: None

output_header_line

If True writes a header line with the column names in the output table.

TYPE: bool DEFAULT: `True`

output_field_separator

The field separator character for the output table ("" counts as "\t").

TYPE: str DEFAULT: "\\t"

output_additional_data_tables

A dictionary containing the output data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

See Also
RAISES DESCRIPTION
TypeError

Invalid type of an argument.

Examples:

See the following functions of the samples.py documentation script: - samples.deploy_model() - samples.deploy_model_mt() - samples.deploy_model_mt_with_interpretation() - samples.deploy_model_mt_snowflake() - samples.deploy_model_expert()

build_deployed_dictionary(dictionary_file_path_or_domain, dictionary_name, output_dictionary_file_path, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Builds a dictionary file to read the output table of a deployed model

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

output_dictionary_file_path

Path (absolute path recommended) of the output dictionary file. Note that a relative path will produce a file in the current working directory.

TYPE: str

See Also
RAISES DESCRIPTION
TypeError

Invalid type of an argument

Examples:

See the following functions of the samples.py documentation script: - samples.build_deployed_dictionary()

sort_data_table(dictionary_file_path_or_domain, dictionary_name, data_table_path, output_data_table_path, sort_variables=None, detect_format=True, header_line=None, field_separator=None, output_header_line=True, output_field_separator='\t', log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Sorts a data table

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

output_data_table_path

Path (absolute path recommended) of the output data file. Note that a relative path will produce a file in the current working directory.

TYPE: str

sort_variables

The names of the variables to sort. If not set sorts the table by its key.

TYPE: list of str DEFAULT: None

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

output_header_line

If True writes a header line with the column names in the output table.

TYPE: bool DEFAULT: `True`

output_field_separator

The field separator character for the output table ("" counts as "\t").

TYPE: str DEFAULT: "\\t"

See Also
RAISES DESCRIPTION
TypeError

Invalid type of a argument.

Examples:

See the following functions of the samples.py documentation script: - samples.sort_data_table() - samples.sort_data_table_expert()

extract_keys_from_data_table(dictionary_file_path_or_domain, dictionary_name, data_table_path, output_data_table_path, detect_format=True, header_line=None, field_separator=None, output_header_line=True, output_field_separator='\t', log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Extracts from data table unique occurrences of a key variable

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary of the data table.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

output_data_table_path

Path (absolute path recommended) of the output data file. Note that a relative path will produce a file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

output_header_line

If True writes a header line with the column names in the output table.

TYPE: bool DEFAULT: `True`

output_field_separator

The field separator character for the output table ("" counts as "\t").

TYPE: str DEFAULT: "\\t"

See Also
RAISES DESCRIPTION
TypeError

Invalid type of an argument.

Examples:

See the following function of the samples.py documentation script: - samples.extract_keys_from_data_table()

train_coclustering(dictionary_file_path_or_domain, dictionary_name, data_table_path, coclustering_variables, coclustering_report_file_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, frequency_variable='', min_optimization_time=0, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Trains a coclustering model from a data table

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

coclustering_variables

The names of variables to use in coclustering. Min length: 2. Max length: 10.

TYPE: list of str

coclustering_report_file_path

Path (absolute path recommended) to the coclustering report file, in the JSON format. Note that a relative path will produce a report file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it trains the coclustering estimator on sample_percentage percent of the data. If equal to "Exclude sample" it trains the coclustering estimator on the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It trains with only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

frequency_variable

Name of frequency variable.

TYPE: str DEFAULT: ""

min_optimization_time

Minimum optimization time in seconds.

TYPE: int DEFAULT: 0

See Also
RETURNS DESCRIPTION
str

The path of the of the resulting coclustering file.

RAISES DESCRIPTION
ValueError

Number of coclustering variables out of the range 2-10.

TypeError

Invalid type of an argument.

Examples:

See the following function of the samples.py documentation script: - samples.train_coclustering()

train_instance_variable_coclustering(dictionary_file_path_or_domain, dictionary_name, data_table_path, coclustering_report_file_path, detect_format=True, header_line=None, field_separator=None, sample_percentage=100.0, sampling_mode='Include sample', selection_variable='', selection_value='', additional_data_tables=None, min_optimization_time=0, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Trains an instance-variable coclustering model from a data table

Note

If keys are available in the input dictionary, they are used as instance identifiers. Otherwise, line numbers in the instance data table are used as instance idenfitiers.

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

data_table_path

Path of the data table file.

TYPE: str

coclustering_report_file_path

Path (absolute path recommended) to the coclustering report file, in the JSON format. Note that a relative path will produce a report file in the current working directory.

TYPE: str

detect_format

If True detects automatically whether the data table file has a header and its field separator. It is set to False if header_line or field_separator are set.

TYPE: bool DEFAULT: `True`

header_line

If True it uses the first line of the data as column names. Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: bool, optional (default `True`) DEFAULT: None

field_separator

A field separator character. "" has the same effect as "\t". Sets detect_format to False if set. Ignored if detect_format is True.

TYPE: str, optional (default "\\t") DEFAULT: None

sample_percentage

See sampling_mode option below.

TYPE: float DEFAULT: 100.0

sampling_mode

If equal to "Include sample" it trains the coclustering estimator on sample_percentage percent of the data. If equal to "Exclude sample" it trains the coclustering estimator on the complement of the data selected with "Include sample". See also Database Sampling.

TYPE: 'Include sample' or 'Exclude sample' DEFAULT: 'Include sample'

selection_variable

It trains with only the records such that the value of selection_variable is equal to selection_value. Ignored if equal to "".

TYPE: str DEFAULT: ""

selection_value

See selection_variable option above. Ignored if equal to "".

DEFAULT: ''

additional_data_tables

A dictionary containing the data paths and file paths for a multi-table dictionary file. For more details see Multi-Table Learning Primer.

TYPE: dict DEFAULT: None

min_optimization_time

Minimum optimization time in seconds.

TYPE: int DEFAULT: 0

See Also
RETURNS DESCRIPTION
str

The path of the of the resulting coclustering file.

RAISES DESCRIPTION
ValueError

Number of coclustering variables out of the range 2-10.

TypeError

Invalid type of an argument.

Examples:

See the following function of the samples.py documentation script: - samples.train_instance_variable_coclustering()

simplify_coclustering(coclustering_file_path, simplified_coclustering_file_path, results_dir=None, max_preserved_information=0, max_cells=0, max_total_parts=0, max_part_numbers=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Simplifies a coclustering model

PARAMETER DESCRIPTION
coclustering_file_path

Path of the coclustering file (extension .khc, or .khcj).

TYPE: str

simplified_coclustering_file_path

Path (absolute path recommended) of the output coclustering file. Note that a relative path will produce a report file in the current working directory.

TYPE: str

max_preserved_information

Maximum information preserve in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_cells

Maximum number of cells in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_total_parts

Maximum number of parts totaled over all variables. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_part_numbers

Dictionary that associate variable names to their maximum number of parts to preserve in the simplified coclustering. If not set there is no limit.

TYPE: dict DEFAULT: None

See Also
RAISES DESCRIPTION
TypeError

Invalid type of an argument.

Examples:

See the following function of the samples.py documentation script: - samples.simplify_coclustering()

prepare_coclustering_deployment(dictionary_file_path_or_domain, dictionary_name, coclustering_file_path, table_variable, deployed_variable_name, coclustering_dictionary_file_path, max_preserved_information=0, max_cells=0, max_total_parts=0, max_part_numbers=None, build_cluster_variable=True, build_distance_variables=False, build_frequency_variables=False, variables_prefix='', log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Prepares a individual-variable coclustering deployment

PARAMETER DESCRIPTION
dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain

dictionary_name

Name of the dictionary to be analyzed.

TYPE: str

coclustering_file_path

Path of the coclustering model file (extension .khc or .khcj).

TYPE: str

table_variable

Name of the table variable in the dictionary.

TYPE: str

deployed_variable_name

Name of the coclustering variable to deploy.

TYPE: str

coclustering_dictionary_file_path

Path of the coclustering dictionary file for deployment.

TYPE: str

max_preserved_information

Maximum information preserve in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_cells

Maximum number of cells in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_total_parts

Maximum number of parts totaled over all variables. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_part_numbers

Dictionary associating variable names to their maximum number of parts to preserve in the simplified coclustering. For variables not present in max_part_numbers there is no limit.

TYPE: dict DEFAULT: None

build_cluster_variable

If True includes a cluster id variable in the deployment.

TYPE: bool DEFAULT: `True`

build_distance_variables

If True includes a cluster distance variable in the deployment.

TYPE: bool DEFAULT: `False`

build_frequency_variables

If True includes the frequency variables in the deployment.

TYPE: bool DEFAULT: `False`

variables_prefix

Prefix for the variables in the deployment dictionary.

TYPE: str DEFAULT: ""

See Also
RAISES DESCRIPTION
TypeError

Invalid type of an argument

Examples:

See the following function of the samples.py documentation script: - samples.deploy_model_expert()

extract_clusters(coclustering_file_path, cluster_variable, clusters_file_path, max_preserved_information=0, max_cells=0, max_total_parts=0, max_part_numbers=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Extracts clusters to a tab separated (TSV) file

PARAMETER DESCRIPTION
coclustering_file_path

Path of the coclustering model file (extension .khc or .khcj).

TYPE: str

cluster_variable

Name of the variable for which the clusters are extracted.

TYPE: str

clusters_file_path

Path (absolute path recommended) of the output clusters TSV file. Note that a relative path will produce a file in the current working directory.

TYPE: str

max_preserved_information

Maximum information preserve in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_cells

Maximum number of cells in the simplified coclustering. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_total_parts

Maximum number of parts totaled over all variables. If equal to 0 there is no limit.

TYPE: int DEFAULT: 0

max_part_numbers

Dictionary that associate variable names to their maximum number of parts to preserve in the simplified coclustering. If not set there is no limit.

TYPE: dict DEFAULT: None

See Also

Examples:

See the following function of the samples.py documentation script: - samples.extract_clusters()

detect_data_table_format(data_table_path, dictionary_file_path_or_domain=None, dictionary_name=None, log_file_path=None, output_scenario_path=None, task_file_path=None, trace=False, stdout_file_path='', stderr_file_path='', max_cores=None, memory_limit_mb=None, temp_dir='', scenario_prologue='', **kwargs)

Detects the format of a data table

Runs an heuristic to detect the format of a data table. The detection heuristic is more accurate if a dictionary with the table schema is provided.

PARAMETER DESCRIPTION
data_table_path

Path of the data table file.

TYPE: str

dictionary_file_path_or_domain

Path of a Khiops dictionary file or a DictionaryDomain object.

TYPE: str or DictionaryDomain DEFAULT: None

dictionary_name

Name of the dictionary.

TYPE: str DEFAULT: None

See Also
RETURNS DESCRIPTION
tuple

A 2-tuple containing: - the header_line boolean - the field_separator character

These are exactly the parameters expected in many Khiops Python API functions.

Examples:

See the following function of the samples.py documentation script: - samples.detect_data_table_format()