khiops.sklearn.dataset
Submodule of khiops.sklearn
Classes for handling diverse data tables
| CLASS | DESCRIPTION |
|---|---|
Dataset |
A representation of a dataset |
DatasetTable |
A generic dataset table |
PandasTable |
DatasetTable encapsulating a pandas dataframe |
NumpyTable |
DatasetTable encapsulating a NumPy array |
SparseTable |
DatasetTable encapsulating a SciPy sparse matrix |
| FUNCTION | DESCRIPTION |
|---|---|
check_dataset_spec |
Checks that a dataset spec is valid |
table_name_of_path |
Returns the table name as the last fragment of the table data path |
get_khiops_type |
Translates a numpy dtype to a Khiops dictionary type |
get_khiops_variable_name |
Return the khiops variable name associated to a column id |
read_internal_data_table |
Reads into a DataFrame a data table file with the internal format settings |
write_internal_data_table |
Writes a DataFrame to data table file with the internal format settings |
Classes
Dataset(X, y=None, categorical_target=True)
A representation of a dataset
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Either:
|
y
|
The target column. |
categorical_target
|
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
to_spec |
Returns a dictionary specification of this dataset |
copy |
Creates a copy of the dataset |
get_table |
Returns a table by its name |
create_khiops_dictionary_domain |
Creates a Khiops dictionary domain representing this dataset |
create_table_files_for_khiops |
Prepares the tables of the dataset to be used by Khiops |
| ATTRIBUTE | DESCRIPTION |
|---|---|
table_type |
type : The table type of this dataset's tables
|
is_multitable |
bool :
|
Attributes
table_type
property
is_multitable
property
bool : True if the dataset is multitable
Methods:
to_spec()
Returns a dictionary specification of this dataset
copy()
Creates a copy of the dataset
Referenced pandas.DataFrame, numpy.ndarray and scipy.sparse.spmatrix objects in tables are copied as references.
get_table(table_name)
Returns a table by its name
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
The name of the table to be retrieved.
|
| RETURNS | DESCRIPTION |
|---|---|
DatasetTable
|
The table object for the specified name. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If there is no table with the specified name. |
create_khiops_dictionary_domain()
Creates a Khiops dictionary domain representing this dataset
| RETURNS | DESCRIPTION |
|---|---|
DictionaryDomain
|
The DictionaryDomain object representing this dataset |
create_table_files_for_khiops(output_dir, sort=True)
Prepares the tables of the dataset to be used by Khiops
If this is a multi-table dataset it will create sorted copies the tables.
| PARAMETER | DESCRIPTION |
|---|---|
output_dir
|
The directory where the sorted tables will be created.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple containing:
|
DatasetTable(name, key=None)
Bases: ABC
A generic dataset table
| METHOD | DESCRIPTION |
|---|---|
check_key |
Checks that the key columns exist |
create_table_file_for_khiops |
Creates a copy of the table at the specified directory |
n_features |
Returns the number of features of the table |
create_khiops_dictionary |
Creates a Khiops dictionary representing this table |
Methods:
check_key()
Checks that the key columns exist
create_table_file_for_khiops(output_dir, sort=True)
abstractmethod
Creates a copy of the table at the specified directory
n_features()
Returns the number of features of the table
The target column does not count.
create_khiops_dictionary()
Creates a Khiops dictionary representing this table
| RETURNS | DESCRIPTION |
|---|---|
Dictionary
|
The Khiops Dictionary object describing this table's schema |
PandasTable(name, dataframe, key=None)
Bases: DatasetTable
DatasetTable encapsulating a pandas dataframe
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the table.
TYPE:
|
dataframe
|
The data frame to be encapsulated. It must be non-empty.
TYPE:
|
key
|
The names of the columns composing the key.
TYPE:
|
NumpyTable(name, array, key=None)
Bases: DatasetTable
DatasetTable encapsulating a NumPy array
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the table.
TYPE:
|
array
|
The data frame to be encapsulated.
TYPE:
|
key
|
The names of the columns composing the key.
TYPE:
|
SparseTable(name, matrix, key=None)
Bases: DatasetTable
DatasetTable encapsulating a SciPy sparse matrix
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the table.
TYPE:
|
matrix
|
The sparse matrix to be encapsulated.
TYPE:
|
key
|
The names of the columns composing the key.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
create_khiops_dictionary |
Creates a Khiops dictionary representing this sparse table |
Methods:
create_khiops_dictionary()
Creates a Khiops dictionary representing this sparse table
Adds metadata to each sparse variable
| RETURNS | DESCRIPTION |
|---|---|
Dictionary
|
The Khiops [Dictionary][khiops.dictionary.Dictionary] object describing this table's schema |
Functions:
check_dataset_spec(ds_spec)
Checks that a dataset spec is valid
| PARAMETER | DESCRIPTION |
|---|---|
ds_spec
|
A specification of a multi-table dataset (see Multi-Table Learning Primer).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If there are objects of the spec with invalid type. |
ValueError
|
If there are objects of the spec with invalid values. |
table_name_of_path(table_path)
Returns the table name as the last fragment of the table data path
| PARAMETER | DESCRIPTION |
|---|---|
table_path
|
Data path of the table, in the format "path/to/table".
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The name of the table. |
get_khiops_type(numpy_type, categorical_str_max_size=None)
Translates a numpy dtype to a Khiops dictionary type
| PARAMETER | DESCRIPTION |
|---|---|
numpy_type
|
Numpy type of the column
TYPE:
|
categorical_str_max_size
|
Maximum length of the entries of the column whose type is
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Khiops type name. Either "Categorical", "Text", "Numerical" or "Timestamp". |
Note
The "Text" Khiops type is inferred if the NumPy type is "string"
and the maximum length of the entries of that type is greater than 100.
get_khiops_variable_name(column_id)
Return the khiops variable name associated to a column id
read_internal_data_table(file_path_or_stream, column_dtypes=None)
Reads into a DataFrame a data table file with the internal format settings
The table is read with the following settings:
- Use tab as separator
- Read the column names from the first line
- Use '"' as quote character
- Use csv.QUOTE_MINIMAL
- double quoting enabled (quotes within quotes can be escaped with '""')
- UTF-8 encoding
- User-specified dtypes (optional)
| PARAMETER | DESCRIPTION |
|---|---|
file_path_or_stream
|
The path of the internal data table file to be read or a readable file object.
TYPE:
|
column_dtypes
|
Dictionary linking column names with dtypes. See
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The dataframe representation of the data table. |
write_internal_data_table(dataframe, file_path_or_stream)
Writes a DataFrame to data table file with the internal format settings
The table is written with the following settings:
- Use tab as separator
- Write the column names on the first line
- Use '"' as quote character
- Use csv.QUOTE_MINIMAL
- double quoting enabled (quotes within quotes can be escaped with '""')
- UTF-8 encoding
- The index is not written
Khiops cannot handle multi-line records. Hence, the carriage returns / line feeds need to be removed from the records before data is handed over to Khiops.
| PARAMETER | DESCRIPTION |
|---|---|
dataframe
|
The dataframe to write.
TYPE:
|
file_path_or_stream
|
The path of the internal data table file to be written or a writable file object.
TYPE:
|