khiops.sklearn.estimators
Submodule of khiops.sklearn
Scikit-Learn Estimator Classes for the Khiops AutoML Suite
Class Overview
The diagram below describes the relationships in this module:
| CLASS | DESCRIPTION |
|---|---|
KhiopsEstimator |
Base class for Khiops Scikit-learn estimators |
KhiopsCoclustering |
A Khiops Coclustering model |
KhiopsSupervisedEstimator |
Abstract Khiops Supervised Estimator |
KhiopsPredictor |
Abstract Khiops Selective Naive Bayes Predictor |
KhiopsClassifier |
Khiops Selective Naive Bayes Classifier |
KhiopsRegressor |
Khiops Selective Naive Bayes Regressor |
KhiopsEncoder |
Khiops supervised discretization/grouping encoder |
Classes
KhiopsEstimator(n_cores=None, verbose=False, output_dir=None, auto_sort=True)
Bases: ABC, BaseEstimator
Base class for Khiops Scikit-learn estimators
Note
The input features collection X needs to have single-line records so that Khiops can handle them. Hence, multi-line records are preprocessed: carriage returns / line feeds are replaced with blank spaces before being handed over to Khiops.
| PARAMETER | DESCRIPTION |
|---|---|
n_cores
|
Maximum number of CPU cores allocated and used for all estimator operations.
TYPE:
|
verbose
|
If
TYPE:
|
output_dir
|
Path of the output directory for the resulting artifacts of Khiops learning tasks. See concrete estimator classes for more information about this parameter.
TYPE:
|
auto_sort
|
Advanced.: See concrete estimator classes for information about this parameter.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
export_report_file |
Exports the model report to a JSON file |
export_dictionary_file |
Export the model's Khiops dictionary file (.kdic) |
fit |
Fit the estimator |
Methods:
export_report_file(report_file_path)
Exports the model report to a JSON file
| PARAMETER | DESCRIPTION |
|---|---|
report_file_path
|
The location of the exported report file.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
When the instance is not fitted. |
export_dictionary_file(dictionary_file_path)
Export the model's Khiops dictionary file (.kdic)
fit(X, y=None, **kwargs)
Fit the estimator
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The fitted estimator instance.
TYPE:
|
KhiopsCoclustering(verbose=False, output_dir=None, auto_sort=True, build_name_var=True, build_distance_vars=False, build_frequency_vars=False, n_cores=None)
Bases: ClusterMixin, KhiopsEstimator
A Khiops Coclustering model
A coclustering is a non-supervised piecewise constant density estimator.
| PARAMETER | DESCRIPTION |
|---|---|
build_distance_vars
|
If
TYPE:
|
build_frequency_vars
|
If
TYPE:
|
build_name_var
|
If
TYPE:
|
verbose
|
If
TYPE:
|
output_dir
|
Path of the output directory for the
TYPE:
|
auto_sort
|
Advanced. Only for multi-table inputs: If
TYPE:
|
n_cores
|
Maximum number of CPU cores allocated and used for all estimator operations.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
is_multitable_model_ |
TYPE:
|
model_ |
The Khiops dictionary domain for the trained coclustering. For coclustering it is a multi-table dictionary even though the model is single-table.
TYPE:
|
model_main_dictionary_name_ |
The name of the main Khiops dictionary within the
TYPE:
|
model_report_ |
The Khiops report object.
TYPE:
|
Examples:
See the following functions of the samples_sklearn.py documentation script:
- samples_sklearn.khiops_coclustering()
| METHOD | DESCRIPTION |
|---|---|
fit |
Trains a Khiops Coclustering model |
simplify |
Creates a simplified coclustering model from the current instance |
predict |
Predicts the most probable cluster for the test dataset X |
fit_predict |
Performs clustering on X and returns result (instead of labels) |
Methods:
fit(X, y=None, **kwargs)
Trains a Khiops Coclustering model
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
id_column
|
The column that contains the id of the instance.
TYPE:
|
columns
|
The columns to be co-clustered. If not specified it uses all columns.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance.
TYPE:
|
simplify(max_preserved_information=0, max_cells=0, max_total_parts=0, max_part_numbers=None)
Creates a simplified coclustering model from the current instance
| PARAMETER | DESCRIPTION |
|---|---|
max_preserved_information
|
Maximum information preserve in the simplified coclustering. If equal to 0 there is no limit.
TYPE:
|
max_cells
|
Maximum number of cells in the simplified coclustering. If equal to 0 there is no limit.
TYPE:
|
max_total_parts
|
Maximum number of parts totaled over all variables. If equal to 0 there is no limit.
TYPE:
|
max_part_numbers
|
Maximum number of clusters for each of the co-clustered column. Specifically, a key-value pair of this dictionary represents the column name and its respective maximum number of clusters. If not specified, then no maximum number of clusters is imposed on any column.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
A new, simplified KhiopsCoclustering estimator instance.
TYPE:
|
predict(X)
Predicts the most probable cluster for the test dataset X
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
`ndarray <numpy.ndarray>`
|
An array containing the encoded columns. A first column containing key column ids is added in multi-table mode. |
fit_predict(X, y=None, **kwargs)
Performs clustering on X and returns result (instead of labels)
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
results
|
TYPE:
|
KhiopsSupervisedEstimator(n_features=1000, n_trees=10, n_text_features=10000, type_text_features='words', specific_pairs=None, all_possible_pairs=True, construction_rules=None, n_feature_parts=0, keep_selected_variables_only=True, verbose=False, output_dir=None, auto_sort=True, n_cores=None)
Bases: KhiopsEstimator
Abstract Khiops Supervised Estimator
| METHOD | DESCRIPTION |
|---|---|
fit |
Fits a supervised estimator according to X,y |
Methods:
fit(X, y=None, **kwargs)
Fits a supervised estimator according to X,y
Called by the concrete sub-classes KhiopsEncoder, KhiopsClassifier, KhiopsRegressor.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance. |
KhiopsPredictor(n_features=1000, n_trees=10, n_text_features=10000, type_text_features='words', n_selected_features=0, n_evaluated_features=0, specific_pairs=None, all_possible_pairs=True, construction_rules=None, n_feature_parts=0, keep_selected_variables_only=True, verbose=False, output_dir=None, auto_sort=True, n_cores=None)
Bases: KhiopsSupervisedEstimator
Abstract Khiops Selective Naive Bayes Predictor
| METHOD | DESCRIPTION |
|---|---|
predict |
Predicts the target variable for the test dataset X |
Methods:
predict(X)
Predicts the target variable for the test dataset X
See the documentation of concrete subclasses for more details.
KhiopsClassifier(n_features=1000, n_pairs=0, n_trees=10, n_text_features=10000, type_text_features='words', n_selected_features=0, n_evaluated_features=0, specific_pairs=None, all_possible_pairs=True, construction_rules=None, n_feature_parts=0, group_target_value=False, keep_selected_variables_only=True, verbose=False, output_dir=None, auto_sort=True, n_cores=None)
Bases: ClassifierMixin, KhiopsPredictor
Khiops Selective Naive Bayes Classifier
This classifier supports automatic feature engineering on multi-table datasets. See Multi-Table Learning Primer for more details.
Note
Visit the Khiops site to learn about the automatic feature engineering algorithm.
| PARAMETER | DESCRIPTION |
|---|---|
n_features
|
Maximum number of features to construct automatically. See Multi-Table Learning Primer for more details on the multi-table-specific features.
TYPE:
|
n_pairs
|
Maximum number of pair features to construct. These features exploit bivariate partitions of native or automatically constructed variables, excluding features derived from the text variables.
TYPE:
|
n_trees
|
Maximum number of decision trees to construct. The trees combine native variables and automatically constructed variables, excluding features derived from the text variables or from variable pairs. Decision trees usually improve the classifier's performance at the cost of the interpretability of the model.
TYPE:
|
n_text_features
|
Maximum number of text features to construct.
TYPE:
|
type_text_features
|
Type of the text features to construct. Can be either one of: - "words": sequences of non-space characters - "ngrams": sequences of bytes - "tokens": user-defined
TYPE:
|
n_selected_features
|
Maximum number of features to be selected in the SNB predictor. If equal to 0 it selects all the features kept in the training.
TYPE:
|
n_evaluated_features
|
Maximum number of features to be evaluated in the SNB predictor training. If equal to 0 it evaluates all informative features.
TYPE:
|
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
TYPE:
|
all_possible_pairs
|
If
TYPE:
|
construction_rules
|
Allowed rules for the automatic feature construction. If not set, Khiops
uses the multi-table construction rules listed in
TYPE:
|
n_feature_parts
|
Maximum number of variable parts produced by preprocessing methods. If equal to 0 it is automatically calculated.
TYPE:
|
group_target_value
|
Allows grouping of the target values in classification. It can substantially increase the training time.
TYPE:
|
keep_selected_variables_only
|
Keeps only predictor-selected variables in the supervised analysis report.
TYPE:
|
verbose
|
If
TYPE:
|
output_dir
|
Path of the output directory for the
TYPE:
|
auto_sort
|
Advanced. Only for multi-table inputs: If
TYPE:
|
n_cores
|
Maximum number of CPU cores allocated and used for all estimator operations.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_classes_ |
The number of classes seen in training.
TYPE:
|
classes_ |
The list of classes seen in training. Depending on the training target, the
contents are
TYPE:
|
n_features_in_ |
The number of features in the main table of the training dataset.
TYPE:
|
is_multitable_model_ |
TYPE:
|
model_ |
The Khiops dictionary domain for the trained classifier.
TYPE:
|
model_main_dictionary_name_ |
The name of the main Khiops dictionary within the
TYPE:
|
model_report_ |
The Khiops report object.
TYPE:
|
Examples:
See the following functions of the samples_sklearn.py documentation script:
- samples_sklearn.khiops_classifier()
- samples_sklearn.khiops_classifier_multiclass()
- samples_sklearn.khiops_classifier_multitable_star()
- samples_sklearn.khiops_classifier_multitable_snowflake()
- samples_sklearn.khiops_classifier_pickle()
| METHOD | DESCRIPTION |
|---|---|
fit |
Fits a Selective Naive Bayes classifier according to X, y |
predict |
Predicts the most probable class for the test dataset X |
predict_proba |
Predicts the class probabilities for the test dataset X |
Methods:
fit(X, y, **kwargs)
Fits a Selective Naive Bayes classifier according to X, y
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance.
TYPE:
|
predict(X)
Predicts the most probable class for the test dataset X
The predicted class of an input sample is the arg-max of the conditional probabilities P(y|X) for each value of y.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
`ndarray <numpy.ndarray>`
|
An array containing the encoded columns. A first column containing key
column ids is added in multi-table mode. The numpy.dtype of the array
matches the type of The key columns are added for multi-table tasks. |
predict_proba(X)
Predicts the class probabilities for the test dataset X
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray or str
|
The probability of the samples for each class in the model. The columns are
named with the pattern The key columns are added for multi-table tasks. |
KhiopsRegressor(n_features=1000, n_trees=0, n_text_features=10000, type_text_features='words', n_selected_features=0, n_evaluated_features=0, construction_rules=None, n_feature_parts=0, keep_selected_variables_only=True, verbose=False, output_dir=None, auto_sort=True, n_cores=None)
Bases: RegressorMixin, KhiopsPredictor
Khiops Selective Naive Bayes Regressor
This regressor supports automatic feature engineering on multi-table datasets. See Multi-Table Learning Primer for more details.
Note
Visit the Khiops site to learn about the automatic feature engineering algorithm.
| PARAMETER | DESCRIPTION |
|---|---|
n_features
|
Maximum number of features to construct automatically. See Multi-Table Learning Primer for more details on the multi-table-specific features.
TYPE:
|
n_trees
|
Maximum number of decision trees to construct. The trees combine native variables and automatically constructed variables, excluding features derived from the text variables or from variable pairs. Decision trees usually improve the regressor's performance at the cost of the interpretability of the model.
TYPE:
|
n_text_features
|
Maximum number of text features to construct.
TYPE:
|
type_text_features
|
Type of the text features to construct. Can be either one of: - "words": sequences of non-space characters - "ngrams": sequences of bytes - "tokens": user-defined
TYPE:
|
n_selected_features
|
Maximum number of features to be selected in the SNB predictor. If equal to 0 it selects all the features kept in the training.
TYPE:
|
n_evaluated_features
|
Maximum number of features to be evaluated in the SNB predictor training. If equal to 0 it evaluates all informative features.
TYPE:
|
construction_rules
|
Allowed rules for the automatic feature construction. If not set, Khiops
uses the multi-table construction rules listed in
TYPE:
|
n_feature_parts
|
Maximum number of variable parts produced by preprocessing methods. If equal to 0 it is automatically calculated.
TYPE:
|
keep_selected_variables_only
|
Keeps only predictor-selected variables in the supervised analysis report.
TYPE:
|
verbose
|
If
TYPE:
|
output_dir
|
Path of the output directory for the
TYPE:
|
auto_sort
|
Advanced. Only for multi-table inputs: If
TYPE:
|
n_cores
|
Maximum number of CPU cores allocated and used for all estimator operations.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_features_in_ |
The number of features in the main table of the training dataset.
TYPE:
|
is_multitable_model_ |
TYPE:
|
model_ |
The Khiops dictionary domain for the trained regressor.
TYPE:
|
model_main_dictionary_name_ |
The name of the main Khiops dictionary within the
TYPE:
|
model_report_ |
The Khiops report object.
TYPE:
|
Examples:
See the following functions of the samples_sklearn.py documentation script:
- samples_sklearn.khiops_regressor()
| METHOD | DESCRIPTION |
|---|---|
fit |
Fits a Selective Naive Bayes regressor according to X, y |
predict |
Predicts the regression values for the test dataset X |
Methods:
fit(X, y=None, **kwargs)
Fits a Selective Naive Bayes regressor according to X, y
Warning
Make sure that the type of y is float. This is easily done with y =
y.astype(float).
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance.
TYPE:
|
predict(X)
Predicts the regression values for the test dataset X
The predicted value is estimated by the Selective Naive Bayes Regressor learned during fit step.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray or str
|
An array containing the encoded columns. A first column containing key column ids is added in multi-table mode. The key columns are added for multi-table tasks. The array is in the form of a numpy.ndarray if X is array-like, or dataset spec containing pandas.DataFrame tables. |
KhiopsEncoder(categorical_target=True, n_features=1000, n_pairs=0, n_trees=0, n_text_features=10000, type_text_features='words', specific_pairs=None, all_possible_pairs=True, construction_rules=None, n_feature_parts=0, informative_features_only=True, group_target_value=False, keep_initial_variables=False, transform_type_categorical='part_id', transform_type_numerical='part_id', transform_type_pairs='part_id', verbose=False, output_dir=None, auto_sort=True, n_cores=None)
Bases: TransformerMixin, KhiopsSupervisedEstimator
Khiops supervised discretization/grouping encoder
| PARAMETER | DESCRIPTION |
|---|---|
categorical_target
|
TYPE:
|
n_features
|
Maximum number of features to construct automatically. See Multi-Table Learning Primer for more details on the multi-table-specific features.
TYPE:
|
n_pairs
|
Maximum number of pair features to construct. These features exploit bivariate partitions of native or automatically constructed variables, excluding features derived from the text variables.
TYPE:
|
n_trees
|
Maximum number of decision trees to construct. The trees combine native variables and automatically constructed variables, excluding features derived from the text variables or from variable pairs. Decision trees usually improve the encoder's performance at the cost of the interpretability of the model.
TYPE:
|
n_text_features
|
Maximum number of text features to construct.
TYPE:
|
type_text_features
|
Type of the text features to construct. Can be either one of: - "words": sequences of non-space characters - "ngrams": sequences of bytes - "tokens": user-defined
TYPE:
|
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
TYPE:
|
all_possible_pairs
|
If
TYPE:
|
construction_rules
|
Allowed rules for the automatic feature construction. If not set, Khiops
uses the multi-table construction rules listed in
TYPE:
|
n_feature_parts
|
Maximum number of variable parts produced by preprocessing methods. If equal to 0 it is automatically calculated.
TYPE:
|
informative_features_only
|
If
TYPE:
|
group_target_value
|
Allows grouping of the target values in classification. It can substantially increase the training time.
TYPE:
|
keep_initial_variables
|
If
TYPE:
|
transform_type_categorical
|
Type of transformation for categorical features. Valid values: - "part_id" - "part_label" - "dummies" - "conditional_info" See the documentation for the
TYPE:
|
transform_type_numerical
|
One of the following strings are valid: - "part_id" - "part_label" - "dummies" - "conditional_info" - "center_reduction" - "0-1_normalization" - "rank_normalization" See the documentation for the
TYPE:
|
transform_type_pairs
|
Type of transformation for bivariate features. Valid values: - "part_id" - "part_label" - "dummies" - "conditional_info"
TYPE:
|
verbose
|
If
TYPE:
|
output_dir
|
Path of the output directory for the
TYPE:
|
auto_sort
|
Advanced. Only for multi-table inputs: If
TYPE:
|
n_cores
|
Maximum number of CPU cores allocated and used for all estimator operations.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
is_multitable_model_ |
TYPE:
|
model_ |
The Khiops dictionary domain for the trained encoder.
TYPE:
|
model_main_dictionary_name_ |
The name of the main Khiops dictionary within the
TYPE:
|
model_report_ |
The Khiops report object.
TYPE:
|
Examples:
See the following functions of the samples_sklearn.py documentation script:
- samples_sklearn.khiops_encoder()
- samples_sklearn.khiops_encoder_multitable_star()
- samples_sklearn.khiops_encoder_multitable_snowflake()
| METHOD | DESCRIPTION |
|---|---|
fit |
Fits the Khiops Encoder according to X, y |
transform |
Transforms X with a fitted Khiops supervised encoder |
fit_transform |
Fit and transforms its inputs |
Methods:
fit(X, y=None, **kwargs)
Fits the Khiops Encoder according to X, y
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance.
TYPE:
|
transform(X)
Transforms X with a fitted Khiops supervised encoder
Note
Numerical features are encoded to categorical ones. See the
transform_type_numerical parameter for details.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
An array containing the encoded columns. A first column containing key column ids is added in multi-table mode. |
fit_transform(X, y=None, **kwargs)
Fit and transforms its inputs
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training dataset. Either an array-like or a dict specification for multi-table datasets (see Multi-Table Learning Primer).
TYPE:
|
y
|
The target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
The calling estimator instance.
TYPE:
|