diff --git a/docs/api/SUMMARY.md b/docs/api/SUMMARY.md index 91e36f0d8..59d5b4d50 100644 --- a/docs/api/SUMMARY.md +++ b/docs/api/SUMMARY.md @@ -13,43 +13,30 @@ search: - [ImageSize](safeds/data/image/typing/ImageSize.md) - labeled - containers - - [ExperimentalTabularDataset](safeds/data/labeled/containers/ExperimentalTabularDataset.md) + - [Dataset](safeds/data/labeled/containers/Dataset.md) - [ImageDataset](safeds/data/labeled/containers/ImageDataset.md) - [TabularDataset](safeds/data/labeled/containers/TabularDataset.md) - [TimeSeriesDataset](safeds/data/labeled/containers/TimeSeriesDataset.md) - tabular - containers + - [Cell](safeds/data/tabular/containers/Cell.md) - [Column](safeds/data/tabular/containers/Column.md) - - [ExperimentalCell](safeds/data/tabular/containers/ExperimentalCell.md) - - [ExperimentalColumn](safeds/data/tabular/containers/ExperimentalColumn.md) - - [ExperimentalRow](safeds/data/tabular/containers/ExperimentalRow.md) - - [ExperimentalTable](safeds/data/tabular/containers/ExperimentalTable.md) - [Row](safeds/data/tabular/containers/Row.md) - [Table](safeds/data/tabular/containers/Table.md) - plotting - - [ExperimentalColumnPlotter](safeds/data/tabular/plotting/ExperimentalColumnPlotter.md) - - [ExperimentalTablePlotter](safeds/data/tabular/plotting/ExperimentalTablePlotter.md) + - [ColumnPlotter](safeds/data/tabular/plotting/ColumnPlotter.md) + - [TablePlotter](safeds/data/tabular/plotting/TablePlotter.md) - transformation - [Discretizer](safeds/data/tabular/transformation/Discretizer.md) - - [ExperimentalDiscretizer](safeds/data/tabular/transformation/ExperimentalDiscretizer.md) - - [ExperimentalInvertibleTableTransformer](safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.md) - - [ExperimentalLabelEncoder](safeds/data/tabular/transformation/ExperimentalLabelEncoder.md) - - [ExperimentalOneHotEncoder](safeds/data/tabular/transformation/ExperimentalOneHotEncoder.md) - - [ExperimentalRangeScaler](safeds/data/tabular/transformation/ExperimentalRangeScaler.md) - - [ExperimentalSimpleImputer](safeds/data/tabular/transformation/ExperimentalSimpleImputer.md) - - [ExperimentalStandardScaler](safeds/data/tabular/transformation/ExperimentalStandardScaler.md) - - [ExperimentalTableTransformer](safeds/data/tabular/transformation/ExperimentalTableTransformer.md) - - [Imputer](safeds/data/tabular/transformation/Imputer.md) - [InvertibleTableTransformer](safeds/data/tabular/transformation/InvertibleTableTransformer.md) - [LabelEncoder](safeds/data/tabular/transformation/LabelEncoder.md) - [OneHotEncoder](safeds/data/tabular/transformation/OneHotEncoder.md) - [RangeScaler](safeds/data/tabular/transformation/RangeScaler.md) + - [SimpleImputer](safeds/data/tabular/transformation/SimpleImputer.md) - [StandardScaler](safeds/data/tabular/transformation/StandardScaler.md) - [TableTransformer](safeds/data/tabular/transformation/TableTransformer.md) - typing - - [ColumnType](safeds/data/tabular/typing/ColumnType.md) - - [ExperimentalDataType](safeds/data/tabular/typing/ExperimentalDataType.md) - - [ExperimentalSchema](safeds/data/tabular/typing/ExperimentalSchema.md) + - [DataType](safeds/data/tabular/typing/DataType.md) - [Schema](safeds/data/tabular/typing/Schema.md) - lang - [AnnotationTarget](safeds/lang/AnnotationTarget.md) @@ -84,9 +71,9 @@ search: - [DecisionTreeClassifier](safeds/ml/classical/classification/DecisionTreeClassifier.md) - [GradientBoostingClassifier](safeds/ml/classical/classification/GradientBoostingClassifier.md) - [KNearestNeighborsClassifier](safeds/ml/classical/classification/KNearestNeighborsClassifier.md) - - [LogisticRegressionClassifier](safeds/ml/classical/classification/LogisticRegressionClassifier.md) + - [LogisticClassifier](safeds/ml/classical/classification/LogisticClassifier.md) - [RandomForestClassifier](safeds/ml/classical/classification/RandomForestClassifier.md) - - [SupportVectorMachineClassifier](safeds/ml/classical/classification/SupportVectorMachineClassifier.md) + - [SupportVectorClassifier](safeds/ml/classical/classification/SupportVectorClassifier.md) - regression - [AdaBoostRegressor](safeds/ml/classical/regression/AdaBoostRegressor.md) - [ArimaRegressor](safeds/ml/classical/regression/ArimaRegressor.md) @@ -95,29 +82,35 @@ search: - [GradientBoostingRegressor](safeds/ml/classical/regression/GradientBoostingRegressor.md) - [KNearestNeighborsRegressor](safeds/ml/classical/regression/KNearestNeighborsRegressor.md) - [LassoRegressor](safeds/ml/classical/regression/LassoRegressor.md) - - [LinearRegressionRegressor](safeds/ml/classical/regression/LinearRegressionRegressor.md) + - [LinearRegressor](safeds/ml/classical/regression/LinearRegressor.md) - [RandomForestRegressor](safeds/ml/classical/regression/RandomForestRegressor.md) - [Regressor](safeds/ml/classical/regression/Regressor.md) - [RidgeRegressor](safeds/ml/classical/regression/RidgeRegressor.md) - - [SupportVectorMachineRegressor](safeds/ml/classical/regression/SupportVectorMachineRegressor.md) + - [SupportVectorRegressor](safeds/ml/classical/regression/SupportVectorRegressor.md) + - [SupervisedModel](safeds/ml/classical/SupervisedModel.md) + - metrics + - [ClassificationMetrics](safeds/ml/metrics/ClassificationMetrics.md) + - [RegressionMetrics](safeds/ml/metrics/RegressionMetrics.md) - nn - - [AvgPooling2DLayer](safeds/ml/nn/AvgPooling2DLayer.md) - - [Convolutional2DLayer](safeds/ml/nn/Convolutional2DLayer.md) - - [ConvolutionalTranspose2DLayer](safeds/ml/nn/ConvolutionalTranspose2DLayer.md) - - [FlattenLayer](safeds/ml/nn/FlattenLayer.md) - - [ForwardLayer](safeds/ml/nn/ForwardLayer.md) - - [InputConversion](safeds/ml/nn/InputConversion.md) - - [InputConversionImage](safeds/ml/nn/InputConversionImage.md) - - [InputConversionTable](safeds/ml/nn/InputConversionTable.md) - - [InputConversionTimeSeries](safeds/ml/nn/InputConversionTimeSeries.md) - - [Layer](safeds/ml/nn/Layer.md) - - [LSTMLayer](safeds/ml/nn/LSTMLayer.md) - - [MaxPooling2DLayer](safeds/ml/nn/MaxPooling2DLayer.md) + - converters + - [InputConversion](safeds/ml/nn/converters/InputConversion.md) + - [InputConversionImage](safeds/ml/nn/converters/InputConversionImage.md) + - [InputConversionTable](safeds/ml/nn/converters/InputConversionTable.md) + - [InputConversionTimeSeries](safeds/ml/nn/converters/InputConversionTimeSeries.md) + - [OutputConversion](safeds/ml/nn/converters/OutputConversion.md) + - [OutputConversionImageToColumn](safeds/ml/nn/converters/OutputConversionImageToColumn.md) + - [OutputConversionImageToImage](safeds/ml/nn/converters/OutputConversionImageToImage.md) + - [OutputConversionImageToTable](safeds/ml/nn/converters/OutputConversionImageToTable.md) + - [OutputConversionTable](safeds/ml/nn/converters/OutputConversionTable.md) + - [OutputConversionTimeSeries](safeds/ml/nn/converters/OutputConversionTimeSeries.md) + - layers + - [AveragePooling2DLayer](safeds/ml/nn/layers/AveragePooling2DLayer.md) + - [Convolutional2DLayer](safeds/ml/nn/layers/Convolutional2DLayer.md) + - [ConvolutionalTranspose2DLayer](safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.md) + - [FlattenLayer](safeds/ml/nn/layers/FlattenLayer.md) + - [ForwardLayer](safeds/ml/nn/layers/ForwardLayer.md) + - [Layer](safeds/ml/nn/layers/Layer.md) + - [LSTMLayer](safeds/ml/nn/layers/LSTMLayer.md) + - [MaxPooling2DLayer](safeds/ml/nn/layers/MaxPooling2DLayer.md) - [NeuralNetworkClassifier](safeds/ml/nn/NeuralNetworkClassifier.md) - [NeuralNetworkRegressor](safeds/ml/nn/NeuralNetworkRegressor.md) - - [OutputConversion](safeds/ml/nn/OutputConversion.md) - - [OutputConversionImageToColumn](safeds/ml/nn/OutputConversionImageToColumn.md) - - [OutputConversionImageToImage](safeds/ml/nn/OutputConversionImageToImage.md) - - [OutputConversionImageToTable](safeds/ml/nn/OutputConversionImageToTable.md) - - [OutputConversionTable](safeds/ml/nn/OutputConversionTable.md) - - [OutputConversionTimeSeries](safeds/ml/nn/OutputConversionTimeSeries.md) diff --git a/docs/api/safeds/data/image/containers/ImageList.md b/docs/api/safeds/data/image/containers/ImageList.md index f5496a620..8e408c1d4 100644 --- a/docs/api/safeds/data/image/containers/ImageList.md +++ b/docs/api/safeds/data/image/containers/ImageList.md @@ -16,7 +16,7 @@ To create an `ImageList` call one of the following static methods: /** * Return the number of images in this image list. */ - @PythonName("number_of_images") attr numberOfImages: Int + @PythonName("number_of_images") attr imageCount: Int /** * Return a list of all widths in this image list. */ @@ -36,7 +36,7 @@ To create an `ImageList` call one of the following static methods: /** * Return the number of different sizes of images in this image list. */ - @PythonName("number_of_sizes") attr numberOfSizes: Int + @PythonName("number_of_sizes") attr sizeCount: Int /** * Create an ImageList from a list of images. @@ -131,7 +131,7 @@ To create an `ImageList` call one of the following static methods: /** * Return a list of all images in this image list. * - * @param indices a list of all indices to include in the output. If None, all indices will be included + * @param indices a list of all indices to include in the output. If null, all indices will be included * * @result images the list of all images */ @@ -525,13 +525,13 @@ Return a list of all heights in this image list. **Type:** [`List`][safeds.lang.List] -## `#!sds attr` numberOfImages {#safeds.data.image.containers.ImageList.numberOfImages data-toc-label='numberOfImages'} +## `#!sds attr` imageCount {#safeds.data.image.containers.ImageList.imageCount data-toc-label='imageCount'} Return the number of images in this image list. **Type:** [`Int`][safeds.lang.Int] -## `#!sds attr` numberOfSizes {#safeds.data.image.containers.ImageList.numberOfSizes data-toc-label='numberOfSizes'} +## `#!sds attr` sizeCount {#safeds.data.image.containers.ImageList.sizeCount data-toc-label='sizeCount'} Return the number of different sizes of images in this image list. @@ -1268,7 +1268,7 @@ Return a list of all images in this image list. | Name | Type | Description | Default | |------|------|-------------|---------| -| `indices` | [`List?`][safeds.lang.List] | a list of all indices to include in the output. If None, all indices will be included | `#!sds null` | +| `indices` | [`List?`][safeds.lang.List] | a list of all indices to include in the output. If null, all indices will be included | `#!sds null` | **Results:** diff --git a/docs/api/safeds/data/labeled/containers/Dataset.md b/docs/api/safeds/data/labeled/containers/Dataset.md new file mode 100644 index 000000000..6c5f90e36 --- /dev/null +++ b/docs/api/safeds/data/labeled/containers/Dataset.md @@ -0,0 +1,19 @@ +--- +search: + boost: 0.5 +--- + +# `#!sds abstract class` Dataset {#safeds.data.labeled.containers.Dataset data-toc-label='Dataset'} + +A dataset is used as input to machine learning models. + +**Inheritors:** + +- [`ImageDataset`][safeds.data.labeled.containers.ImageDataset] +- [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] + +??? quote "Stub code in `Dataset.sdsstub`" + + ```sds linenums="6" + class Dataset + ``` diff --git a/docs/api/safeds/data/labeled/containers/ExperimentalTabularDataset.md b/docs/api/safeds/data/labeled/containers/ExperimentalTabularDataset.md deleted file mode 100644 index d99e2f7e6..000000000 --- a/docs/api/safeds/data/labeled/containers/ExperimentalTabularDataset.md +++ /dev/null @@ -1,106 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalTabularDataset {#safeds.data.labeled.containers.ExperimentalTabularDataset data-toc-label='ExperimentalTabularDataset'} - -A dataset containing tabular data. It can be used to train machine learning models. - -Columns in a tabular dataset are divided into three categories: - -* The target column is the column that a model should predict. -* Feature columns are columns that a model should use to make predictions. -* Extra columns are columns that are neither feature nor target. They can be used to provide additional context, - like an ID column. - -Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns -are specified, all columns except the target column are used as features. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `data` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The data. | - | -| `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | -| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.labeled.containers import TabularDataset - // dataset = TabularDataset( - // {"id": [1, 2, 3], "feature": [4, 5, 6], "target": [1, 2, 3]}, - // target_name="target", - // extra_names=["id"] - // ) -} -``` - -??? quote "Stub code in `ExperimentalTabularDataset.sdsstub`" - - ```sds linenums="34" - class ExperimentalTabularDataset( - data: ExperimentalTable, - @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List? = null - ) { - /** - * The feature columns of the tabular dataset. - */ - attr features: ExperimentalTable - /** - * The target column of the tabular dataset. - */ - attr target: ExperimentalColumn - /** - * Additional columns of the tabular dataset that are neither features nor target. - * - * These can be used to store additional information about instances, such as IDs. - */ - attr extras: ExperimentalTable - - /** - * Return a table containing all columns of the tabular dataset. - * - * @result table A table containing all columns of the tabular dataset. - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable - } - ``` - -## `#!sds attr` extras {#safeds.data.labeled.containers.ExperimentalTabularDataset.extras data-toc-label='extras'} - -Additional columns of the tabular dataset that are neither features nor target. - -These can be used to store additional information about instances, such as IDs. - -**Type:** [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] - -## `#!sds attr` features {#safeds.data.labeled.containers.ExperimentalTabularDataset.features data-toc-label='features'} - -The feature columns of the tabular dataset. - -**Type:** [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] - -## `#!sds attr` target {#safeds.data.labeled.containers.ExperimentalTabularDataset.target data-toc-label='target'} - -The target column of the tabular dataset. - -**Type:** [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] - -## `#!sds fun` toTable {#safeds.data.labeled.containers.ExperimentalTabularDataset.toTable data-toc-label='toTable'} - -Return a table containing all columns of the tabular dataset. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | A table containing all columns of the tabular dataset. | - -??? quote "Stub code in `ExperimentalTabularDataset.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/labeled/containers/ImageDataset.md b/docs/api/safeds/data/labeled/containers/ImageDataset.md index 824134151..3499f85dd 100644 --- a/docs/api/safeds/data/labeled/containers/ImageDataset.md +++ b/docs/api/safeds/data/labeled/containers/ImageDataset.md @@ -2,6 +2,8 @@ A Dataset for ImageLists as input and ImageLists, Tables or Columns as output. +**Parent type:** [`Dataset`][safeds.data.labeled.containers.Dataset] + **Parameters:** | Name | Type | Description | Default | @@ -19,13 +21,13 @@ A Dataset for ImageLists as input and ImageLists, Tables or Columns as output. ??? quote "Stub code in `ImageDataset.sdsstub`" - ```sds linenums="16" + ```sds linenums="17" class ImageDataset( @PythonName("input_data") inputData: ImageList, @PythonName("output_data") outputData: T, @PythonName("batch_size") batchSize: Int = 1, shuffle: Boolean = false - ) { + ) sub Dataset { /** * Get the input `ImageSize` of this dataset. */ @@ -89,7 +91,7 @@ Get the input data of this dataset. ??? quote "Stub code in `ImageDataset.sdsstub`" - ```sds linenums="36" + ```sds linenums="37" @Pure @PythonName("get_input") fun getInput() -> input: ImageList @@ -107,7 +109,7 @@ Get the output data of this dataset. ??? quote "Stub code in `ImageDataset.sdsstub`" - ```sds linenums="45" + ```sds linenums="46" @Pure @PythonName("get_output") fun getOutput() -> output: T @@ -127,7 +129,7 @@ The original dataset list is not modified. ??? quote "Stub code in `ImageDataset.sdsstub`" - ```sds linenums="56" + ```sds linenums="57" @Pure fun shuffle() -> imageDataset: ImageDataset ``` diff --git a/docs/api/safeds/data/labeled/containers/TabularDataset.md b/docs/api/safeds/data/labeled/containers/TabularDataset.md index 9380925ca..b518fe690 100644 --- a/docs/api/safeds/data/labeled/containers/TabularDataset.md +++ b/docs/api/safeds/data/labeled/containers/TabularDataset.md @@ -1,8 +1,18 @@ # `#!sds class` TabularDataset {#safeds.data.labeled.containers.TabularDataset data-toc-label='TabularDataset'} -A tabular dataset maps feature columns to a target column. +A dataset containing tabular data. It can be used to train machine learning models. -Create a tabular dataset from a mapping of column names to their values. +Columns in a tabular dataset are divided into three categories: + +- The target column is the column that a model should predict. +- Feature columns are columns that a model should use to make predictions. +- Extra columns are columns that are neither feature nor target. They can be used to provide additional context, + like an ID column. + +Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns +are specified, all columns except the target column are used as features. + +**Parent type:** [`Dataset`][safeds.data.labeled.containers.Dataset] **Parameters:** @@ -10,28 +20,31 @@ Create a tabular dataset from a mapping of column names to their values. |------|------|-------------|---------| | `data` | `#!sds union>, Table>` | The data. | - | | `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | -| `extraNames` | [`List`][safeds.lang.List] | Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the target column are used as features. | `#!sds []` | +| `extraNames` | [`List`][safeds.lang.List] | Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but the target column are used as features. | `#!sds []` | **Examples:** -```sds hl_lines="2" +```sds pipeline example { - val dataset = TabularDataset( - {"id": [1, 2, 3], "feature": [4, 5, 6], "target": [1, 2, 3]}, - targetName="target", - extraNames=["id"] + val table = Table( + { + "id": [1, 2, 3], + "feature": [4, 5, 6], + "target": [1, 2, 3], + }, ); + val dataset = table.toTabularDataset(targetName="target", extraNames=["id"]); } ``` ??? quote "Stub code in `TabularDataset.sdsstub`" - ```sds linenums="27" + ```sds linenums="36" class TabularDataset( data: union>, Table>, @PythonName("target_name") targetName: String, @PythonName("extra_names") extraNames: List = [] - ) { + ) sub Dataset { /** * The feature columns of the tabular dataset. */ @@ -48,11 +61,9 @@ pipeline example { attr extras: Table /** - * Return a new `Table` containing the feature columns and the target column. + * Return a table containing all columns of the tabular dataset. * - * The original `TabularDataset` is not modified. - * - * @result table A table containing the feature columns and the target column. + * @result table A table containing all columns of the tabular dataset. */ @Pure @PythonName("to_table") @@ -82,19 +93,17 @@ The target column of the tabular dataset. ## `#!sds fun` toTable {#safeds.data.labeled.containers.TabularDataset.toTable data-toc-label='toTable'} -Return a new `Table` containing the feature columns and the target column. - -The original `TabularDataset` is not modified. +Return a table containing all columns of the tabular dataset. **Results:** | Name | Type | Description | |------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the feature columns and the target column. | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | A table containing all columns of the tabular dataset. | ??? quote "Stub code in `TabularDataset.sdsstub`" - ```sds linenums="54" + ```sds linenums="61" @Pure @PythonName("to_table") fun toTable() -> table: Table diff --git a/docs/api/safeds/data/labeled/containers/TimeSeriesDataset.md b/docs/api/safeds/data/labeled/containers/TimeSeriesDataset.md index 46a6d8527..5f047bc06 100644 --- a/docs/api/safeds/data/labeled/containers/TimeSeriesDataset.md +++ b/docs/api/safeds/data/labeled/containers/TimeSeriesDataset.md @@ -11,7 +11,7 @@ Create a time series dataset from a mapping of column names to their values. | `data` | `#!sds union>, Table>` | The data. | - | | `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | | `timeName` | [`String`][safeds.lang.String] | Name of the time column. | - | -| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | +| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | **Examples:** diff --git a/docs/api/safeds/data/tabular/containers/Cell.md b/docs/api/safeds/data/tabular/containers/Cell.md new file mode 100644 index 000000000..d060ba500 --- /dev/null +++ b/docs/api/safeds/data/tabular/containers/Cell.md @@ -0,0 +1,928 @@ +--- +search: + boost: 0.5 +--- + +# `#!sds abstract class` Cell {#safeds.data.tabular.containers.Cell data-toc-label='Cell'} + +A single value in a table. + +This class cannot be instantiated directly. It is only used for arguments of callbacks. + +**Type parameters:** + +| Name | Upper Bound | Description | Default | +|------|-------------|-------------|---------| +| `T` | [`Any?`][safeds.lang.Any] | - | [`Any?`][safeds.lang.Any] | + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="8" + class Cell { + /** + * Negate a boolean. This WILL LATER BE equivalent to the ^not operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^not()); + * // Column("example", [false, true]) + * } + */ + @Pure + @PythonName("not_") + fun ^not() -> result: Cell + + /** + * Perform a boolean AND operation. This WILL LATER BE equivalent to the ^and operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^and(false)); + * // Column("example", [false, false]) + * } + */ + @Pure + @PythonName("and_") + fun ^and( + other: union> + ) -> result: Cell + + /** + * Perform a boolean OR operation. This WILL LATER BE equivalent to the ^or operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^or(true)); + * // Column("example", [true, true]) + * } + */ + @Pure + @PythonName("or_") + fun ^or( + other: union> + ) -> result: Cell + + /** + * Perform a boolean XOR operation. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.xor(true)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun xor( + other: union> + ) -> result: Cell + + /** + * Get the absolute value. + * + * @example + * pipeline example { + * val column = Column("example", [1, -2]); + * val result = column.transform((cell) -> cell.abs()); + * // Column("example", [1, 2]) + * } + */ + @Pure + fun abs() -> result: Cell + + /** + * Round up to the nearest integer. + * + * @example + * pipeline example { + * val column = Column("example", [1.1, 2.9]); + * val result = column.transform((cell) -> cell.ceil()); + * // Column("example", [2, 3]) + * } + */ + @Pure + fun ceil() -> result: Cell + + /** + * Round down to the nearest integer. + * + * @example + * pipeline example { + * val column = Column("example", [1.1, 2.9]); + * val result = column.transform((cell) -> cell.floor()); + * // Column("example", [1, 2]) + * } + */ + @Pure + fun floor() -> result: Cell + + /** + * Negate the value. + * + * @example + * pipeline example { + * val column = Column("example", [1, -2]); + * val result = column.transform((cell) -> cell.neg()); + * // Column("example", [-1, 2]) + * } + */ + @Pure + fun neg() -> result: Cell + + /** + * Add a value. This WILL LATER BE equivalent to the `+` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.add(3)); + * // Column("example", [4, 5]) + * } + */ + @Pure + fun add( + other: Any + ) -> result: Cell + + /** + * Perform a modulo operation. + * + * @example + * pipeline example { + * val column = Column("example", [5, 6]); + * val result = column.transform((cell) -> cell.mod(3)); + * // Column("example", [2, 0]) + * } + */ + @Pure + fun mod( + other: Any + ) -> result: Cell + + /** + * Multiply by a value. This WILL LATER BE equivalent to the `*` operator. + * + * @example + * pipeline example { + * val column = Column("example", [2, 3]); + * val result = column.transform((cell) -> cell.mul(4)); + * // Column("example", [8, 12]) + * } + */ + @Pure + fun mul( + other: Any + ) -> result: Cell + + /** + * Raise to a power. + * + * @example + * pipeline example { + * val column = Column("example", [2, 3]); + * val result = column.transform((cell) -> cell.pow(3.0)); + * // Column("example", [8, 27]) + * } + */ + @Pure + fun pow( + other: union + ) -> result: Cell + + /** + * Subtract a value. This WILL LATER BE equivalent to the `-` operator. + * + * @example + * pipeline example { + * val column = Column("example", [5, 6]); + * val result = column.transform((cell) -> cell.^sub(3)); + * // Column("example", [2, 3]) + * } + */ + @Pure + fun ^sub( + other: Any + ) -> result: Cell + + /** + * Divide by a value. This WILL LATER BE equivalent to the `/` operator. + * + * @example + * pipeline example { + * val column = Column("example", [6, 8]); + * val result = column.transform((cell) -> cell.div(2)); + * // Column("example", [3, 4]) + * } + */ + @Pure + fun div( + other: Any + ) -> result: Cell + + /** + * Check if equal to a value. This WILL LATER BE equivalent to the `==` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.eq(2)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun eq( + other: Any + ) -> result: Cell + + /** + * Check if greater than or equal to a value. This WILL LATER BE equivalent to the `>=` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.ge(2)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun ge( + other: Any + ) -> result: Cell + + /** + * Check if greater than a value. This WILL LATER BE equivalent to the `>` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.gt(2)); + * // Column("example", [false, false]) + * } + */ + @Pure + fun gt( + other: Any + ) -> result: Cell + + /** + * Check if less than or equal to a value. This WILL LATER BE equivalent to the `<=` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.le(2)); + * // Column("example", [true, true]) + * } + */ + @Pure + fun le( + other: Any + ) -> result: Cell + + /** + * Check if less than a value. This WILL LATER BE equivalent to the `<` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.lt(2)); + * // Column("example", [true, false]) + * } + */ + @Pure + fun lt( + other: Any + ) -> result: Cell + } + ``` + +## `#!sds fun` abs {#safeds.data.tabular.containers.Cell.abs data-toc-label='abs'} + +Get the absolute value. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, -2]); + val result = column.transform((cell) -> cell.abs()); + // Column("example", [1, 2]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="80" + @Pure + fun abs() -> result: Cell + ``` + +## `#!sds fun` add {#safeds.data.tabular.containers.Cell.add data-toc-label='add'} + +Add a value. This WILL LATER BE equivalent to the `+` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.add(3)); + // Column("example", [4, 5]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="132" + @Pure + fun add( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` and {#safeds.data.tabular.containers.Cell.and data-toc-label='and'} + +Perform a boolean AND operation. This WILL LATER BE equivalent to the ^and operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | `#!sds union>` | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [true, false]); + val result = column.transform((cell) -> cell.^and(false)); + // Column("example", [false, false]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="33" + @Pure + @PythonName("and_") + fun ^and( + other: union> + ) -> result: Cell + ``` + +## `#!sds fun` ceil {#safeds.data.tabular.containers.Cell.ceil data-toc-label='ceil'} + +Round up to the nearest integer. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1.1, 2.9]); + val result = column.transform((cell) -> cell.ceil()); + // Column("example", [2, 3]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="93" + @Pure + fun ceil() -> result: Cell + ``` + +## `#!sds fun` div {#safeds.data.tabular.containers.Cell.div data-toc-label='div'} + +Divide by a value. This WILL LATER BE equivalent to the `/` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [6, 8]); + val result = column.transform((cell) -> cell.div(2)); + // Column("example", [3, 4]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="207" + @Pure + fun div( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` eq {#safeds.data.tabular.containers.Cell.eq data-toc-label='eq'} + +Check if equal to a value. This WILL LATER BE equivalent to the `==` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.eq(2)); + // Column("example", [false, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="222" + @Pure + fun eq( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` floor {#safeds.data.tabular.containers.Cell.floor data-toc-label='floor'} + +Round down to the nearest integer. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1.1, 2.9]); + val result = column.transform((cell) -> cell.floor()); + // Column("example", [1, 2]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="106" + @Pure + fun floor() -> result: Cell + ``` + +## `#!sds fun` ge {#safeds.data.tabular.containers.Cell.ge data-toc-label='ge'} + +Check if greater than or equal to a value. This WILL LATER BE equivalent to the `>=` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.ge(2)); + // Column("example", [false, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="237" + @Pure + fun ge( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` gt {#safeds.data.tabular.containers.Cell.gt data-toc-label='gt'} + +Check if greater than a value. This WILL LATER BE equivalent to the `>` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.gt(2)); + // Column("example", [false, false]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="252" + @Pure + fun gt( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` le {#safeds.data.tabular.containers.Cell.le data-toc-label='le'} + +Check if less than or equal to a value. This WILL LATER BE equivalent to the `<=` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.le(2)); + // Column("example", [true, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="267" + @Pure + fun le( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` lt {#safeds.data.tabular.containers.Cell.lt data-toc-label='lt'} + +Check if less than a value. This WILL LATER BE equivalent to the `<` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, 2]); + val result = column.transform((cell) -> cell.lt(2)); + // Column("example", [true, false]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="282" + @Pure + fun lt( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` mod {#safeds.data.tabular.containers.Cell.mod data-toc-label='mod'} + +Perform a modulo operation. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [5, 6]); + val result = column.transform((cell) -> cell.mod(3)); + // Column("example", [2, 0]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="147" + @Pure + fun mod( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` mul {#safeds.data.tabular.containers.Cell.mul data-toc-label='mul'} + +Multiply by a value. This WILL LATER BE equivalent to the `*` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [2, 3]); + val result = column.transform((cell) -> cell.mul(4)); + // Column("example", [8, 12]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="162" + @Pure + fun mul( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` neg {#safeds.data.tabular.containers.Cell.neg data-toc-label='neg'} + +Negate the value. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [1, -2]); + val result = column.transform((cell) -> cell.neg()); + // Column("example", [-1, 2]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="119" + @Pure + fun neg() -> result: Cell + ``` + +## `#!sds fun` not {#safeds.data.tabular.containers.Cell.not data-toc-label='not'} + +Negate a boolean. This WILL LATER BE equivalent to the ^not operator. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [true, false]); + val result = column.transform((cell) -> cell.^not()); + // Column("example", [false, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="19" + @Pure + @PythonName("not_") + fun ^not() -> result: Cell + ``` + +## `#!sds fun` or {#safeds.data.tabular.containers.Cell.or data-toc-label='or'} + +Perform a boolean OR operation. This WILL LATER BE equivalent to the ^or operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | `#!sds union>` | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [true, false]); + val result = column.transform((cell) -> cell.^or(true)); + // Column("example", [true, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="49" + @Pure + @PythonName("or_") + fun ^or( + other: union> + ) -> result: Cell + ``` + +## `#!sds fun` pow {#safeds.data.tabular.containers.Cell.pow data-toc-label='pow'} + +Raise to a power. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | `#!sds union, Float>` | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [2, 3]); + val result = column.transform((cell) -> cell.pow(3.0)); + // Column("example", [8, 27]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="177" + @Pure + fun pow( + other: union + ) -> result: Cell + ``` + +## `#!sds fun` sub {#safeds.data.tabular.containers.Cell.sub data-toc-label='sub'} + +Subtract a value. This WILL LATER BE equivalent to the `-` operator. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | [`Any`][safeds.lang.Any] | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [5, 6]); + val result = column.transform((cell) -> cell.^sub(3)); + // Column("example", [2, 3]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="192" + @Pure + fun ^sub( + other: Any + ) -> result: Cell + ``` + +## `#!sds fun` xor {#safeds.data.tabular.containers.Cell.xor data-toc-label='xor'} + +Perform a boolean XOR operation. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `other` | `#!sds union>` | - | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `result` | [`Cell`][safeds.data.tabular.containers.Cell] | - | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("example", [true, false]); + val result = column.transform((cell) -> cell.xor(true)); + // Column("example", [false, true]) +} +``` + +??? quote "Stub code in `Cell.sdsstub`" + + ```sds linenums="65" + @Pure + fun xor( + other: union> + ) -> result: Cell + ``` diff --git a/docs/api/safeds/data/tabular/containers/Column.md b/docs/api/safeds/data/tabular/containers/Column.md index 273eca09f..4030f7c59 100644 --- a/docs/api/safeds/data/tabular/containers/Column.md +++ b/docs/api/safeds/data/tabular/containers/Column.md @@ -1,13 +1,13 @@ # `#!sds class` Column {#safeds.data.tabular.containers.Column data-toc-label='Column'} -A column is a named collection of values. +A named, one-dimensional collection of homogeneous values. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `name` | [`String`][safeds.lang.String] | The name of the column. | - | -| `data` | [`List`][safeds.lang.List] | The data. | `#!sds []` | +| `data` | [`List?`][safeds.lang.List] | The data of the column. If null, an empty column is created. | `#!sds null` | **Type parameters:** @@ -28,183 +28,54 @@ pipeline example { ```sds linenums="18" class Column( name: String, - data: List = [] + data: List? = null ) { /** - * Return the name of the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val name = column.name; // "test" - * } + * Whether the column is numeric. */ - attr name: String + @PythonName("is_numeric") attr isNumeric: Boolean /** - * Return the number of elements in the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val numberOfRows = column.numberOfRows; // 3 - * } - */ - @PythonName("number_of_rows") attr numberOfRows: Int - /** - * Return the type of the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val type = column.type; // Integer - * } - * - * @example - * pipeline example { - * val column = Column("test", ["a", "b", "c"]); - * val type = column.type; // String - * } + * Whether the column is temporal. */ - attr type: ColumnType - + @PythonName("is_temporal") attr isTemporal: Boolean /** - * Return a list of all unique values in the column. - * - * @result result1 List of unique values in the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, 2, 4, 3]); - * val uniqueValues = column.getUniqueValues(); // [1, 2, 3, 4] - * } + * The name of the column. */ - @Deprecated( - alternative="Try ExperimentalColumn.getDistinctValues instead.", - reason="The word 'unique' could imply that only values that occur exactly once are returned.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("get_unique_values") - fun getUniqueValues() -> result1: List - + attr name: String /** - * Return column value at specified index, starting at 0. - * - * @param index Index of requested element. - * - * @result result1 Value at index in column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val value = column.getValue(1); // 2 - * } + * The number of rows in the column. */ - @Pure - @PythonName("get_value") - fun getValue( - index: Int - ) -> result1: T - + @PythonName("number_of_rows") attr rowCount: Int /** - * Check if all values have a given property. - * - * @param predicate Callable that is used to find matches. - * - * @result allMatch True if all match. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val allMatch = column.all((value) -> value < 4); // true - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val allMatch = column.all((value) -> value < 2); // false - * } + * The plotter for the column. */ - @Pure - fun all( - predicate: (value: T) -> matches: Boolean - ) -> allMatch: Boolean - + attr plot: ColumnPlotter /** - * Check if any value has a given property. - * - * @param predicate Callable that is used to find matches. - * - * @result anyMatch True if any match. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val anyMatch = column.any((value) -> value < 2); // true - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val anyMatch = column.any((value) -> value < 1); // false - * } + * The type of the column. */ - @Pure - fun any( - predicate: (value: T) -> matches: Boolean - ) -> anyMatch: Boolean + attr type: DataType /** - * Check if no values has a given property. - * - * @param predicate Callable that is used to find matches. - * - * @result noneMatch True if none match. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val noneMatch = column.none((value) -> value < 1); // true - * } + * Return the column value at specified index. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val noneMatch = column.none((value) -> value > 1); // false - * } - */ - @Pure - fun none( - predicate: (value: T) -> matches: Boolean - ) -> noneMatch: Boolean - - /** - * Return whether the column has missing values. + * Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at + * -1). * - * @result hasMissingValues True if missing values exist. + * @param index Index of requested value. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val hasMissingValues = column.hasMissingValues(); // true - * } + * @result value Value at index. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val hasMissingValues = column.hasMissingValues(); // false + * val result = column.getValue(1); // 2 * } */ - @Deprecated( - alternative="Column.missingValueCount() > 0.", - reason="Barely saves any characters.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("has_missing_values") - fun hasMissingValues() -> hasMissingValues: Boolean + @PythonName("get_value") + fun getValue( + index: Int + ) -> value: T /** * Return a new column with a new name. @@ -218,46 +89,45 @@ pipeline example { * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val renamedColumn = column.rename("new_name"); + * val result = column.rename("new_name"); + * // Column("new_name", [1, 2, 3]) * } */ @Pure fun rename( @PythonName("new_name") newName: String - ) -> renamedColumn: Column + ) -> renamedColumn: Column /** - * Apply a transform method to every data point. + * Return a new column with values transformed by the transformer. * * The original column is not modified. * - * @param transformer Function that will be applied to all data points. + * @param transformer The transformer to apply to each value. * - * @result transformedColumn The transformed column. + * @result transformedColumn A new column with transformed values. * * @example * pipeline example { - * val price = Column("price", [4.99, 5.99, 2.49]); - * val discountedPrice = price.transform((value) -> value * 0.75); + * val column = Column("test", [1, 2, 3]); + * val result = column.transform((cell) -> cell.mul(2)); + * // Column("test", [2, 4, 6]) * } */ @Pure fun transform( - transformer: (value: T) -> transformedValue: R + transformer: (cell: Cell) -> transformedCell: Cell ) -> transformedColumn: Column /** - * Return a table with a number of statistical key values. - * - * The original Column is not modified. + * Return a table with important statistics about the column. * * @result statistics The table with statistics. * * @example * pipeline example { - * // from safeds.data.tabular.containers import Column - * // column = Column("a", [1, 3]) - * // column.summarize_statistics() + * val column = Column("a", [1, 3]); + * val result = column.summarizeStatistics(); * } */ @Pure @@ -265,229 +135,213 @@ pipeline example { fun summarizeStatistics() -> statistics: Table /** - * Calculate Pearson correlation between this and another column. Both columns have to be numerical. + * Calculate the Pearson correlation between this column and another column. + * + * The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly + * related: * - * @result correlation Correlation between the two columns. + * - A correlation of -1 indicates a perfect negative linear relationship. + * - A correlation of 0 indicates no linear relationship. + * - A correlation of 1 indicates a perfect positive linear relationship. + * + * @param other The other column to calculate the correlation with. + * + * @result correlation The Pearson correlation between the two columns. * * @example * pipeline example { - * val column1 = Column("test1", [1, 2, 3]); - * val column2 = Column("test2", [2, 4, 6]); - * val correlation = column1.correlationWith(column2); // 1.0 + * val column1 = Column("test", [1, 2, 3]); + * val column2 = Column("test", [2, 4, 6]); + * val result = column1.correlationWith(column2); * } * * @example * pipeline example { - * val column1 = Column("test1", [1, 2, 3]); - * val column2 = Column("test2", [3, 2, 1]); - * val correlation = column1.correlationWith(column2); // -1.0 + * val column1 = Column("test", [1, 2, 3]); + * val column2 = Column("test", [3, 2, 1]); + * val result = column1.correlationWith(column2); * } */ @Pure @PythonName("correlation_with") fun correlationWith( - @PythonName("other_column") otherColumn: Column + other: Column ) -> correlation: Float + /** + * Return the number of distinct values in the column. + * + * @param ignoreMissingValues Whether to ignore missing values when counting distinct values. + * + * @result distinctValueCount The number of distinct values in the column. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3, 2]); + * val result = column.distinctValueCount(); // 3 + * } + */ + @Pure + @PythonName("distinct_value_count") + fun distinctValueCount( + @PythonName("ignore_missing_values") ignoreMissingValues: Boolean = true + ) -> distinctValueCount: Int + /** * Calculate the idness of this column. * - * We define the idness as follows: + * We define the idness as the number of distinct values (including missing values) divided by the number of rows. + * If the column is empty, the idness is 1.0. * - * $$ - * \frac{\text{number of different values}}{\text{number of rows}} - * $$ + * A high idness indicates that the column most values in the column are unique. In this case, you must be careful + * when using the column for analysis, as a model may learn a mapping from this column to the target. * * @result idness The idness of the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val idness = column.idness(); // 1.0 + * val result = column.idness(); // 1.0 * } * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val idness = column.idness(); // 0.75 + * val column = Column("test", [1, 2, 3, 2]); + * val result = column.idness(); // 0.75 * } */ @Pure fun idness() -> idness: Float /** - * Return the maximum value of the column. The column has to be numerical. + * Return the maximum value in the column. * - * @result maximum The maximum value. + * @result max The maximum value in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val maximum = column.maximum(); // 3 + * val result = column.max(); // 3 * } */ - @Deprecated( - alternative="Try ExperimentalColumn.max instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - fun maximum() -> maximum: Float + fun max() -> max: T? /** - * Return the mean value of the column. The column has to be numerical. + * Return the mean of the values in the column. + * + * The mean is the sum of the values divided by the number of values. * - * @result mean The mean value. + * @result mean The mean of the values in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val mean = column.mean(); // 2.0 + * val result = column.mean(); // 2.0 * } */ @Pure - fun mean() -> mean: Float + fun mean() -> mean: T /** - * Return the median value of the column. The column has to be numerical. + * Return the median of the values in the column. * - * @result median The median value. + * The median is the value in the middle of the sorted list of values. If the number of values is even, the median + * is the mean of the two middle values. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val median = column.median(); // 2.0 - * } + * @result median The median of the values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val median = column.median(); // 2.5 + * val column = Column("test", [1, 2, 3]); + * val result = column.median(); // 2.0 * } */ @Pure - fun median() -> median: Float + fun median() -> median: T /** - * Return the minimum value of the column. The column has to be numerical. + * Return the minimum value in the column. * - * @result minimum The minimum value. + * @result min The minimum value in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val minimum = column.minimum(); // 1 + * val result = column.min(); // 1 * } */ - @Deprecated( - alternative="Try ExperimentalColumn.min instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - fun minimum() -> minimum: Float + fun min() -> min: T? /** * Return the number of missing values in the column. * - * @result count The number of missing values. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val missingValueCount = column.missingValueCount(); // 0 - * } + * @result missingValueCount The number of missing values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val missingValueCount = column.missingValueCount(); // 1 + * val column = Column("test", [1, null, 3]); + * val result = column.missingValueCount(); // 1 * } */ @Pure @PythonName("missing_value_count") - fun missingValueCount() -> count: Int + fun missingValueCount() -> missingValueCount: Int /** - * Return the ratio of missing values to the total number of elements in the column. - * - * @result missinValueRatio The ratio of missing values to the total number of elements in the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val missingValueRatio = column.missingValueRatio(); // 0.0 - * } + * Return the missing value ratio. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val missingValueRatio = column.missingValueRatio(); // 0.25 - * } - */ - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missinValueRatio: Float - - /** - * Return the mode of the column. + * We define the missing value ratio as the number of missing values in the column divided by the number of rows. + * If the column is empty, the missing value ratio is 1.0. * - * @result mode Returns a list with the most common values. + * A high missing value ratio indicates that the column is dominated by missing values. In this case, the column + * may not be useful for analysis. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val mode = column.mode(); // [2] - * } + * @result missingValueRatio The ratio of missing values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3, 3]); - * val mode = column.mode(); // [2, 3] + * val column = Column("test", [1, null, 3, null]); + * val result = column.missingValueRatio(); // 0.5 * } */ @Pure - fun mode() -> mode: List + @PythonName("missing_value_ratio") + fun missingValueRatio() -> missingValueRatio: Float /** - * Calculate the stability of this column. - * - * We define the stability as follows: + * Return the stability of the column. * - * $$ - * \frac{\text{number of occurrences of most common non-null value}}{\text{number of non-null values}} - * $$ + * We define the stability as the number of occurrences of the most common non-missing value divided by the total + * number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. * - * The stability is not defined for a column with only null values. + * A high stability indicates that the column is dominated by a single value. In this case, the column may not be + * useful for analysis. * * @result stability The stability of the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val stability = column.stability(); // 0.5 - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 2, 3, null]); - * val stability = column.stability(); // 0.5 + * val column = Column("test", [1, 1, 2, 3, null]); + * val result = column.stability(); // 0.5 * } */ @Pure fun stability() -> stability: Float /** - * Return the standard deviation of the column. The column has to be numerical. + * Return the standard deviation of the values in the column. + * + * The standard deviation is the square root of the variance. * - * @result standardDeviation The standard deviation of all values. + * @result standardDeviation The standard deviation of the values in the column. If no standard deviation can be calculated due to the + * type of the column, null is returned. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val standardDeviation = column.standardDeviation(); // 1.0 + * val result = column.standardDeviation(); // 1.0 * } */ @Pure @@ -495,468 +349,223 @@ pipeline example { fun standardDeviation() -> standardDeviation: Float /** - * Return the sum of the column. The column has to be numerical. + * Return the variance of the values in the column. * - * @result sum The sum of all values. + * The variance is the average of the squared differences from the mean. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val sum = column.sum(); // 6 - * } - */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - fun sum() -> sum: Float - - /** - * Return the variance of the column. The column has to be numerical. - * - * @result variance The variance of all values. + * @result variance The variance of the values in the column. If no variance can be calculated due to the type of the column, + * null is returned. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val variance = column.variance(); // 1.0 + * val result = column.variance(); // 1.0 * } */ @Pure fun variance() -> variance: Float /** - * Plot this column in a boxplot. This function can only plot real numerical data. - * - * @result boxplot The plot as an image. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val plot = column.plotBoxplot(); - * } - */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.boxPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_boxplot") - fun plotBoxplot() -> boxplot: Image - - /** - * Plot a column in a histogram. + * Return the values of the column in a list. * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. - * - * @result histogram The plot as an image. + * @result values The values of the column in a list. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val plot = column.plotHistogram(); - * } - */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.histogram instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_histogram") - fun plotHistogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image - - /** - * Create a plot comparing the numerical values of columns using IDs as the x-axis. - * - * @param columnList A list of time columns to be plotted. - * - * @result plot A plot with all the Columns plotted by the ID on the x-axis. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Column - * // col1 =Column("target", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) - * // col2 =Column("target", [42, 51, 63, 71, 83, 91, 10, 11, 12, 13]) - * // image = col1.plot_compare_columns([col2]) - * } - */ - @Deprecated( - alternative="We still decide where to move this.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_compare_columns") - fun plotCompareColumns( - @PythonName("column_list") columnList: List> - ) -> plot: Image - - /** - * Plot a lagplot for the given column. - * - * @param lag The amount of lag used to plot - * - * @result plot The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Column("values", [1,2,3,4,3,2]) - * // image = table.plot_lagplot(2) + * val result = column.toList(); // [1, 2, 3] * } */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.lagPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_lagplot") - fun plotLagplot( - lag: Int - ) -> plot: Image + @PythonName("to_list") + fun toList() -> values: List /** * Create a table that contains only this column. * * @result table The table with this column. - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: Table - - /** - * Return an HTML representation of the column. - * - * @result html The generated HTML. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val html = column.toHtml(); + * val result = column.toTable(); + * // Table({"test": [1, 2, 3]}) * } */ @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("to_table") + fun toTable() -> table: Table } ``` -## `#!sds attr` name {#safeds.data.tabular.containers.Column.name data-toc-label='name'} - -Return the name of the column. - -**Type:** [`String`][safeds.lang.String] - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val name = column.name; // "test" -} -``` - -## `#!sds attr` numberOfRows {#safeds.data.tabular.containers.Column.numberOfRows data-toc-label='numberOfRows'} - -Return the number of elements in the column. - -**Type:** [`Int`][safeds.lang.Int] - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val numberOfRows = column.numberOfRows; // 3 -} -``` - -## `#!sds attr` type {#safeds.data.tabular.containers.Column.type data-toc-label='type'} - -Return the type of the column. - -**Type:** [`ColumnType`][safeds.data.tabular.typing.ColumnType] - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val type = column.type; // Integer -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", ["a", "b", "c"]); - val type = column.type; // String -} -``` - -## `#!sds fun` all {#safeds.data.tabular.containers.Column.all data-toc-label='all'} +## `#!sds attr` isNumeric {#safeds.data.tabular.containers.Column.isNumeric data-toc-label='isNumeric'} -Check if all values have a given property. +Whether the column is numeric. -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (value: T) -> (matches: Boolean)` | Callable that is used to find matches. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `allMatch` | [`Boolean`][safeds.lang.Boolean] | True if all match. | +**Type:** [`Boolean`][safeds.lang.Boolean] -**Examples:** +## `#!sds attr` isTemporal {#safeds.data.tabular.containers.Column.isTemporal data-toc-label='isTemporal'} -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val allMatch = column.all((value) -> value < 4); // true -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val allMatch = column.all((value) -> value < 2); // false -} -``` +Whether the column is temporal. -??? quote "Stub code in `Column.sdsstub`" +**Type:** [`Boolean`][safeds.lang.Boolean] - ```sds linenums="118" - @Pure - fun all( - predicate: (value: T) -> matches: Boolean - ) -> allMatch: Boolean - ``` +## `#!sds attr` name {#safeds.data.tabular.containers.Column.name data-toc-label='name'} -## `#!sds fun` any {#safeds.data.tabular.containers.Column.any data-toc-label='any'} +The name of the column. -Check if any value has a given property. +**Type:** [`String`][safeds.lang.String] -**Parameters:** +## `#!sds attr` plot {#safeds.data.tabular.containers.Column.plot data-toc-label='plot'} -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (value: T) -> (matches: Boolean)` | Callable that is used to find matches. | - | +The plotter for the column. -**Results:** +**Type:** [`ColumnPlotter`][safeds.data.tabular.plotting.ColumnPlotter] -| Name | Type | Description | -|------|------|-------------| -| `anyMatch` | [`Boolean`][safeds.lang.Boolean] | True if any match. | +## `#!sds attr` rowCount {#safeds.data.tabular.containers.Column.rowCount data-toc-label='rowCount'} -**Examples:** +The number of rows in the column. -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val anyMatch = column.any((value) -> value < 2); // true -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val anyMatch = column.any((value) -> value < 1); // false -} -``` +**Type:** [`Int`][safeds.lang.Int] -??? quote "Stub code in `Column.sdsstub`" +## `#!sds attr` type {#safeds.data.tabular.containers.Column.type data-toc-label='type'} - ```sds linenums="142" - @Pure - fun any( - predicate: (value: T) -> matches: Boolean - ) -> anyMatch: Boolean - ``` +The type of the column. + +**Type:** [`DataType`][safeds.data.tabular.typing.DataType] ## `#!sds fun` correlationWith {#safeds.data.tabular.containers.Column.correlationWith data-toc-label='correlationWith'} -Calculate Pearson correlation between this and another column. Both columns have to be numerical. +Calculate the Pearson correlation between this column and another column. + +The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly +related: + +- A correlation of -1 indicates a perfect negative linear relationship. +- A correlation of 0 indicates no linear relationship. +- A correlation of 1 indicates a perfect positive linear relationship. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `otherColumn` | [`Column`][safeds.data.tabular.containers.Column] | - | - | +| `other` | [`Column`][safeds.data.tabular.containers.Column] | The other column to calculate the correlation with. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `correlation` | [`Float`][safeds.lang.Float] | Correlation between the two columns. | +| `correlation` | [`Float`][safeds.lang.Float] | The Pearson correlation between the two columns. | **Examples:** ```sds hl_lines="4" pipeline example { - val column1 = Column("test1", [1, 2, 3]); - val column2 = Column("test2", [2, 4, 6]); - val correlation = column1.correlationWith(column2); // 1.0 + val column1 = Column("test", [1, 2, 3]); + val column2 = Column("test", [2, 4, 6]); + val result = column1.correlationWith(column2); } ``` ```sds hl_lines="4" pipeline example { - val column1 = Column("test1", [1, 2, 3]); - val column2 = Column("test2", [3, 2, 1]); - val correlation = column1.correlationWith(column2); // -1.0 + val column1 = Column("test", [1, 2, 3]); + val column2 = Column("test", [3, 2, 1]); + val result = column1.correlationWith(column2); } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="275" + ```sds linenums="154" @Pure @PythonName("correlation_with") fun correlationWith( - @PythonName("other_column") otherColumn: Column + other: Column ) -> correlation: Float ``` -## :warning:{ title="Deprecated" } `#!sds fun` getUniqueValues {#safeds.data.tabular.containers.Column.getUniqueValues data-toc-label='getUniqueValues'} - -!!! warning "Deprecated" +## `#!sds fun` distinctValueCount {#safeds.data.tabular.containers.Column.distinctValueCount data-toc-label='distinctValueCount'} - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +Return the number of distinct values in the column. - - **Alternative:** Try ExperimentalColumn.getDistinctValues instead. - - **Reason:** The word 'unique' could imply that only values that occur exactly once are returned. +**Parameters:** -Return a list of all unique values in the column. +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `ignoreMissingValues` | [`Boolean`][safeds.lang.Boolean] | Whether to ignore missing values when counting distinct values. | `#!sds true` | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | List of unique values in the column. | +| `distinctValueCount` | [`Int`][safeds.lang.Int] | The number of distinct values in the column. | **Examples:** ```sds hl_lines="3" pipeline example { - val column = Column("test", [1, 2, 3, 2, 4, 3]); - val uniqueValues = column.getUniqueValues(); // [1, 2, 3, 4] + val column = Column("test", [1, 2, 3, 2]); + val result = column.distinctValueCount(); // 3 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="70" - @Deprecated( - alternative="Try ExperimentalColumn.getDistinctValues instead.", - reason="The word 'unique' could imply that only values that occur exactly once are returned.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="173" @Pure - @PythonName("get_unique_values") - fun getUniqueValues() -> result1: List + @PythonName("distinct_value_count") + fun distinctValueCount( + @PythonName("ignore_missing_values") ignoreMissingValues: Boolean = true + ) -> distinctValueCount: Int ``` ## `#!sds fun` getValue {#safeds.data.tabular.containers.Column.getValue data-toc-label='getValue'} -Return column value at specified index, starting at 0. +Return the column value at specified index. + +Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at +-1). **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `index` | [`Int`][safeds.lang.Int] | Index of requested element. | - | +| `index` | [`Int`][safeds.lang.Int] | Index of requested value. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | `#!sds T` | Value at index in column. | +| `value` | `#!sds T` | Value at index. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val value = column.getValue(1); // 2 + val result = column.getValue(1); // 2 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="93" + ```sds linenums="63" @Pure @PythonName("get_value") fun getValue( index: Int - ) -> result1: T - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` hasMissingValues {#safeds.data.tabular.containers.Column.hasMissingValues data-toc-label='hasMissingValues'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Column.missingValueCount() > 0. - - **Reason:** Barely saves any characters. - -Return whether the column has missing values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `hasMissingValues` | [`Boolean`][safeds.lang.Boolean] | True if missing values exist. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3, null]); - val hasMissingValues = column.hasMissingValues(); // true -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val hasMissingValues = column.hasMissingValues(); // false -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="188" - @Deprecated( - alternative="Column.missingValueCount() > 0.", - reason="Barely saves any characters.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("has_missing_values") - fun hasMissingValues() -> hasMissingValues: Boolean + ) -> value: T ``` ## `#!sds fun` idness {#safeds.data.tabular.containers.Column.idness data-toc-label='idness'} Calculate the idness of this column. -We define the idness as follows: +We define the idness as the number of distinct values (including missing values) divided by the number of rows. +If the column is empty, the idness is 1.0. -$$ -\frac{\text{number of different values}}{\text{number of rows}} -$$ +A high idness indicates that the column most values in the column are unique. In this case, you must be careful +when using the column for analysis, as a model may learn a mapping from this column to the target. **Results:** @@ -969,157 +578,130 @@ $$ ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val idness = column.idness(); // 1.0 + val result = column.idness(); // 1.0 } ``` ```sds hl_lines="3" pipeline example { - val column = Column("test", [1, 2, 2, 3]); - val idness = column.idness(); // 0.75 + val column = Column("test", [1, 2, 3, 2]); + val result = column.idness(); // 0.75 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="304" + ```sds linenums="202" @Pure fun idness() -> idness: Float ``` -## :warning:{ title="Deprecated" } `#!sds fun` maximum {#safeds.data.tabular.containers.Column.maximum data-toc-label='maximum'} - -!!! warning "Deprecated" +## `#!sds fun` max {#safeds.data.tabular.containers.Column.max data-toc-label='max'} - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalColumn.max instead. - - **Reason:** More concise. - -Return the maximum value of the column. The column has to be numerical. +Return the maximum value in the column. **Results:** | Name | Type | Description | |------|------|-------------| -| `maximum` | [`Float`][safeds.lang.Float] | The maximum value. | +| `max` | `#!sds T?` | The maximum value in the column. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val maximum = column.maximum(); // 3 + val result = column.max(); // 3 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="318" - @Deprecated( - alternative="Try ExperimentalColumn.max instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="216" @Pure - fun maximum() -> maximum: Float + fun max() -> max: T? ``` ## `#!sds fun` mean {#safeds.data.tabular.containers.Column.mean data-toc-label='mean'} -Return the mean value of the column. The column has to be numerical. +Return the mean of the values in the column. + +The mean is the sum of the values divided by the number of values. **Results:** | Name | Type | Description | |------|------|-------------| -| `mean` | [`Float`][safeds.lang.Float] | The mean value. | +| `mean` | `#!sds T` | The mean of the values in the column. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val mean = column.mean(); // 2.0 + val result = column.mean(); // 2.0 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="338" + ```sds linenums="232" @Pure - fun mean() -> mean: Float + fun mean() -> mean: T ``` ## `#!sds fun` median {#safeds.data.tabular.containers.Column.median data-toc-label='median'} -Return the median value of the column. The column has to be numerical. +Return the median of the values in the column. + +The median is the value in the middle of the sorted list of values. If the number of values is even, the median +is the mean of the two middle values. **Results:** | Name | Type | Description | |------|------|-------------| -| `median` | [`Float`][safeds.lang.Float] | The median value. | +| `median` | `#!sds T` | The median of the values in the column. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val median = column.median(); // 2.0 -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3, 4]); - val median = column.median(); // 2.5 + val result = column.median(); // 2.0 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="358" + ```sds linenums="249" @Pure - fun median() -> median: Float + fun median() -> median: T ``` -## :warning:{ title="Deprecated" } `#!sds fun` minimum {#safeds.data.tabular.containers.Column.minimum data-toc-label='minimum'} +## `#!sds fun` min {#safeds.data.tabular.containers.Column.min data-toc-label='min'} -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalColumn.min instead. - - **Reason:** More concise. - -Return the minimum value of the column. The column has to be numerical. +Return the minimum value in the column. **Results:** | Name | Type | Description | |------|------|-------------| -| `minimum` | [`Float`][safeds.lang.Float] | The minimum value. | +| `min` | `#!sds T?` | The minimum value in the column. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val minimum = column.minimum(); // 1 + val result = column.min(); // 1 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="372" - @Deprecated( - alternative="Try ExperimentalColumn.min instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="263" @Pure - fun minimum() -> minimum: Float + fun min() -> min: T? ``` ## `#!sds fun` missingValueCount {#safeds.data.tabular.containers.Column.missingValueCount data-toc-label='missingValueCount'} @@ -1130,321 +712,56 @@ Return the number of missing values in the column. | Name | Type | Description | |------|------|-------------| -| `count` | [`Int`][safeds.lang.Int] | The number of missing values. | +| `missingValueCount` | [`Int`][safeds.lang.Int] | The number of missing values in the column. | **Examples:** ```sds hl_lines="3" pipeline example { - val column = Column("test", [1, 2, 3, 4]); - val missingValueCount = column.missingValueCount(); // 0 -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3, null]); - val missingValueCount = column.missingValueCount(); // 1 + val column = Column("test", [1, null, 3]); + val result = column.missingValueCount(); // 1 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="398" + ```sds linenums="277" @Pure @PythonName("missing_value_count") - fun missingValueCount() -> count: Int + fun missingValueCount() -> missingValueCount: Int ``` ## `#!sds fun` missingValueRatio {#safeds.data.tabular.containers.Column.missingValueRatio data-toc-label='missingValueRatio'} -Return the ratio of missing values to the total number of elements in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `missinValueRatio` | [`Float`][safeds.lang.Float] | The ratio of missing values to the total number of elements in the column. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3, 4]); - val missingValueRatio = column.missingValueRatio(); // 0.0 -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3, null]); - val missingValueRatio = column.missingValueRatio(); // 0.25 -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="419" - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missinValueRatio: Float - ``` - -## `#!sds fun` mode {#safeds.data.tabular.containers.Column.mode data-toc-label='mode'} - -Return the mode of the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `mode` | [`List`][safeds.lang.List] | Returns a list with the most common values. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 2, 3]); - val mode = column.mode(); // [2] -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 2, 3, 3]); - val mode = column.mode(); // [2, 3] -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="440" - @Pure - fun mode() -> mode: List - ``` - -## `#!sds fun` none {#safeds.data.tabular.containers.Column.none data-toc-label='none'} - -Check if no values has a given property. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (value: T) -> (matches: Boolean)` | Callable that is used to find matches. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `noneMatch` | [`Boolean`][safeds.lang.Boolean] | True if none match. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val noneMatch = column.none((value) -> value < 1); // true -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val noneMatch = column.none((value) -> value > 1); // false -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="166" - @Pure - fun none( - predicate: (value: T) -> matches: Boolean - ) -> noneMatch: Boolean - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotBoxplot {#safeds.data.tabular.containers.Column.plotBoxplot data-toc-label='plotBoxplot'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalColumn.plot.boxPlot instead. - - **Reason:** Groups all plotting methods in one place. - -Plot this column in a boxplot. This function can only plot real numerical data. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `boxplot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val plot = column.plotBoxplot(); -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="531" - @Deprecated( - alternative="Try ExperimentalColumn.plot.boxPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_boxplot") - fun plotBoxplot() -> boxplot: Image - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotCompareColumns {#safeds.data.tabular.containers.Column.plotCompareColumns data-toc-label='plotCompareColumns'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** We still decide where to move this. - - **Reason:** Groups all plotting methods in one place. - -Create a plot comparing the numerical values of columns using IDs as the x-axis. - -**Parameters:** +Return the missing value ratio. -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columnList` | [`List>`][safeds.lang.List] | A list of time columns to be plotted. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `plot` | [`Image`][safeds.data.image.containers.Image] | A plot with all the Columns plotted by the ID on the x-axis. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import Column - // col1 =Column("target", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) - // col2 =Column("target", [42, 51, 63, 71, 83, 91, 10, 11, 12, 13]) - // image = col1.plot_compare_columns([col2]) -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="581" - @Deprecated( - alternative="We still decide where to move this.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_compare_columns") - fun plotCompareColumns( - @PythonName("column_list") columnList: List> - ) -> plot: Image - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotHistogram {#safeds.data.tabular.containers.Column.plotHistogram data-toc-label='plotHistogram'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalColumn.plot.histogram instead. - - **Reason:** Groups all plotting methods in one place. - -Plot a column in a histogram. - -**Parameters:** +We define the missing value ratio as the number of missing values in the column divided by the number of rows. +If the column is empty, the missing value ratio is 1.0. -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to use in the histogram. Default is 10. | `#!sds 10` | +A high missing value ratio indicates that the column is dominated by missing values. In this case, the column +may not be useful for analysis. **Results:** | Name | Type | Description | |------|------|-------------| -| `plot` | [`Image`][safeds.data.image.containers.Image] | - | +| `missingValueRatio` | [`Float`][safeds.lang.Float] | The ratio of missing values in the column. | **Examples:** ```sds hl_lines="3" pipeline example { - val column = Column("test", [1, 2, 3]); - val plot = column.plotHistogram(); -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="554" - @Deprecated( - alternative="Try ExperimentalColumn.plot.histogram instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_histogram") - fun plotHistogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotLagplot {#safeds.data.tabular.containers.Column.plotLagplot data-toc-label='plotLagplot'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalColumn.plot.lagPlot instead. - - **Reason:** Groups all plotting methods in one place. - -Plot a lagplot for the given column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `lag` | [`Int`][safeds.lang.Int] | The amount of lag used to plot | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `plot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import Table - // table = Column("values", [1,2,3,4,3,2]) - // image = table.plot_lagplot(2) + val column = Column("test", [1, null, 3, null]); + val result = column.missingValueRatio(); // 0.5 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="607" - @Deprecated( - alternative="Try ExperimentalColumn.plot.lagPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="298" @Pure - @PythonName("plot_lagplot") - fun plotLagplot( - lag: Int - ) -> plot: Image + @PythonName("missing_value_ratio") + fun missingValueRatio() -> missingValueRatio: Float ``` ## `#!sds fun` rename {#safeds.data.tabular.containers.Column.rename data-toc-label='rename'} @@ -1463,37 +780,36 @@ The original column is not modified. | Name | Type | Description | |------|------|-------------| -| `renamedColumn` | [`Column`][safeds.data.tabular.containers.Column] | A new column with the new name. | +| `renamedColumn` | [`Column`][safeds.data.tabular.containers.Column] | A new column with the new name. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val renamedColumn = column.rename("new_name"); + val result = column.rename("new_name"); + // Column("new_name", [1, 2, 3]) } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="213" + ```sds linenums="85" @Pure fun rename( @PythonName("new_name") newName: String - ) -> renamedColumn: Column + ) -> renamedColumn: Column ``` ## `#!sds fun` stability {#safeds.data.tabular.containers.Column.stability data-toc-label='stability'} -Calculate the stability of this column. - -We define the stability as follows: +Return the stability of the column. -$$ -\frac{\text{number of occurrences of most common non-null value}}{\text{number of non-null values}} -$$ +We define the stability as the number of occurrences of the most common non-missing value divided by the total +number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. -The stability is not defined for a column with only null values. +A high stability indicates that the column is dominated by a single value. In this case, the column may not be +useful for analysis. **Results:** @@ -1505,95 +821,50 @@ The stability is not defined for a column with only null values. ```sds hl_lines="3" pipeline example { - val column = Column("test", [1, 2, 2, 3]); - val stability = column.stability(); // 0.5 -} -``` -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 2, 3, null]); - val stability = column.stability(); // 0.5 + val column = Column("test", [1, 1, 2, 3, null]); + val result = column.stability(); // 0.5 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="468" + ```sds linenums="319" @Pure fun stability() -> stability: Float ``` ## `#!sds fun` standardDeviation {#safeds.data.tabular.containers.Column.standardDeviation data-toc-label='standardDeviation'} -Return the standard deviation of the column. The column has to be numerical. +Return the standard deviation of the values in the column. + +The standard deviation is the square root of the variance. **Results:** | Name | Type | Description | |------|------|-------------| -| `standardDeviation` | [`Float`][safeds.lang.Float] | The standard deviation of all values. | +| `standardDeviation` | [`Float`][safeds.lang.Float] | The standard deviation of the values in the column. If no standard deviation can be calculated due to the type of the column, null is returned. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val standardDeviation = column.standardDeviation(); // 1.0 + val result = column.standardDeviation(); // 1.0 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="482" + ```sds linenums="336" @Pure @PythonName("standard_deviation") fun standardDeviation() -> standardDeviation: Float ``` -## :warning:{ title="Deprecated" } `#!sds fun` sum {#safeds.data.tabular.containers.Column.sum data-toc-label='sum'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** No use case. - -Return the sum of the column. The column has to be numerical. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `sum` | [`Float`][safeds.lang.Float] | The sum of all values. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val column = Column("test", [1, 2, 3]); - val sum = column.sum(); // 6 -} -``` - -??? quote "Stub code in `Column.sdsstub`" - - ```sds linenums="497" - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - fun sum() -> sum: Float - ``` - ## `#!sds fun` summarizeStatistics {#safeds.data.tabular.containers.Column.summarizeStatistics data-toc-label='summarizeStatistics'} -Return a table with a number of statistical key values. - -The original Column is not modified. +Return a table with important statistics about the column. **Results:** @@ -1603,47 +874,46 @@ The original Column is not modified. **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // from safeds.data.tabular.containers import Column - // column = Column("a", [1, 3]) - // column.summarize_statistics() + val column = Column("a", [1, 3]); + val result = column.summarizeStatistics(); } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="252" + ```sds linenums="122" @Pure @PythonName("summarize_statistics") fun summarizeStatistics() -> statistics: Table ``` -## `#!sds fun` toHtml {#safeds.data.tabular.containers.Column.toHtml data-toc-label='toHtml'} +## `#!sds fun` toList {#safeds.data.tabular.containers.Column.toList data-toc-label='toList'} -Return an HTML representation of the column. +Return the values of the column in a list. **Results:** | Name | Type | Description | |------|------|-------------| -| `html` | [`String`][safeds.lang.String] | The generated HTML. | +| `values` | [`List`][safeds.lang.List] | The values of the column in a list. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val html = column.toHtml(); + val result = column.toList(); // [1, 2, 3] } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="639" + ```sds linenums="368" @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("to_list") + fun toList() -> values: List ``` ## `#!sds fun` toTable {#safeds.data.tabular.containers.Column.toTable data-toc-label='toTable'} @@ -1656,9 +926,19 @@ Create a table that contains only this column. |------|------|-------------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table with this column. | +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("test", [1, 2, 3]); + val result = column.toTable(); + // Table({"test": [1, 2, 3]}) +} +``` + ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="624" + ```sds linenums="384" @Pure @PythonName("to_table") fun toTable() -> table: Table @@ -1666,7 +946,7 @@ Create a table that contains only this column. ## `#!sds fun` transform {#safeds.data.tabular.containers.Column.transform data-toc-label='transform'} -Apply a transform method to every data point. +Return a new column with values transformed by the transformer. The original column is not modified. @@ -1674,13 +954,13 @@ The original column is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `transformer` | `#!sds (value: T) -> (transformedValue: R)` | Function that will be applied to all data points. | - | +| `transformer` | `#!sds (cell: Cell) -> (transformedCell: Cell)` | The transformer to apply to each value. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `transformedColumn` | [`Column`][safeds.data.tabular.containers.Column] | The transformed column. | +| `transformedColumn` | [`Column`][safeds.data.tabular.containers.Column] | A new column with transformed values. | **Type parameters:** @@ -1692,42 +972,45 @@ The original column is not modified. ```sds hl_lines="3" pipeline example { - val price = Column("price", [4.99, 5.99, 2.49]); - val discountedPrice = price.transform((value) -> value * 0.75); + val column = Column("test", [1, 2, 3]); + val result = column.transform((cell) -> cell.mul(2)); + // Column("test", [2, 4, 6]) } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="233" + ```sds linenums="106" @Pure fun transform( - transformer: (value: T) -> transformedValue: R + transformer: (cell: Cell) -> transformedCell: Cell ) -> transformedColumn: Column ``` ## `#!sds fun` variance {#safeds.data.tabular.containers.Column.variance data-toc-label='variance'} -Return the variance of the column. The column has to be numerical. +Return the variance of the values in the column. + +The variance is the average of the squared differences from the mean. **Results:** | Name | Type | Description | |------|------|-------------| -| `variance` | [`Float`][safeds.lang.Float] | The variance of all values. | +| `variance` | [`Float`][safeds.lang.Float] | The variance of the values in the column. If no variance can be calculated due to the type of the column, null is returned. | **Examples:** ```sds hl_lines="3" pipeline example { val column = Column("test", [1, 2, 3]); - val variance = column.variance(); // 1.0 + val result = column.variance(); // 1.0 } ``` ??? quote "Stub code in `Column.sdsstub`" - ```sds linenums="517" + ```sds linenums="354" @Pure fun variance() -> variance: Float ``` diff --git a/docs/api/safeds/data/tabular/containers/ExperimentalCell.md b/docs/api/safeds/data/tabular/containers/ExperimentalCell.md deleted file mode 100644 index 01bd1f95a..000000000 --- a/docs/api/safeds/data/tabular/containers/ExperimentalCell.md +++ /dev/null @@ -1,928 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ExperimentalCell {#safeds.data.tabular.containers.ExperimentalCell data-toc-label='ExperimentalCell'} - -A single value in a table. - -This class cannot be instantiated directly. It is only used for arguments of callbacks. - -**Type parameters:** - -| Name | Upper Bound | Description | Default | -|------|-------------|-------------|---------| -| `T` | [`Any?`][safeds.lang.Any] | - | [`Any?`][safeds.lang.Any] | - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="9" - class ExperimentalCell { - /** - * Negate a boolean. This is equivalent to the `~` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.not_()) - * } - */ - @Pure - @PythonName("not_") - fun `not`() -> result: ExperimentalCell - - /** - * Perform a boolean AND operation. This is equivalent to the `&` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.and_(False)) - * } - */ - @Pure - @PythonName("and_") - fun `and`( - other: union> - ) -> result: ExperimentalCell - - /** - * Perform a boolean OR operation. This is equivalent to the `|` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.or_(True)) - * } - */ - @Pure - @PythonName("or_") - fun `or`( - other: union> - ) -> result: ExperimentalCell - - /** - * Perform a boolean XOR operation. This is equivalent to the `^` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.xor(True)) - * } - */ - @Pure - fun xor( - other: union> - ) -> result: ExperimentalCell - - /** - * Get the absolute value. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, -2]) - * // column.transform(lambda cell: cell.abs()) - * } - */ - @Pure - fun abs() -> result: ExperimentalCell - - /** - * Round up to the nearest integer. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1.1, 2.9]) - * // column.transform(lambda cell: cell.ceil()) - * } - */ - @Pure - fun ceil() -> result: ExperimentalCell - - /** - * Round down to the nearest integer. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1.1, 2.9]) - * // column.transform(lambda cell: cell.floor()) - * } - */ - @Pure - fun floor() -> result: ExperimentalCell - - /** - * Negate the value. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, -2]) - * // column.transform(lambda cell: cell.neg()) - * } - */ - @Pure - fun neg() -> result: ExperimentalCell - - /** - * Add a value. This is equivalent to the `+` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.add(3)) - * } - */ - @Pure - fun add( - other: Any - ) -> result: ExperimentalCell - - /** - * Perform a modulo operation. This is equivalent to the `%` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [5, 6]) - * // column.transform(lambda cell: cell.mod(3)) - * } - */ - @Pure - fun mod( - other: Any - ) -> result: ExperimentalCell - - /** - * Multiply by a value. This is equivalent to the `*` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [2, 3]) - * // column.transform(lambda cell: cell.mul(4)) - * } - */ - @Pure - fun mul( - other: Any - ) -> result: ExperimentalCell - - /** - * Raise to a power. This is equivalent to the `**` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [2, 3]) - * // column.transform(lambda cell: cell.pow(3)) - * } - */ - @Pure - fun pow( - other: union - ) -> result: ExperimentalCell - - /** - * Subtract a value. This is equivalent to the `-` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [5, 6]) - * // column.transform(lambda cell: cell.sub(3)) - * } - */ - @Pure - fun `sub`( - other: Any - ) -> result: ExperimentalCell - - /** - * Divide by a value. This is equivalent to the `/` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [6, 8]) - * // column.transform(lambda cell: cell.div(2)) - * } - */ - @Pure - fun div( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if equal to a value. This is equivalent to the `==` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.eq(2)) - * } - */ - @Pure - fun eq( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if greater than or equal to a value. This is equivalent to the `>=` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.ge(2)) - * } - */ - @Pure - fun ge( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if greater than a value. This is equivalent to the `>` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.gt(2)) - * } - */ - @Pure - fun gt( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if less than or equal to a value. This is equivalent to the `<=` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.le(2)) - * } - */ - @Pure - fun le( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if less than a value. This is equivalent to the `<` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.lt(2)) - * } - */ - @Pure - fun lt( - other: Any - ) -> result: ExperimentalCell - } - ``` - -## `#!sds fun` abs {#safeds.data.tabular.containers.ExperimentalCell.abs data-toc-label='abs'} - -Get the absolute value. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, -2]) - // column.transform(lambda cell: cell.abs()) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="81" - @Pure - fun abs() -> result: ExperimentalCell - ``` - -## `#!sds fun` add {#safeds.data.tabular.containers.ExperimentalCell.add data-toc-label='add'} - -Add a value. This is equivalent to the `+` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.add(3)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="133" - @Pure - fun add( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` and {#safeds.data.tabular.containers.ExperimentalCell.and data-toc-label='and'} - -Perform a boolean AND operation. This is equivalent to the `&` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | `#!sds union>` | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [True, False]) - // column.transform(lambda cell: cell.and_(False)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="34" - @Pure - @PythonName("and_") - fun `and`( - other: union> - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` ceil {#safeds.data.tabular.containers.ExperimentalCell.ceil data-toc-label='ceil'} - -Round up to the nearest integer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1.1, 2.9]) - // column.transform(lambda cell: cell.ceil()) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="94" - @Pure - fun ceil() -> result: ExperimentalCell - ``` - -## `#!sds fun` div {#safeds.data.tabular.containers.ExperimentalCell.div data-toc-label='div'} - -Divide by a value. This is equivalent to the `/` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [6, 8]) - // column.transform(lambda cell: cell.div(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="208" - @Pure - fun div( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` eq {#safeds.data.tabular.containers.ExperimentalCell.eq data-toc-label='eq'} - -Check if equal to a value. This is equivalent to the `==` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.eq(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="223" - @Pure - fun eq( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` floor {#safeds.data.tabular.containers.ExperimentalCell.floor data-toc-label='floor'} - -Round down to the nearest integer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1.1, 2.9]) - // column.transform(lambda cell: cell.floor()) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="107" - @Pure - fun floor() -> result: ExperimentalCell - ``` - -## `#!sds fun` ge {#safeds.data.tabular.containers.ExperimentalCell.ge data-toc-label='ge'} - -Check if greater than or equal to a value. This is equivalent to the `>=` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.ge(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="238" - @Pure - fun ge( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` gt {#safeds.data.tabular.containers.ExperimentalCell.gt data-toc-label='gt'} - -Check if greater than a value. This is equivalent to the `>` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.gt(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="253" - @Pure - fun gt( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` le {#safeds.data.tabular.containers.ExperimentalCell.le data-toc-label='le'} - -Check if less than or equal to a value. This is equivalent to the `<=` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.le(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="268" - @Pure - fun le( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` lt {#safeds.data.tabular.containers.ExperimentalCell.lt data-toc-label='lt'} - -Check if less than a value. This is equivalent to the `<` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, 2]) - // column.transform(lambda cell: cell.lt(2)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="283" - @Pure - fun lt( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` mod {#safeds.data.tabular.containers.ExperimentalCell.mod data-toc-label='mod'} - -Perform a modulo operation. This is equivalent to the `%` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [5, 6]) - // column.transform(lambda cell: cell.mod(3)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="148" - @Pure - fun mod( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` mul {#safeds.data.tabular.containers.ExperimentalCell.mul data-toc-label='mul'} - -Multiply by a value. This is equivalent to the `*` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [2, 3]) - // column.transform(lambda cell: cell.mul(4)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="163" - @Pure - fun mul( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` neg {#safeds.data.tabular.containers.ExperimentalCell.neg data-toc-label='neg'} - -Negate the value. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [1, -2]) - // column.transform(lambda cell: cell.neg()) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="120" - @Pure - fun neg() -> result: ExperimentalCell - ``` - -## `#!sds fun` not {#safeds.data.tabular.containers.ExperimentalCell.not data-toc-label='not'} - -Negate a boolean. This is equivalent to the `~` operator. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [True, False]) - // column.transform(lambda cell: cell.not_()) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("not_") - fun `not`() -> result: ExperimentalCell - ``` - -## `#!sds fun` or {#safeds.data.tabular.containers.ExperimentalCell.or data-toc-label='or'} - -Perform a boolean OR operation. This is equivalent to the `|` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | `#!sds union>` | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [True, False]) - // column.transform(lambda cell: cell.or_(True)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("or_") - fun `or`( - other: union> - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` pow {#safeds.data.tabular.containers.ExperimentalCell.pow data-toc-label='pow'} - -Raise to a power. This is equivalent to the `**` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | `#!sds union, Float>` | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [2, 3]) - // column.transform(lambda cell: cell.pow(3)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="178" - @Pure - fun pow( - other: union - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` sub {#safeds.data.tabular.containers.ExperimentalCell.sub data-toc-label='sub'} - -Subtract a value. This is equivalent to the `-` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`Any`][safeds.lang.Any] | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [5, 6]) - // column.transform(lambda cell: cell.sub(3)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="193" - @Pure - fun `sub`( - other: Any - ) -> result: ExperimentalCell - ``` - -## `#!sds fun` xor {#safeds.data.tabular.containers.ExperimentalCell.xor data-toc-label='xor'} - -Perform a boolean XOR operation. This is equivalent to the `^` operator. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | `#!sds union>` | - | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("example", [True, False]) - // column.transform(lambda cell: cell.xor(True)) -} -``` - -??? quote "Stub code in `ExperimentalCell.sdsstub`" - - ```sds linenums="66" - @Pure - fun xor( - other: union> - ) -> result: ExperimentalCell - ``` diff --git a/docs/api/safeds/data/tabular/containers/ExperimentalColumn.md b/docs/api/safeds/data/tabular/containers/ExperimentalColumn.md deleted file mode 100644 index f94fd0172..000000000 --- a/docs/api/safeds/data/tabular/containers/ExperimentalColumn.md +++ /dev/null @@ -1,1353 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalColumn {#safeds.data.tabular.containers.ExperimentalColumn data-toc-label='ExperimentalColumn'} - -A named, one-dimensional collection of homogeneous values. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | -| `data` | [`List?`][safeds.lang.List] | The data of the column. If None, an empty column is created. | `#!sds null` | - -**Type parameters:** - -| Name | Upper Bound | Description | Default | -|------|-------------|-------------|---------| -| `T` | [`Any?`][safeds.lang.Any] | - | - | - -**Examples:** - -```sds hl_lines="2 3" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // ExperimentalColumn("test", [1, 2, 3]) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="20" - class ExperimentalColumn( - name: String, - data: List? = null - ) { - /** - * Whether the column is numeric. - */ - @PythonName("is_numeric") attr isNumeric: Boolean - /** - * Whether the column is temporal. - */ - @PythonName("is_temporal") attr isTemporal: Boolean - /** - * The name of the column. - */ - attr name: String - /** - * The number of rows in the column. - */ - @PythonName("number_of_rows") attr numberOfRows: Int - /** - * The plotter for the column. - */ - attr plot: ExperimentalColumnPlotter - /** - * The type of the column. - */ - attr type: ExperimentalDataType - - /** - * Return the distinct values in the column. - * - * @result distinctValues The distinct values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3, 2]) - * // column.get_distinct_values() - * } - */ - @Pure - @PythonName("get_distinct_values") - fun getDistinctValues() -> distinctValues: List - - /** - * Return the column value at specified index. Indexing starts at 0. - * - * @param index Index of requested value. - * - * @result value Value at index. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.get_value(1) - * } - */ - @Pure - @PythonName("get_value") - fun getValue( - index: Int - ) -> value: T - - /** - * Return whether all values in the column satisfy the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result allSatisfyPredicate Whether all values in the column satisfy the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.all(lambda cell: cell > 0) - * } - */ - @Pure - fun all( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> allSatisfyPredicate: Boolean - - /** - * Return whether any value in the column satisfies the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result anySatisfyPredicate Whether any value in the column satisfies the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.any(lambda cell: cell > 2) - * } - */ - @Pure - fun any( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> anySatisfyPredicate: Boolean - - /** - * Return how many values in the column satisfy the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result count The number of values in the column that satisfy the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.count(lambda cell: cell > 1) - * } - */ - @Pure - fun count( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> count: Int - - /** - * Return whether no value in the column satisfies the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result noneSatisfyPredicate Whether no value in the column satisfies the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.none(lambda cell: cell < 0) - * } - */ - @Pure - fun none( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> noneSatisfyPredicate: Boolean - - /** - * Return a new column with a new name. - * - * The original column is not modified. - * - * @param newName The new name of the column. - * - * @result renamedColumn A new column with the new name. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.rename("new_name") - * } - */ - @Pure - fun rename( - @PythonName("new_name") newName: String - ) -> renamedColumn: ExperimentalColumn - - /** - * Return a new column with values transformed by the transformer. - * - * The original column is not modified. - * - * @param transformer The transformer to apply to each value. - * - * @result transformedColumn A new column with transformed values. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.transform(lambda cell: 2 * cell) - * } - */ - @Pure - fun transform( - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> transformedColumn: ExperimentalColumn - - /** - * Return a table with important statistics about the column. - * - * @result statistics The table with statistics. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("a", [1, 3]) - * // column.summarize_statistics() - * } - */ - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - - /** - * Calculate the Pearson correlation between this column and another column. - * - * The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly related: - * * A correlation of -1 indicates a perfect negative linear relationship. - * * A correlation of 0 indicates no linear relationship. - * * A correlation of 1 indicates a perfect positive linear relationship. - * - * @param other The other column to calculate the correlation with. - * - * @result correlation The Pearson correlation between the two columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column1 = ExperimentalColumn("test", [1, 2, 3]) - * // column2 = ExperimentalColumn("test", [2, 4, 6]) - * // column1.correlation_with(column2) - * } - */ - @Pure - @PythonName("correlation_with") - fun correlationWith( - other: ExperimentalColumn - ) -> correlation: Float - - /** - * Return the number of distinct values in the column. - * - * @result distinctValueCount The number of distinct values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3, 2]) - * // column.distinct_value_count() - * } - */ - @Pure - @PythonName("distinct_value_count") - fun distinctValueCount() -> distinctValueCount: Int - - /** - * Calculate the idness of this column. - * - * We define the idness as the number of distinct values divided by the number of rows. If the column is empty, - * the idness is 1.0. - * - * A high idness indicates that the column most values in the column are unique. In this case, you must be careful - * when using the column for analysis, as a model may learn a mapping from this column to the target. - * - * @result idness The idness of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column1 = ExperimentalColumn("test", [1, 2, 3]) - * // column1.idness() - * } - */ - @Pure - fun idness() -> idness: Float - - /** - * Return the maximum value in the column. - * - * @result max The maximum value in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.max() - * } - */ - @Pure - fun max() -> max: T - - /** - * Return the mean of the values in the column. - * - * The mean is the sum of the values divided by the number of values. - * - * @result mean The mean of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.mean() - * } - */ - @Pure - fun mean() -> mean: T - - /** - * Return the median of the values in the column. - * - * The median is the value in the middle of the sorted list of values. If the number of values is even, the median - * is the mean of the two middle values. - * - * @result median The median of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.median() - * } - */ - @Pure - fun median() -> median: T - - /** - * Return the minimum value in the column. - * - * @result min The minimum value in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.min() - * } - */ - @Pure - fun min() -> min: T - - /** - * Return the number of missing values in the column. - * - * @result missingValueCount The number of missing values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, None, 3]) - * // column.missing_value_count() - * } - */ - @Pure - @PythonName("missing_value_count") - fun missingValueCount() -> missingValueCount: Int - - /** - * Return the missing value ratio. - * - * We define the missing value ratio as the number of missing values in the column divided by the number of rows. - * If the column is empty, the missing value ratio is 1.0. - * - * A high missing value ratio indicates that the column is dominated by missing values. In this case, the column - * may not be useful for analysis. - * - * @result missingValueRatio The ratio of missing values in the column. - */ - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missingValueRatio: Float - - /** - * Return the mode of the values in the column. - * - * The mode is the value that appears most frequently in the column. If multiple values occur equally often, all - * of them are returned. The values are sorted in ascending order. - * - * @result mode The mode of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [3, 1, 2, 1, 3]) - * // column.mode() - * } - */ - @Pure - fun mode() -> mode: ExperimentalColumn - - /** - * Return the stability of the column. - * - * We define the stability as the number of occurrences of the most common non-missing value divided by the total - * number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. - * - * A high stability indicates that the column is dominated by a single value. In this case, the column may not be - * useful for analysis. - * - * @result stability The stability of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 1, 2, 3, None]) - * // column.stability() - * } - */ - @Pure - fun stability() -> stability: Float - - /** - * Return the standard deviation of the values in the column. - * - * The standard deviation is the square root of the variance. - * - * @result standardDeviation The standard deviation of the values in the column. If no standard deviation can be calculated due to the - * type of the column, None is returned. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.standard_deviation() - * } - */ - @Pure - @PythonName("standard_deviation") - fun standardDeviation() -> standardDeviation: Float? - - /** - * Return the variance of the values in the column. - * - * The variance is the average of the squared differences from the mean. - * - * @result variance The variance of the values in the column. If no variance can be calculated due to the type of the column, - * None is returned. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.variance() - * } - */ - @Pure - fun variance() -> variance: Float? - - /** - * Return the values of the column in a list. - * - * @result values The values of the column in a list. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.to_list() - * } - */ - @Pure - @PythonName("to_list") - fun toList() -> values: List - - /** - * Create a table that contains only this column. - * - * @result table The table with this column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.to_table() - * } - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable - - /** - * Convert the column to the old column format. This method is temporary and will be removed in a later version. - * - * @result oldColumn The column in the old format. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("a", [1, 2, 3]) - * // old_column = column.temporary_to_old_column() - * } - */ - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_column") - fun temporaryToOldColumn() -> oldColumn: Column - } - ``` - -## `#!sds attr` isNumeric {#safeds.data.tabular.containers.ExperimentalColumn.isNumeric data-toc-label='isNumeric'} - -Whether the column is numeric. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` isTemporal {#safeds.data.tabular.containers.ExperimentalColumn.isTemporal data-toc-label='isTemporal'} - -Whether the column is temporal. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` name {#safeds.data.tabular.containers.ExperimentalColumn.name data-toc-label='name'} - -The name of the column. - -**Type:** [`String`][safeds.lang.String] - -## `#!sds attr` numberOfRows {#safeds.data.tabular.containers.ExperimentalColumn.numberOfRows data-toc-label='numberOfRows'} - -The number of rows in the column. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` plot {#safeds.data.tabular.containers.ExperimentalColumn.plot data-toc-label='plot'} - -The plotter for the column. - -**Type:** [`ExperimentalColumnPlotter`][safeds.data.tabular.plotting.ExperimentalColumnPlotter] - -## `#!sds attr` type {#safeds.data.tabular.containers.ExperimentalColumn.type data-toc-label='type'} - -The type of the column. - -**Type:** [`ExperimentalDataType`][safeds.data.tabular.typing.ExperimentalDataType] - -## `#!sds fun` all {#safeds.data.tabular.containers.ExperimentalColumn.all data-toc-label='all'} - -Return whether all values in the column satisfy the predicate. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The predicate to apply to each value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `allSatisfyPredicate` | [`Boolean`][safeds.lang.Boolean] | Whether all values in the column satisfy the predicate. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.all(lambda cell: cell > 0) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="99" - @Pure - fun all( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> allSatisfyPredicate: Boolean - ``` - -## `#!sds fun` any {#safeds.data.tabular.containers.ExperimentalColumn.any data-toc-label='any'} - -Return whether any value in the column satisfies the predicate. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The predicate to apply to each value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `anySatisfyPredicate` | [`Boolean`][safeds.lang.Boolean] | Whether any value in the column satisfies the predicate. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.any(lambda cell: cell > 2) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="118" - @Pure - fun any( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> anySatisfyPredicate: Boolean - ``` - -## `#!sds fun` correlationWith {#safeds.data.tabular.containers.ExperimentalColumn.correlationWith data-toc-label='correlationWith'} - -Calculate the Pearson correlation between this column and another column. - -The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly related: -* A correlation of -1 indicates a perfect negative linear relationship. -* A correlation of 0 indicates no linear relationship. -* A correlation of 1 indicates a perfect positive linear relationship. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | The other column to calculate the correlation with. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `correlation` | [`Float`][safeds.lang.Float] | The Pearson correlation between the two columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column1 = ExperimentalColumn("test", [1, 2, 3]) - // column2 = ExperimentalColumn("test", [2, 4, 6]) - // column1.correlation_with(column2) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="239" - @Pure - @PythonName("correlation_with") - fun correlationWith( - other: ExperimentalColumn - ) -> correlation: Float - ``` - -## `#!sds fun` count {#safeds.data.tabular.containers.ExperimentalColumn.count data-toc-label='count'} - -Return how many values in the column satisfy the predicate. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The predicate to apply to each value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `count` | [`Int`][safeds.lang.Int] | The number of values in the column that satisfy the predicate. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.count(lambda cell: cell > 1) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="137" - @Pure - fun count( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> count: Int - ``` - -## `#!sds fun` distinctValueCount {#safeds.data.tabular.containers.ExperimentalColumn.distinctValueCount data-toc-label='distinctValueCount'} - -Return the number of distinct values in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `distinctValueCount` | [`Int`][safeds.lang.Int] | The number of distinct values in the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3, 2]) - // column.distinct_value_count() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="257" - @Pure - @PythonName("distinct_value_count") - fun distinctValueCount() -> distinctValueCount: Int - ``` - -## `#!sds fun` getDistinctValues {#safeds.data.tabular.containers.ExperimentalColumn.getDistinctValues data-toc-label='getDistinctValues'} - -Return the distinct values in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `distinctValues` | [`List`][safeds.lang.List] | The distinct values in the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3, 2]) - // column.get_distinct_values() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="61" - @Pure - @PythonName("get_distinct_values") - fun getDistinctValues() -> distinctValues: List - ``` - -## `#!sds fun` getValue {#safeds.data.tabular.containers.ExperimentalColumn.getValue data-toc-label='getValue'} - -Return the column value at specified index. Indexing starts at 0. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `index` | [`Int`][safeds.lang.Int] | Index of requested value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `value` | `#!sds T` | Value at index. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.get_value(1) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="79" - @Pure - @PythonName("get_value") - fun getValue( - index: Int - ) -> value: T - ``` - -## `#!sds fun` idness {#safeds.data.tabular.containers.ExperimentalColumn.idness data-toc-label='idness'} - -Calculate the idness of this column. - -We define the idness as the number of distinct values divided by the number of rows. If the column is empty, -the idness is 1.0. - -A high idness indicates that the column most values in the column are unique. In this case, you must be careful -when using the column for analysis, as a model may learn a mapping from this column to the target. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `idness` | [`Float`][safeds.lang.Float] | The idness of the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column1 = ExperimentalColumn("test", [1, 2, 3]) - // column1.idness() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="279" - @Pure - fun idness() -> idness: Float - ``` - -## `#!sds fun` max {#safeds.data.tabular.containers.ExperimentalColumn.max data-toc-label='max'} - -Return the maximum value in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `max` | `#!sds T` | The maximum value in the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.max() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="294" - @Pure - fun max() -> max: T - ``` - -## `#!sds fun` mean {#safeds.data.tabular.containers.ExperimentalColumn.mean data-toc-label='mean'} - -Return the mean of the values in the column. - -The mean is the sum of the values divided by the number of values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `mean` | `#!sds T` | The mean of the values in the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.mean() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="311" - @Pure - fun mean() -> mean: T - ``` - -## `#!sds fun` median {#safeds.data.tabular.containers.ExperimentalColumn.median data-toc-label='median'} - -Return the median of the values in the column. - -The median is the value in the middle of the sorted list of values. If the number of values is even, the median -is the mean of the two middle values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `median` | `#!sds T` | The median of the values in the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.median() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="329" - @Pure - fun median() -> median: T - ``` - -## `#!sds fun` min {#safeds.data.tabular.containers.ExperimentalColumn.min data-toc-label='min'} - -Return the minimum value in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `min` | `#!sds T` | The minimum value in the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.min() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="344" - @Pure - fun min() -> min: T - ``` - -## `#!sds fun` missingValueCount {#safeds.data.tabular.containers.ExperimentalColumn.missingValueCount data-toc-label='missingValueCount'} - -Return the number of missing values in the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `missingValueCount` | [`Int`][safeds.lang.Int] | The number of missing values in the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, None, 3]) - // column.missing_value_count() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="359" - @Pure - @PythonName("missing_value_count") - fun missingValueCount() -> missingValueCount: Int - ``` - -## `#!sds fun` missingValueRatio {#safeds.data.tabular.containers.ExperimentalColumn.missingValueRatio data-toc-label='missingValueRatio'} - -Return the missing value ratio. - -We define the missing value ratio as the number of missing values in the column divided by the number of rows. -If the column is empty, the missing value ratio is 1.0. - -A high missing value ratio indicates that the column is dominated by missing values. In this case, the column -may not be useful for analysis. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `missingValueRatio` | [`Float`][safeds.lang.Float] | The ratio of missing values in the column. | - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="374" - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missingValueRatio: Float - ``` - -## `#!sds fun` mode {#safeds.data.tabular.containers.ExperimentalColumn.mode data-toc-label='mode'} - -Return the mode of the values in the column. - -The mode is the value that appears most frequently in the column. If multiple values occur equally often, all -of them are returned. The values are sorted in ascending order. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `mode` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | The mode of the values in the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [3, 1, 2, 1, 3]) - // column.mode() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="393" - @Pure - fun mode() -> mode: ExperimentalColumn - ``` - -## `#!sds fun` none {#safeds.data.tabular.containers.ExperimentalColumn.none data-toc-label='none'} - -Return whether no value in the column satisfies the predicate. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `predicate` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The predicate to apply to each value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `noneSatisfyPredicate` | [`Boolean`][safeds.lang.Boolean] | Whether no value in the column satisfies the predicate. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.none(lambda cell: cell < 0) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="156" - @Pure - fun none( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> noneSatisfyPredicate: Boolean - ``` - -## `#!sds fun` rename {#safeds.data.tabular.containers.ExperimentalColumn.rename data-toc-label='rename'} - -Return a new column with a new name. - -The original column is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `newName` | [`String`][safeds.lang.String] | The new name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `renamedColumn` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | A new column with the new name. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.rename("new_name") -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="177" - @Pure - fun rename( - @PythonName("new_name") newName: String - ) -> renamedColumn: ExperimentalColumn - ``` - -## `#!sds fun` stability {#safeds.data.tabular.containers.ExperimentalColumn.stability data-toc-label='stability'} - -Return the stability of the column. - -We define the stability as the number of occurrences of the most common non-missing value divided by the total -number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. - -A high stability indicates that the column is dominated by a single value. In this case, the column may not be -useful for analysis. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `stability` | [`Float`][safeds.lang.Float] | The stability of the column. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 1, 2, 3, None]) - // column.stability() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="414" - @Pure - fun stability() -> stability: Float - ``` - -## `#!sds fun` standardDeviation {#safeds.data.tabular.containers.ExperimentalColumn.standardDeviation data-toc-label='standardDeviation'} - -Return the standard deviation of the values in the column. - -The standard deviation is the square root of the variance. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `standardDeviation` | [`Float?`][safeds.lang.Float] | The standard deviation of the values in the column. If no standard deviation can be calculated due to the type of the column, None is returned. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.standard_deviation() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="432" - @Pure - @PythonName("standard_deviation") - fun standardDeviation() -> standardDeviation: Float? - ``` - -## `#!sds fun` summarizeStatistics {#safeds.data.tabular.containers.ExperimentalColumn.summarizeStatistics data-toc-label='summarizeStatistics'} - -Return a table with important statistics about the column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `statistics` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with statistics. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("a", [1, 3]) - // column.summarize_statistics() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="215" - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` temporaryToOldColumn {#safeds.data.tabular.containers.ExperimentalColumn.temporaryToOldColumn data-toc-label='temporaryToOldColumn'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** Only a temporary solution until this implementation is stable. - -Convert the column to the old column format. This method is temporary and will be removed in a later version. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `oldColumn` | [`Column`][safeds.data.tabular.containers.Column] | The column in the old format. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("a", [1, 2, 3]) - // old_column = column.temporary_to_old_column() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="498" - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_column") - fun temporaryToOldColumn() -> oldColumn: Column - ``` - -## `#!sds fun` toList {#safeds.data.tabular.containers.ExperimentalColumn.toList data-toc-label='toList'} - -Return the values of the column in a list. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `values` | [`List`][safeds.lang.List] | The values of the column in a list. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.to_list() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="466" - @Pure - @PythonName("to_list") - fun toList() -> values: List - ``` - -## `#!sds fun` toTable {#safeds.data.tabular.containers.ExperimentalColumn.toTable data-toc-label='toTable'} - -Create a table that contains only this column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with this column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.to_table() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="482" - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.containers.ExperimentalColumn.transform data-toc-label='transform'} - -Return a new column with values transformed by the transformer. - -The original column is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformer` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The transformer to apply to each value. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedColumn` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | A new column with transformed values. | - -**Type parameters:** - -| Name | Upper Bound | Description | Default | -|------|-------------|-------------|---------| -| `R` | [`Any?`][safeds.lang.Any] | - | - | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.transform(lambda cell: 2 * cell) -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="198" - @Pure - fun transform( - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> transformedColumn: ExperimentalColumn - ``` - -## `#!sds fun` variance {#safeds.data.tabular.containers.ExperimentalColumn.variance data-toc-label='variance'} - -Return the variance of the values in the column. - -The variance is the average of the squared differences from the mean. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `variance` | [`Float?`][safeds.lang.Float] | The variance of the values in the column. If no variance can be calculated due to the type of the column, None is returned. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // column.variance() -} -``` - -??? quote "Stub code in `ExperimentalColumn.sdsstub`" - - ```sds linenums="451" - @Pure - fun variance() -> variance: Float? - ``` diff --git a/docs/api/safeds/data/tabular/containers/ExperimentalRow.md b/docs/api/safeds/data/tabular/containers/ExperimentalRow.md deleted file mode 100644 index ed85c4b47..000000000 --- a/docs/api/safeds/data/tabular/containers/ExperimentalRow.md +++ /dev/null @@ -1,164 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ExperimentalRow {#safeds.data.tabular.containers.ExperimentalRow data-toc-label='ExperimentalRow'} - -A one-dimensional collection of named, heterogeneous values. - -This class cannot be instantiated directly. It is only used for arguments of callbacks. - -??? quote "Stub code in `ExperimentalRow.sdsstub`" - - ```sds linenums="12" - class ExperimentalRow { - /** - * The names of the columns in the row. - */ - @PythonName("column_names") attr columnNames: List - /** - * The number of columns in the row. - */ - @PythonName("number_of_columns") attr numberOfColumns: Int - /** - * The schema of the row. - */ - attr `schema`: ExperimentalSchema - - /** - * Get the value of the specified column. - * - * @param name The name of the column. - * - * @result value The value of the column. - */ - @Pure - @PythonName("get_value") - fun getValue( - name: String - ) -> value: ExperimentalCell - - /** - * Get the type of the specified column. - * - * @param name The name of the column. - * - * @result type The type of the column. - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Check if the row has a column with the specified name. - * - * @param name The name of the column. - * - * @result hasColumn Whether the row has a column with the specified name. - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean - } - ``` - -## `#!sds attr` columnNames {#safeds.data.tabular.containers.ExperimentalRow.columnNames data-toc-label='columnNames'} - -The names of the columns in the row. - -**Type:** [`List`][safeds.lang.List] - -## `#!sds attr` numberOfColumns {#safeds.data.tabular.containers.ExperimentalRow.numberOfColumns data-toc-label='numberOfColumns'} - -The number of columns in the row. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` schema {#safeds.data.tabular.containers.ExperimentalRow.schema data-toc-label='schema'} - -The schema of the row. - -**Type:** [`ExperimentalSchema`][safeds.data.tabular.typing.ExperimentalSchema] - -## `#!sds fun` getColumnType {#safeds.data.tabular.containers.ExperimentalRow.getColumnType data-toc-label='getColumnType'} - -Get the type of the specified column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `type` | [`ExperimentalDataType`][safeds.data.tabular.typing.ExperimentalDataType] | The type of the column. | - -??? quote "Stub code in `ExperimentalRow.sdsstub`" - - ```sds linenums="46" - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - ``` - -## `#!sds fun` getValue {#safeds.data.tabular.containers.ExperimentalRow.getValue data-toc-label='getValue'} - -Get the value of the specified column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `value` | [`ExperimentalCell`][safeds.data.tabular.containers.ExperimentalCell] | The value of the column. | - -??? quote "Stub code in `ExperimentalRow.sdsstub`" - - ```sds linenums="33" - @Pure - @PythonName("get_value") - fun getValue( - name: String - ) -> value: ExperimentalCell - ``` - -## `#!sds fun` hasColumn {#safeds.data.tabular.containers.ExperimentalRow.hasColumn data-toc-label='hasColumn'} - -Check if the row has a column with the specified name. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | Whether the row has a column with the specified name. | - -??? quote "Stub code in `ExperimentalRow.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean - ``` diff --git a/docs/api/safeds/data/tabular/containers/ExperimentalTable.md b/docs/api/safeds/data/tabular/containers/ExperimentalTable.md deleted file mode 100644 index 86102820f..000000000 --- a/docs/api/safeds/data/tabular/containers/ExperimentalTable.md +++ /dev/null @@ -1,2457 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalTable {#safeds.data.tabular.containers.ExperimentalTable data-toc-label='ExperimentalTable'} - -A two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. - -To create a `Table` call the constructor or use one of the following static methods: - -| Method | Description | -| ------------------------------------------------------------------------------------| -------------------------------------- | -| [fromCsvFile][safeds.data.tabular.containers.ExperimentalTable.fromCsvFile] | Create a table from a CSV file. | -| [fromJsonFile][safeds.data.tabular.containers.ExperimentalTable.fromJsonFile] | Create a table from a JSON file. | -| [fromParquetFile][safeds.data.tabular.containers.ExperimentalTable.fromParquetFile] | Create a table from a Parquet file. | -| [fromColumns][safeds.data.tabular.containers.ExperimentalTable.fromColumns] | Create a table from a list of columns. | -| [fromMap][safeds.data.tabular.containers.ExperimentalTable.fromMap] | Create a table from a dictionary. | - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `data` | [`Map>?`][safeds.lang.Map] | The data of the table. If None, an empty table is created. | `#!sds null` | - -**Examples:** - -```sds hl_lines="2 3" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="34" - class ExperimentalTable( - data: Map>? = null - ) { - /** - * The names of the columns in the table. - */ - @PythonName("column_names") attr columnNames: List - /** - * The number of columns in the table. - */ - @PythonName("number_of_columns") attr numberOfColumns: Int - /** - * The number of rows in the table. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - */ - @PythonName("number_of_rows") attr numberOfRows: Int - /** - * The plotter for the table. - */ - attr plot: ExperimentalTablePlotter - /** - * The schema of the table. - */ - attr `schema`: ExperimentalSchema - - /** - * Create a table from a list of columns. - * - * @param columns The columns. - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // a = ExperimentalColumn("a", [1, 2, 3]) - * // b = ExperimentalColumn("b", [4, 5, 6]) - * // ExperimentalTable.from_columns([a, b]) - * } - */ - @Pure - @PythonName("from_columns") - static fun fromColumns( - columns: union, List>> - ) -> table: ExperimentalTable - - /** - * Create a table from a CSV file. - * - * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_csv_file("./src/resources/from_csv_file.csv") - * } - */ - @Pure - @PythonName("from_csv_file") - static fun fromCsvFile( - path: String - ) -> table: ExperimentalTable - - /** - * Create a table from a map of column names to column values. - * - * @param data The data. - * - * @result table The generated table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // data = {'a': [1, 2, 3], 'b': [4, 5, 6]} - * // ExperimentalTable.from_dict(data) - * } - */ - @Pure - @PythonName("from_dict") - static fun fromMap( - data: Map> - ) -> table: ExperimentalTable - - /** - * Create a table from a JSON file. - * - * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_json_file("./src/resources/from_json_file_2.json") - * } - */ - @Pure - @PythonName("from_json_file") - static fun fromJsonFile( - path: String - ) -> table: ExperimentalTable - - /** - * Create a table from a Parquet file. - * - * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_parquet_file("./src/resources/from_parquet_file.parquet") - * } - */ - @Pure - @PythonName("from_parquet_file") - static fun fromParquetFile( - path: String - ) -> table: ExperimentalTable - - /** - * Return a new table with additional columns. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param columns The columns to add. - * - * @result newTable The table with the additional columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // new_column = ExperimentalColumn("b", [4, 5, 6]) - * // table.add_columns(new_column) - * } - */ - @Pure - @PythonName("add_columns") - fun addColumns( - columns: union, List>> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with an additional computed column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the new column. - * @param computer The function that computes the values of the new column. - * - * @result newTable The table with the computed column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.add_computed_column("c", lambda row: row.get_value("a") + row.get_value("b")) - * } - */ - @Pure - @PythonName("add_computed_column") - fun addComputedColumn( - name: String, - computer: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Get a column from the table. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - * - * @param name The name of the column. - * - * @result column The column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.get_column("a") - * } - */ - @Pure - @PythonName("get_column") - fun getColumn( - name: String - ) -> column: ExperimentalColumn - - /** - * Get the data type of a column. - * - * @param name The name of the column. - * - * @result type The data type of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.get_column_type("a") - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Check if the table has a column with a specific name. - * - * @param name The name of the column. - * - * @result hasColumn Whether the table has a column with the specified name. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.has_column("a") - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean - - /** - * Return a new table without the specified columns. - * - * **Note:** The original table is not modified. - * - * @param names The names of the columns to remove. - * - * @result newTable The table with the columns removed. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_columns("a") - * } - */ - @Pure - @PythonName("remove_columns") - fun removeColumns( - names: union, String> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with only the specified columns. - * - * @param names The names of the columns to keep. - * - * @result newTable The table with only the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_columns_except("a") - * } - */ - @Pure - @PythonName("remove_columns_except") - fun removeColumnsExcept( - names: union, String> - ) -> newTable: ExperimentalTable - - /** - * Return a new table without columns that contain missing values. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @result newTable The table without columns containing missing values. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, None]}) - * // table.remove_columns_with_missing_values() - * } - */ - @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> newTable: ExperimentalTable - - /** - * Return a new table without non-numeric columns. - * - * **Note:** The original table is not modified. - * - * @result newTable The table without non-numeric columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": ["4", "5", "6"]}) - * // table.remove_non_numeric_columns() - * } - */ - @Pure - @PythonName("remove_non_numeric_columns") - fun removeNonNumericColumns() -> newTable: ExperimentalTable - - /** - * Return a new table with a column renamed. - * - * **Note:** The original table is not modified. - * - * @param oldName The name of the column to rename. - * @param newName The new name of the column. - * - * @result newTable The table with the column renamed. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.rename_column("a", "c") - * } - */ - @Pure - @PythonName("rename_column") - fun renameColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_name") newName: String - ) -> newTable: ExperimentalTable - - /** - * Return a new table with a column replaced by zero or more columns. - * - * **Note:** The original table is not modified. - * - * @param oldName The name of the column to replace. - * @param newColumns The new column or columns. - * - * @result newTable The table with the column replaced. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.replace_column("a", []) - * } - */ - @Pure - @PythonName("replace_column") - fun replaceColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_columns") newColumns: union, List>> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with a column transformed. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column to transform. - * @param transformer The function that transforms the column. - * - * @result newTable The table with the transformed column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.transform_column("a", lambda cell: cell + 1) - * } - */ - @Pure - @PythonName("transform_column") - fun transformColumn( - name: String, - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without duplicate rows. - * - * **Note:** The original table is not modified. - * - * @result newTable The table without duplicate rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 2], "b": [4, 5, 5]}) - * // table.remove_duplicate_rows() - * } - */ - @Pure - @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> newTable: ExperimentalTable - - /** - * Return a new table without rows that satisfy a condition. - * - * **Note:** The original table is not modified. - * - * @param query The function that determines which rows to remove. - * - * @result newTable The table without the specified rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_rows(lambda row: row.get_value("a") == 2) - * } - */ - @Pure - @PythonName("remove_rows") - fun removeRows( - query: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows that satisfy a condition on a specific column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column. - * @param query The function that determines which rows to remove. - * - * @result newTable The table without the specified rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_rows_by_column("a", lambda cell: cell == 2) - * } - */ - @Pure - @PythonName("remove_rows_by_column") - fun removeRowsByColumn( - name: String, - query: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows containing missing values in the specified columns. - * - * **Note:** The original table is not modified. - * - * @param columnNames Names of the columns to consider. If None, all columns are considered. - * - * @result newTable The table without rows containing missing values in the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, None, 3], "b": [4, 5, None]}) - * // table.remove_rows_with_missing_values() - * } - */ - @Pure - @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues( - @PythonName("column_names") columnNames: List? = null - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows containing outliers in the specified columns. - * - * Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the - * data point from the mean of the column divided by the standard deviation of the column. If the z-score is - * greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the - * calculation of the z-score. - * - * The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in - * `column_names`. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param columnNames Names of the columns to consider. If None, all numeric columns are considered. - * @param zScoreThreshold The z-score threshold for detecting outliers. - * - * @result newTable The table without rows containing outliers in the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5, 6, 1000, None], - * // "b": [1, 2, 3, 4, 5, 6, 7, 8], - * // } - * // ) - * // table.remove_rows_with_outliers(z_score_threshold=2) - * } - */ - @Pure - @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers( - @PythonName("column_names") columnNames: List? = null, - @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows shuffled. - * - * **Note:** The original table is not modified. - * - * @result newTable The table with the rows shuffled. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.shuffle_rows() - * } - */ - @Pure - @PythonName("shuffle_rows") - fun shuffleRows() -> newTable: ExperimentalTable - - /** - * Return a new table with a slice of rows. - * - * **Note:** The original table is not modified. - * - * @param start The start index of the slice. - * @param length The length of the slice. If None, the slice contains all rows starting from `start`. - * - * @result newTable The table with the slice of rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.slice_rows(start=1) - * } - */ - @Pure - @PythonName("slice_rows") - fun sliceRows( - start: Int = 0, - length: Int? = null - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows sorted. - * - * **Note:** The original table is not modified. - * - * @param keySelector The function that selects the key to sort by. - * @param descending Whether to sort in descending order. - * - * @result newTable The table with the rows sorted. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - * // table.sort_rows(lambda row: row.get_value("a") - row.get_value("b")) - * } - */ - @Pure - @PythonName("sort_rows") - fun sortRows( - @PythonName("key_selector") keySelector: (param1: ExperimentalRow) -> result1: ExperimentalCell, - descending: Boolean = false - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows sorted by a specific column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column to sort by. - * @param descending Whether to sort in descending order. - * - * @result newTable The table with the rows sorted by the specified column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - * // table.sort_rows_by_column("a") - * } - */ - @Pure - @PythonName("sort_rows_by_column") - fun sortRowsByColumn( - name: String, - descending: Boolean = false - ) -> newTable: ExperimentalTable - - /** - * Create two tables by splitting the rows of the current table. - * - * The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table - * contains the remaining rows. - * - * **Note:** The original table is not modified. - * - * @param percentageInFirst The percentage of rows to include in the first table. Must be between 0 and 1. - * @param shuffle Whether to shuffle the rows before splitting. - * - * @result firstTable The first table. - * @result secondTable The second table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}) - * // first_table, second_table = table.split_rows(0.6) - * // first_table - * // second_table - * } - */ - @Pure - @PythonName("split_rows") - fun splitRows( - @PythonName("percentage_in_first") percentageInFirst: Float, - shuffle: Boolean = true - ) -> (firstTable: ExperimentalTable, secondTable: ExperimentalTable) - - /** - * Return a new table with the columns of another table added. - * - * **Notes:** - * - * * The original tables are not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param other The table to add as columns. - * - * @result newTable The table with the columns added. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table1 = ExperimentalTable({"a": [1, 2, 3]}) - * // table2 = ExperimentalTable({"b": [4, 5, 6]}) - * // table1.add_table_as_columns(table2) - * } - */ - @Pure - @PythonName("add_table_as_columns") - fun addTableAsColumns( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows of another table added. - * - * **Notes:** - * - * * The original tables are not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param other The table to add as rows. - * - * @result newTable The table with the rows added. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table1 = ExperimentalTable({"a": [1, 2, 3]}) - * // table2 = ExperimentalTable({"a": [4, 5, 6]}) - * // table1.add_table_as_rows(table2) - * } - */ - @Pure - @PythonName("add_table_as_rows") - fun addTableAsRows( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - - /** - * Return a new table inverse-transformed by a **fitted, invertible** transformer. - * - * **Notes:** - * - * * The original table is not modified. - * * Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - * - * @param fittedTransformer The fitted, invertible transformer to apply. - * - * @result newTable The inverse-transformed table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // from safeds.data.tabular.transformation import ExperimentalRangeScaler - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // transformer, transformed_table = ExperimentalRangeScaler(min_=0, max_=1).fit_and_transform(table, ["a"]) - * // transformed_table.inverse_transform_table(transformer) - * } - */ - @Pure - @PythonName("inverse_transform_table") - fun inverseTransformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalInvertibleTableTransformer - ) -> newTable: ExperimentalTable - - /** - * Return a new table transformed by a **fitted** transformer. - * - * **Notes:** - * - * * The original table is not modified. - * * Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - * - * @param fittedTransformer The fitted transformer to apply. - * - * @result newTable The transformed table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // from safeds.data.tabular.transformation import ExperimentalRangeScaler - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // transformer = ExperimentalRangeScaler(min_=0, max_=1).fit(table, ["a"]) - * // table.transform_table(transformer) - * } - */ - @Pure - @PythonName("transform_table") - fun transformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalTableTransformer - ) -> newTable: ExperimentalTable - - /** - * Return a table with important statistics about this table. - * - * @result statistics The table with statistics. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 3]}) - * // table.summarize_statistics() - * } - */ - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - - /** - * Return the data of the table as a list of columns. - * - * @result columns List of columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // columns = table.to_columns() - * } - */ - @Pure - @PythonName("to_columns") - fun toColumns() -> columns: List> - - /** - * Write the table to a CSV file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_csv_file("./src/resources/to_csv_file.csv") - * } - */ - @Pure - @PythonName("to_csv_file") - fun toCsvFile( - path: String - ) - - /** - * Return a map of column names to column values. - * - * @result map Dictionary representation of the table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_dict() - * } - */ - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - - /** - * Write the table to a JSON file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - * - * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". - * @param orientation The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If - * "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but - * slower and less memory-efficient. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_json_file("./src/resources/to_json_file_2.json") - * } - */ - @Pure - @PythonName("to_json_file") - fun toJsonFile( - path: String, - orientation: literal<"column", "row"> = "column" - ) - - /** - * Write the table to a Parquet file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_parquet_file("./src/resources/to_parquet_file.parquet") - * } - */ - @Pure - @PythonName("to_parquet_file") - fun toParquetFile( - path: String - ) - - /** - * Return a new `TabularDataset` with columns marked as a target, feature, or extra. - * - * * The target column is the column that a model should predict. - * * Feature columns are columns that a model should use to make predictions. - * * Extra columns are columns that are neither feature nor target. They can be used to provide additional context, - * like an ID column. - * - * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns - * are specified, all columns except the target column are used as features. - * - * @param targetName Name of the target column. - * @param extraNames Names of the columns that are neither feature nor target. If None, no extra columns are used, i.e. all but - * the target column are used as features. - * - * @result dataset A new tabular dataset with the given target and feature names. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "item": ["apple", "milk", "beer"], - * // "price": [1.10, 1.19, 1.79], - * // "amount_bought": [74, 72, 51], - * // } - * // ) - * // dataset = table.to_tabular_dataset(target_name="amount_bought", extra_names=["item"]) - * } - */ - @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( - @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List? = null - ) -> dataset: ExperimentalTabularDataset - - /** - * Convert the table to the old table format. This method is temporary and will be removed in a later version. - * - * @result oldTable The table in the old format. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // old_table = table.temporary_to_old_table() - * } - */ - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_table") - fun temporaryToOldTable() -> oldTable: Table - } - ``` - -## `#!sds attr` columnNames {#safeds.data.tabular.containers.ExperimentalTable.columnNames data-toc-label='columnNames'} - -The names of the columns in the table. - -**Type:** [`List`][safeds.lang.List] - -## `#!sds attr` numberOfColumns {#safeds.data.tabular.containers.ExperimentalTable.numberOfColumns data-toc-label='numberOfColumns'} - -The number of columns in the table. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` numberOfRows {#safeds.data.tabular.containers.ExperimentalTable.numberOfRows data-toc-label='numberOfRows'} - -The number of rows in the table. - -**Note:** This operation must fully load the data into memory, which can be expensive. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` plot {#safeds.data.tabular.containers.ExperimentalTable.plot data-toc-label='plot'} - -The plotter for the table. - -**Type:** [`ExperimentalTablePlotter`][safeds.data.tabular.plotting.ExperimentalTablePlotter] - -## `#!sds attr` schema {#safeds.data.tabular.containers.ExperimentalTable.schema data-toc-label='schema'} - -The schema of the table. - -**Type:** [`ExperimentalSchema`][safeds.data.tabular.typing.ExperimentalSchema] - -## `#!sds fun` addColumns {#safeds.data.tabular.containers.ExperimentalTable.addColumns data-toc-label='addColumns'} - -Return a new table with additional columns. - -**Notes:** - -* The original table is not modified. -* This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columns` | `#!sds union, List>>` | The columns to add. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the additional columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3]}) - // new_column = ExperimentalColumn("b", [4, 5, 6]) - // table.add_columns(new_column) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="178" - @Pure - @PythonName("add_columns") - fun addColumns( - columns: union, List>> - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` addComputedColumn {#safeds.data.tabular.containers.ExperimentalTable.addComputedColumn data-toc-label='addComputedColumn'} - -Return a new table with an additional computed column. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the new column. | - | -| `computer` | `#!sds (param1: ExperimentalRow) -> (result1: ExperimentalCell)` | The function that computes the values of the new column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the computed column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.add_computed_column("c", lambda row: row.get_value("a") + row.get_value("b")) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="201" - @Pure - @PythonName("add_computed_column") - fun addComputedColumn( - name: String, - computer: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` addTableAsColumns {#safeds.data.tabular.containers.ExperimentalTable.addTableAsColumns data-toc-label='addTableAsColumns'} - -Return a new table with the columns of another table added. - -**Notes:** - -* The original tables are not modified. -* This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to add as columns. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the columns added. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table1 = ExperimentalTable({"a": [1, 2, 3]}) - // table2 = ExperimentalTable({"b": [4, 5, 6]}) - // table1.add_table_as_columns(table2) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="689" - @Pure - @PythonName("add_table_as_columns") - fun addTableAsColumns( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` addTableAsRows {#safeds.data.tabular.containers.ExperimentalTable.addTableAsRows data-toc-label='addTableAsRows'} - -Return a new table with the rows of another table added. - -**Notes:** - -* The original tables are not modified. -* This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `other` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to add as rows. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the rows added. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table1 = ExperimentalTable({"a": [1, 2, 3]}) - // table2 = ExperimentalTable({"a": [4, 5, 6]}) - // table1.add_table_as_rows(table2) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="715" - @Pure - @PythonName("add_table_as_rows") - fun addTableAsRows( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` getColumn {#safeds.data.tabular.containers.ExperimentalTable.getColumn data-toc-label='getColumn'} - -Get a column from the table. - -**Note:** This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `column` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | The column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.get_column("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="224" - @Pure - @PythonName("get_column") - fun getColumn( - name: String - ) -> column: ExperimentalColumn - ``` - -## `#!sds fun` getColumnType {#safeds.data.tabular.containers.ExperimentalTable.getColumnType data-toc-label='getColumnType'} - -Get the data type of a column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `type` | [`ExperimentalDataType`][safeds.data.tabular.typing.ExperimentalDataType] | The data type of the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.get_column_type("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="244" - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - ``` - -## `#!sds fun` hasColumn {#safeds.data.tabular.containers.ExperimentalTable.hasColumn data-toc-label='hasColumn'} - -Check if the table has a column with a specific name. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | Whether the table has a column with the specified name. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.has_column("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="264" - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean - ``` - -## `#!sds fun` inverseTransformTable {#safeds.data.tabular.containers.ExperimentalTable.inverseTransformTable data-toc-label='inverseTransformTable'} - -Return a new table inverse-transformed by a **fitted, invertible** transformer. - -**Notes:** - -* The original table is not modified. -* Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `fittedTransformer` | [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] | The fitted, invertible transformer to apply. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The inverse-transformed table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // from safeds.data.tabular.transformation import ExperimentalRangeScaler - // table = ExperimentalTable({"a": [1, 2, 3]}) - // transformer, transformed_table = ExperimentalRangeScaler(min_=0, max_=1).fit_and_transform(table, ["a"]) - // transformed_table.inverse_transform_table(transformer) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="742" - @Pure - @PythonName("inverse_transform_table") - fun inverseTransformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalInvertibleTableTransformer - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeColumns {#safeds.data.tabular.containers.ExperimentalTable.removeColumns data-toc-label='removeColumns'} - -Return a new table without the specified columns. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `names` | `#!sds union, String>` | The names of the columns to remove. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the columns removed. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.remove_columns("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="286" - @Pure - @PythonName("remove_columns") - fun removeColumns( - names: union, String> - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeColumnsExcept {#safeds.data.tabular.containers.ExperimentalTable.removeColumnsExcept data-toc-label='removeColumnsExcept'} - -Return a new table with only the specified columns. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `names` | `#!sds union, String>` | The names of the columns to keep. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with only the specified columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.remove_columns_except("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="306" - @Pure - @PythonName("remove_columns_except") - fun removeColumnsExcept( - names: union, String> - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeColumnsWithMissingValues {#safeds.data.tabular.containers.ExperimentalTable.removeColumnsWithMissingValues data-toc-label='removeColumnsWithMissingValues'} - -Return a new table without columns that contain missing values. - -**Notes:** - -* The original table is not modified. -* This operation must fully load the data into memory, which can be expensive. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without columns containing missing values. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, None]}) - // table.remove_columns_with_missing_values() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="329" - @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeDuplicateRows {#safeds.data.tabular.containers.ExperimentalTable.removeDuplicateRows data-toc-label='removeDuplicateRows'} - -Return a new table without duplicate rows. - -**Note:** The original table is not modified. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without duplicate rows. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 2], "b": [4, 5, 5]}) - // table.remove_duplicate_rows() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="437" - @Pure - @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeNonNumericColumns {#safeds.data.tabular.containers.ExperimentalTable.removeNonNumericColumns data-toc-label='removeNonNumericColumns'} - -Return a new table without non-numeric columns. - -**Note:** The original table is not modified. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without non-numeric columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": ["4", "5", "6"]}) - // table.remove_non_numeric_columns() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="347" - @Pure - @PythonName("remove_non_numeric_columns") - fun removeNonNumericColumns() -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeRows {#safeds.data.tabular.containers.ExperimentalTable.removeRows data-toc-label='removeRows'} - -Return a new table without rows that satisfy a condition. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `query` | `#!sds (param1: ExperimentalRow) -> (result1: ExperimentalCell)` | The function that determines which rows to remove. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without the specified rows. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.remove_rows(lambda row: row.get_value("a") == 2) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="457" - @Pure - @PythonName("remove_rows") - fun removeRows( - query: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeRowsByColumn {#safeds.data.tabular.containers.ExperimentalTable.removeRowsByColumn data-toc-label='removeRowsByColumn'} - -Return a new table without rows that satisfy a condition on a specific column. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | -| `query` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The function that determines which rows to remove. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without the specified rows. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.remove_rows_by_column("a", lambda cell: cell == 2) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="480" - @Pure - @PythonName("remove_rows_by_column") - fun removeRowsByColumn( - name: String, - query: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeRowsWithMissingValues {#safeds.data.tabular.containers.ExperimentalTable.removeRowsWithMissingValues data-toc-label='removeRowsWithMissingValues'} - -Return a new table without rows containing missing values in the specified columns. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columnNames` | [`List?`][safeds.lang.List] | Names of the columns to consider. If None, all columns are considered. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without rows containing missing values in the specified columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, None, 3], "b": [4, 5, None]}) - // table.remove_rows_with_missing_values() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="503" - @Pure - @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues( - @PythonName("column_names") columnNames: List? = null - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` removeRowsWithOutliers {#safeds.data.tabular.containers.ExperimentalTable.removeRowsWithOutliers data-toc-label='removeRowsWithOutliers'} - -Return a new table without rows containing outliers in the specified columns. - -Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the -data point from the mean of the column divided by the standard deviation of the column. If the z-score is -greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the -calculation of the z-score. - -The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in -`column_names`. - -**Notes:** - -* The original table is not modified. -* This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columnNames` | [`List?`][safeds.lang.List] | Names of the columns to consider. If None, all numeric columns are considered. | `#!sds null` | -| `zScoreThreshold` | [`Float`][safeds.lang.Float] | The z-score threshold for detecting outliers. | `#!sds 3.0` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table without rows containing outliers in the specified columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable( - // { - // "a": [1, 2, 3, 4, 5, 6, 1000, None], - // "b": [1, 2, 3, 4, 5, 6, 7, 8], - // } - // ) - // table.remove_rows_with_outliers(z_score_threshold=2) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="542" - @Pure - @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers( - @PythonName("column_names") columnNames: List? = null, - @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` renameColumn {#safeds.data.tabular.containers.ExperimentalTable.renameColumn data-toc-label='renameColumn'} - -Return a new table with a column renamed. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `oldName` | [`String`][safeds.lang.String] | The name of the column to rename. | - | -| `newName` | [`String`][safeds.lang.String] | The new name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the column renamed. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.rename_column("a", "c") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="368" - @Pure - @PythonName("rename_column") - fun renameColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_name") newName: String - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` replaceColumn {#safeds.data.tabular.containers.ExperimentalTable.replaceColumn data-toc-label='replaceColumn'} - -Return a new table with a column replaced by zero or more columns. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `oldName` | [`String`][safeds.lang.String] | The name of the column to replace. | - | -| `newColumns` | `#!sds union, List>>` | The new column or columns. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the column replaced. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.replace_column("a", []) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="392" - @Pure - @PythonName("replace_column") - fun replaceColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_columns") newColumns: union, List>> - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` shuffleRows {#safeds.data.tabular.containers.ExperimentalTable.shuffleRows data-toc-label='shuffleRows'} - -Return a new table with the rows shuffled. - -**Note:** The original table is not modified. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the rows shuffled. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.shuffle_rows() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="563" - @Pure - @PythonName("shuffle_rows") - fun shuffleRows() -> newTable: ExperimentalTable - ``` - -## `#!sds fun` sliceRows {#safeds.data.tabular.containers.ExperimentalTable.sliceRows data-toc-label='sliceRows'} - -Return a new table with a slice of rows. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `start` | [`Int`][safeds.lang.Int] | The start index of the slice. | `#!sds 0` | -| `length` | [`Int?`][safeds.lang.Int] | The length of the slice. If None, the slice contains all rows starting from `start`. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the slice of rows. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.slice_rows(start=1) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="584" - @Pure - @PythonName("slice_rows") - fun sliceRows( - start: Int = 0, - length: Int? = null - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` sortRows {#safeds.data.tabular.containers.ExperimentalTable.sortRows data-toc-label='sortRows'} - -Return a new table with the rows sorted. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `keySelector` | `#!sds (param1: ExperimentalRow) -> (result1: ExperimentalCell)` | The function that selects the key to sort by. | - | -| `descending` | [`Boolean`][safeds.lang.Boolean] | Whether to sort in descending order. | `#!sds false` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the rows sorted. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - // table.sort_rows(lambda row: row.get_value("a") - row.get_value("b")) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="608" - @Pure - @PythonName("sort_rows") - fun sortRows( - @PythonName("key_selector") keySelector: (param1: ExperimentalRow) -> result1: ExperimentalCell, - descending: Boolean = false - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` sortRowsByColumn {#safeds.data.tabular.containers.ExperimentalTable.sortRowsByColumn data-toc-label='sortRowsByColumn'} - -Return a new table with the rows sorted by a specific column. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column to sort by. | - | -| `descending` | [`Boolean`][safeds.lang.Boolean] | Whether to sort in descending order. | `#!sds false` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the rows sorted by the specified column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - // table.sort_rows_by_column("a") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="632" - @Pure - @PythonName("sort_rows_by_column") - fun sortRowsByColumn( - name: String, - descending: Boolean = false - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` splitRows {#safeds.data.tabular.containers.ExperimentalTable.splitRows data-toc-label='splitRows'} - -Create two tables by splitting the rows of the current table. - -The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table -contains the remaining rows. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `percentageInFirst` | [`Float`][safeds.lang.Float] | The percentage of rows to include in the first table. Must be between 0 and 1. | - | -| `shuffle` | [`Boolean`][safeds.lang.Boolean] | Whether to shuffle the rows before splitting. | `#!sds true` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `firstTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The first table. | -| `secondTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The second table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}) - // first_table, second_table = table.split_rows(0.6) - // first_table - // second_table -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="662" - @Pure - @PythonName("split_rows") - fun splitRows( - @PythonName("percentage_in_first") percentageInFirst: Float, - shuffle: Boolean = true - ) -> (firstTable: ExperimentalTable, secondTable: ExperimentalTable) - ``` - -## `#!sds fun` summarizeStatistics {#safeds.data.tabular.containers.ExperimentalTable.summarizeStatistics data-toc-label='summarizeStatistics'} - -Return a table with important statistics about this table. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `statistics` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with statistics. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 3]}) - // table.summarize_statistics() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="787" - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` temporaryToOldTable {#safeds.data.tabular.containers.ExperimentalTable.temporaryToOldTable data-toc-label='temporaryToOldTable'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** Only a temporary solution until this implementation is stable. - -Convert the table to the old table format. This method is temporary and will be removed in a later version. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `oldTable` | [`Table`][safeds.data.tabular.containers.Table] | The table in the old format. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // old_table = table.temporary_to_old_table() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="941" - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_table") - fun temporaryToOldTable() -> oldTable: Table - ``` - -## `#!sds fun` toColumns {#safeds.data.tabular.containers.ExperimentalTable.toColumns data-toc-label='toColumns'} - -Return the data of the table as a list of columns. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `columns` | [`List>`][safeds.lang.List] | List of columns. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // columns = table.to_columns() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="803" - @Pure - @PythonName("to_columns") - fun toColumns() -> columns: List> - ``` - -## `#!sds fun` toCsvFile {#safeds.data.tabular.containers.ExperimentalTable.toCsvFile data-toc-label='toCsvFile'} - -Write the table to a CSV file. - -If the file and/or the parent directories do not exist, they will be created. If the file exists already, it -will be overwritten. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.to_csv_file("./src/resources/to_csv_file.csv") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="822" - @Pure - @PythonName("to_csv_file") - fun toCsvFile( - path: String - ) - ``` - -## `#!sds fun` toJsonFile {#safeds.data.tabular.containers.ExperimentalTable.toJsonFile data-toc-label='toJsonFile'} - -Write the table to a JSON file. - -If the file and/or the parent directories do not exist, they will be created. If the file exists already, it -will be overwritten. - -**Note:** This operation must fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". | - | -| `orientation` | `#!sds literal<"column", "row">` | The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but slower and less memory-efficient. | `#!sds "column"` | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.to_json_file("./src/resources/to_json_file_2.json") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="864" - @Pure - @PythonName("to_json_file") - fun toJsonFile( - path: String, - orientation: literal<"column", "row"> = "column" - ) - ``` - -## `#!sds fun` toMap {#safeds.data.tabular.containers.ExperimentalTable.toMap data-toc-label='toMap'} - -Return a map of column names to column values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `map` | [`Map>`][safeds.lang.Map] | Dictionary representation of the table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.to_dict() -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="840" - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - ``` - -## `#!sds fun` toParquetFile {#safeds.data.tabular.containers.ExperimentalTable.toParquetFile data-toc-label='toParquetFile'} - -Write the table to a Parquet file. - -If the file and/or the parent directories do not exist, they will be created. If the file exists already, it -will be overwritten. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.to_parquet_file("./src/resources/to_parquet_file.parquet") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="886" - @Pure - @PythonName("to_parquet_file") - fun toParquetFile( - path: String - ) - ``` - -## `#!sds fun` toTabularDataset {#safeds.data.tabular.containers.ExperimentalTable.toTabularDataset data-toc-label='toTabularDataset'} - -Return a new `TabularDataset` with columns marked as a target, feature, or extra. - -* The target column is the column that a model should predict. -* Feature columns are columns that a model should use to make predictions. -* Extra columns are columns that are neither feature nor target. They can be used to provide additional context, - like an ID column. - -Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns -are specified, all columns except the target column are used as features. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | -| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither feature nor target. If None, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `dataset` | [`ExperimentalTabularDataset`][safeds.data.labeled.containers.ExperimentalTabularDataset] | A new tabular dataset with the given target and feature names. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable( - // { - // "item": ["apple", "milk", "beer"], - // "price": [1.10, 1.19, 1.79], - // "amount_bought": [74, 72, 51], - // } - // ) - // dataset = table.to_tabular_dataset(target_name="amount_bought", extra_names=["item"]) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="922" - @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( - @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List? = null - ) -> dataset: ExperimentalTabularDataset - ``` - -## `#!sds fun` transformColumn {#safeds.data.tabular.containers.ExperimentalTable.transformColumn data-toc-label='transformColumn'} - -Return a new table with a column transformed. - -**Note:** The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column to transform. | - | -| `transformer` | `#!sds (param1: ExperimentalCell) -> (result1: ExperimentalCell)` | The function that transforms the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table with the transformed column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - // table.transform_column("a", lambda cell: cell + 1) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="416" - @Pure - @PythonName("transform_column") - fun transformColumn( - name: String, - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - ``` - -## `#!sds fun` transformTable {#safeds.data.tabular.containers.ExperimentalTable.transformTable data-toc-label='transformTable'} - -Return a new table transformed by a **fitted** transformer. - -**Notes:** - -* The original table is not modified. -* Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `fittedTransformer` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | The fitted transformer to apply. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // from safeds.data.tabular.transformation import ExperimentalRangeScaler - // table = ExperimentalTable({"a": [1, 2, 3]}) - // transformer = ExperimentalRangeScaler(min_=0, max_=1).fit(table, ["a"]) - // table.transform_table(transformer) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="769" - @Pure - @PythonName("transform_table") - fun transformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalTableTransformer - ) -> newTable: ExperimentalTable - ``` - -## `#!sds static fun` fromColumns {#safeds.data.tabular.containers.ExperimentalTable.fromColumns data-toc-label='fromColumns'} - -Create a table from a list of columns. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columns` | `#!sds union, List>>` | The columns. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The created table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - // a = ExperimentalColumn("a", [1, 2, 3]) - // b = ExperimentalColumn("b", [4, 5, 6]) - // ExperimentalTable.from_columns([a, b]) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="75" - @Pure - @PythonName("from_columns") - static fun fromColumns( - columns: union, List>> - ) -> table: ExperimentalTable - ``` - -## `#!sds static fun` fromCsvFile {#safeds.data.tabular.containers.ExperimentalTable.fromCsvFile data-toc-label='fromCsvFile'} - -Create a table from a CSV file. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The created table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // ExperimentalTable.from_csv_file("./src/resources/from_csv_file.csv") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="94" - @Pure - @PythonName("from_csv_file") - static fun fromCsvFile( - path: String - ) -> table: ExperimentalTable - ``` - -## `#!sds static fun` fromJsonFile {#safeds.data.tabular.containers.ExperimentalTable.fromJsonFile data-toc-label='fromJsonFile'} - -Create a table from a JSON file. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The created table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // ExperimentalTable.from_json_file("./src/resources/from_json_file_2.json") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="133" - @Pure - @PythonName("from_json_file") - static fun fromJsonFile( - path: String - ) -> table: ExperimentalTable - ``` - -## `#!sds static fun` fromMap {#safeds.data.tabular.containers.ExperimentalTable.fromMap data-toc-label='fromMap'} - -Create a table from a map of column names to column values. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `data` | [`Map>`][safeds.lang.Map] | The data. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The generated table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // data = {'a': [1, 2, 3], 'b': [4, 5, 6]} - // ExperimentalTable.from_dict(data) -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="114" - @Pure - @PythonName("from_dict") - static fun fromMap( - data: Map> - ) -> table: ExperimentalTable - ``` - -## `#!sds static fun` fromParquetFile {#safeds.data.tabular.containers.ExperimentalTable.fromParquetFile data-toc-label='fromParquetFile'} - -Create a table from a Parquet file. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The created table. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // ExperimentalTable.from_parquet_file("./src/resources/from_parquet_file.parquet") -} -``` - -??? quote "Stub code in `ExperimentalTable.sdsstub`" - - ```sds linenums="152" - @Pure - @PythonName("from_parquet_file") - static fun fromParquetFile( - path: String - ) -> table: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/containers/Row.md b/docs/api/safeds/data/tabular/containers/Row.md index 4add3463d..429571c87 100644 --- a/docs/api/safeds/data/tabular/containers/Row.md +++ b/docs/api/safeds/data/tabular/containers/Row.md @@ -1,494 +1,164 @@ -# :warning:{ title="Deprecated" } `#!sds class` Row {#safeds.data.tabular.containers.Row data-toc-label='Row'} +--- +search: + boost: 0.5 +--- -!!! warning "Deprecated" +# `#!sds abstract class` Row {#safeds.data.tabular.containers.Row data-toc-label='Row'} - This class is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +A one-dimensional collection of named, heterogeneous values. - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. - -A row is a collection of named values. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `data` | [`Map?`][safeds.lang.Map] | The data. If None, an empty row is created. | `#!sds null` | - -**Examples:** - -```sds hl_lines="2" -pipeline example { - val row = Row({"a": 1, "b": 2}); -} -``` +This class cannot be instantiated directly. It is only used for arguments of callbacks. ??? quote "Stub code in `Row.sdsstub`" - ```sds linenums="21" - class Row( - data: Map? = null // TODO: update default value to empty map - ) { + ```sds linenums="11" + class Row { /** - * Return a list of all column names in the row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val columnNames = row.columnNames; // ["a", "b"] - * } + * The names of the columns in the row. */ @PythonName("column_names") attr columnNames: List /** - * Return the number of columns in this row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val numberOfColumns = row.numberOfColumns; // 2 - * } + * The number of columns in the row. */ - @PythonName("number_of_columns") attr numberOfColumns: Int + @PythonName("number_of_columns") attr columnCount: Int /** - * Return the schema of the row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val `schema` = row.`schema`; - * } + * The schema of the row. */ - attr `schema`: Schema + attr ^schema: Schema /** - * Create a row from a dictionary that maps column names to column values. - * - * @param data The data. + * Get the value of the specified column. * - * @result row The created row. + * @param name The name of the column. * - * @example - * pipeline example { - * val row = Row.fromDict({"a": 1, "b": 2}); - * } - */ - @Pure - @PythonName("from_dict") - static fun fromDict( - data: Map - ) -> row: Row - - /** - * Return the value of a specified column. - * - * @param columnName The column name. - * - * @result value The column value. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val value = row.getValue("a"); // 1 - * } + * @result value The value of the column. */ @Pure @PythonName("get_value") fun getValue( - @PythonName("column_name") columnName: String - ) -> value: Any + name: String + ) -> value: Cell /** - * Check whether the row contains a given column. - * - * @param columnName The column name. + * Get the type of the specified column. * - * @result hasColumn True, if the row contains the column, False otherwise. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val hasColumn = row.hasColumn("a"); // True - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> hasColumn: Boolean - - /** - * Return the type of the specified column. - * - * @param columnName The column name. + * @param name The name of the column. * * @result type The type of the column. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val type = row.getColumnType("a"); // Integer - * } */ @Pure @PythonName("get_column_type") fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType - - /** - * Sort the columns of a `Row` with the given comparator and return a new `Row`. - * - * The original row is not modified. The comparator is a function with four parameters: - * - * * `name_1` is the name of the first column. - * * `value_1` is the value of the first column. - * * `name_2` is the name of the second column. - * * `value_2` is the value of the second column. - * - * It should return an integer, indicating the desired order of the columns: - * - * * If `col1` should be ordered before `col2`, the function should return a negative number. - * * If `col1` should be ordered after `col2`, the function should return a positive number. - * * If the original order of `col1` and `col2` should be kept, the function should return 0. - * - * If no comparator is given, the columns will be sorted alphabetically by their name. - * - * @param comparator The function used to compare two tuples of (ColumnName, Value). - * - * @result sortedRow A new row with sorted columns. - * - * @example - * pipeline example { - * val row = Row({"b": 2, "a": 1}); - * val sortedRow = row.sortColumns((name1, value1, name2, value2) -> - * value1 as (Int) - value2 as (Int) - * ); - * } - */ - @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (name1: String, value1: Any, name2: String, value2: Any) -> comparison: Int - ) -> sortedRow: Row - - /** - * Return a map of column names to column values. - * - * @result map Map representation of the row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val map = row.toMap(); // {"a": 1, "b": 2} - * } - */ - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map + name: String + ) -> type: DataType /** - * Return an HTML representation of the row. + * Check if the row has a column with the specified name. * - * @result html The generated HTML. + * @param name The name of the column. * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val html = row.toHtml(); - * } + * @result hasColumn Whether the row has a column with the specified name. */ @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("has_column") + fun hasColumn( + name: String + ) -> hasColumn: Boolean } ``` -## `#!sds attr` columnNames {#safeds.data.tabular.containers.Row.columnNames data-toc-label='columnNames'} +## `#!sds attr` columnCount {#safeds.data.tabular.containers.Row.columnCount data-toc-label='columnCount'} -Return a list of all column names in the row. - -**Type:** [`List`][safeds.lang.List] - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val columnNames = row.columnNames; // ["a", "b"] -} -``` - -## `#!sds attr` numberOfColumns {#safeds.data.tabular.containers.Row.numberOfColumns data-toc-label='numberOfColumns'} - -Return the number of columns in this row. +The number of columns in the row. **Type:** [`Int`][safeds.lang.Int] -**Examples:** +## `#!sds attr` columnNames {#safeds.data.tabular.containers.Row.columnNames data-toc-label='columnNames'} + +The names of the columns in the row. -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val numberOfColumns = row.numberOfColumns; // 2 -} -``` +**Type:** [`List`][safeds.lang.List] ## `#!sds attr` schema {#safeds.data.tabular.containers.Row.schema data-toc-label='schema'} -Return the schema of the row. +The schema of the row. **Type:** [`Schema`][safeds.data.tabular.typing.Schema] -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val `schema` = row.`schema`; -} -``` - ## `#!sds fun` getColumnType {#safeds.data.tabular.containers.Row.getColumnType data-toc-label='getColumnType'} -Return the type of the specified column. +Get the type of the specified column. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The column name. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `type` | [`ColumnType`][safeds.data.tabular.typing.ColumnType] | The type of the column. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val type = row.getColumnType("a"); // Integer -} -``` +| `type` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the column. | ??? quote "Stub code in `Row.sdsstub`" - ```sds linenums="124" + ```sds linenums="45" @Pure @PythonName("get_column_type") fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType + name: String + ) -> type: DataType ``` ## `#!sds fun` getValue {#safeds.data.tabular.containers.Row.getValue data-toc-label='getValue'} -Return the value of a specified column. +Get the value of the specified column. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The column name. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `value` | [`Any`][safeds.lang.Any] | The column value. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val value = row.getValue("a"); // 1 -} -``` +| `value` | [`Cell`][safeds.data.tabular.containers.Cell] | The value of the column. | ??? quote "Stub code in `Row.sdsstub`" - ```sds linenums="86" + ```sds linenums="32" @Pure @PythonName("get_value") fun getValue( - @PythonName("column_name") columnName: String - ) -> value: Any + name: String + ) -> value: Cell ``` ## `#!sds fun` hasColumn {#safeds.data.tabular.containers.Row.hasColumn data-toc-label='hasColumn'} -Check whether the row contains a given column. +Check if the row has a column with the specified name. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The column name. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | True, if the row contains the column, False otherwise. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val hasColumn = row.hasColumn("a"); // True -} -``` +| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | Whether the row has a column with the specified name. | ??? quote "Stub code in `Row.sdsstub`" - ```sds linenums="105" + ```sds linenums="58" @Pure @PythonName("has_column") fun hasColumn( - @PythonName("column_name") columnName: String + name: String ) -> hasColumn: Boolean ``` - -## `#!sds fun` sortColumns {#safeds.data.tabular.containers.Row.sortColumns data-toc-label='sortColumns'} - -Sort the columns of a `Row` with the given comparator and return a new `Row`. - -The original row is not modified. The comparator is a function with four parameters: - -* `name_1` is the name of the first column. -* `value_1` is the value of the first column. -* `name_2` is the name of the second column. -* `value_2` is the value of the second column. - -It should return an integer, indicating the desired order of the columns: - -* If `col1` should be ordered before `col2`, the function should return a negative number. -* If `col1` should be ordered after `col2`, the function should return a positive number. -* If the original order of `col1` and `col2` should be kept, the function should return 0. - -If no comparator is given, the columns will be sorted alphabetically by their name. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `comparator` | `#!sds (name1: String, value1: Any, name2: String, value2: Any) -> (comparison: Int)` | The function used to compare two tuples of (ColumnName, Value). | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `sortedRow` | [`Row`][safeds.data.tabular.containers.Row] | A new row with sorted columns. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"b": 2, "a": 1}); - val sortedRow = row.sortColumns((name1, value1, name2, value2) -> - value1 as (Int) - value2 as (Int) - ); -} -``` - -??? quote "Stub code in `Row.sdsstub`" - - ```sds linenums="160" - @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (name1: String, value1: Any, name2: String, value2: Any) -> comparison: Int - ) -> sortedRow: Row - ``` - -## `#!sds fun` toHtml {#safeds.data.tabular.containers.Row.toHtml data-toc-label='toHtml'} - -Return an HTML representation of the row. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `html` | [`String`][safeds.lang.String] | The generated HTML. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val html = row.toHtml(); -} -``` - -??? quote "Stub code in `Row.sdsstub`" - - ```sds linenums="192" - @Pure - @PythonName("to_html") - fun toHtml() -> html: String - ``` - -## `#!sds fun` toMap {#safeds.data.tabular.containers.Row.toMap data-toc-label='toMap'} - -Return a map of column names to column values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `map` | [`Map`][safeds.lang.Map] | Map representation of the row. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val row = Row({"a": 1, "b": 2}); - val map = row.toMap(); // {"a": 1, "b": 2} -} -``` - -??? quote "Stub code in `Row.sdsstub`" - - ```sds linenums="177" - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map - ``` - -## `#!sds static fun` fromDict {#safeds.data.tabular.containers.Row.fromDict data-toc-label='fromDict'} - -Create a row from a dictionary that maps column names to column values. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `data` | [`Map`][safeds.lang.Map] | The data. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `row` | [`Row`][safeds.data.tabular.containers.Row] | The created row. | - -**Examples:** - -```sds hl_lines="2" -pipeline example { - val row = Row.fromDict({"a": 1, "b": 2}); -} -``` - -??? quote "Stub code in `Row.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("from_dict") - static fun fromDict( - data: Map - ) -> row: Row - ``` diff --git a/docs/api/safeds/data/tabular/containers/Table.md b/docs/api/safeds/data/tabular/containers/Table.md index 726638832..a2d60956d 100644 --- a/docs/api/safeds/data/tabular/containers/Table.md +++ b/docs/api/safeds/data/tabular/containers/Table.md @@ -1,144 +1,102 @@ # `#!sds class` Table {#safeds.data.tabular.containers.Table data-toc-label='Table'} -A table is a two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. +A two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. To create a `Table` call the constructor or use one of the following static methods: -| Method | Description | -| -------------------------- | -------------------------------------- | -| [Table.fromCsvFile][safeds.data.tabular.containers.Table.fromCsvFile] | Create a table from a CSV file. | -| [Table.fromJsonFile][safeds.data.tabular.containers.Table.fromJsonFile] | Create a table from a JSON file. | -| [Table.fromMap][safeds.data.tabular.containers.Table.fromMap] | Create a table from a map. | -| [Table.fromColumns][safeds.data.tabular.containers.Table.fromColumns] | Create a table from a list of columns. | -| [Table.fromRows][safeds.data.tabular.containers.Table.fromRows] | Create a table from a list of rows. | - -Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. +| Method | Description | +| ----------------------------------------------------------------------- | -------------------------------------- | +| [fromCsvFile][safeds.data.tabular.containers.Table.fromCsvFile] | Create a table from a CSV file. | +| [fromJsonFile][safeds.data.tabular.containers.Table.fromJsonFile] | Create a table from a JSON file. | +| [fromParquetFile][safeds.data.tabular.containers.Table.fromParquetFile] | Create a table from a Parquet file. | +| [fromColumns][safeds.data.tabular.containers.Table.fromColumns] | Create a table from a list of columns. | +| [fromMap][safeds.data.tabular.containers.Table.fromMap] | Create a table from a map. | **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `data` | [`Map>?`][safeds.lang.Map] | The data. If None, an empty table is created. | `#!sds null` | +| `data` | [`Map>?`][safeds.lang.Map] | The data of the table. If null, an empty table is created. | `#!sds null` | **Examples:** ```sds hl_lines="2" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="31" + ```sds linenums="32" class Table( - data: Map>? = null // TODO: update default value to empty map + data: Map>? = null ) { /** - * Return a list of all column names in this table. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val columnNames = table.columnNames; // ["a", "b"] - * } + * The names of the columns in the table. */ @PythonName("column_names") attr columnNames: List /** - * Return the number of columns. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val numberOfColumns = table.numberOfColumns; // 2 - * } + * The number of columns in the table. */ - @PythonName("number_of_columns") attr numberOfColumns: Int + @PythonName("number_of_columns") attr columnCount: Int /** - * Return the number of rows. + * The number of rows in the table. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val numberOfRows = table.numberOfRows; // 2 - * } + * **Note:** This operation must fully load the data into memory, which can be expensive. */ - @PythonName("number_of_rows") attr numberOfRows: Int + @PythonName("number_of_rows") attr rowCount: Int /** - * Return the schema of the table. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val `schema` = table.`schema`; - * } + * The plotter for the table. */ - attr `schema`: Schema - + attr plot: TablePlotter /** - * Read data from a CSV file into a table. - * - * @param path The path to the CSV file. - * - * @result table The table created from the CSV file. - * - * @example - * pipeline example { - * val table = Table.fromCsvFile("path/to/file.csv"); - * } + * The schema of the table. */ - @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_csv_file") - static fun fromCsvFile( - path: String - ) -> table: Table + attr ^schema: Schema /** - * Read data from an Excel file into a table. - * - * Valid file extensions are `.xls`, `.xlsx`, `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. + * Create a table from a list of columns. * - * @param path The path to the Excel file. + * @param columns The columns. * - * @result table The table created from the Excel file. + * @result table The created table. * * @example * pipeline example { - * val table = Table.fromExcelFile("path/to/file.xlsx"); + * val a = Column("a", [1, 2, 3]); + * val b = Column("b", [4, 5, 6]); + * val result = Table.fromColumns([a, b]); * } */ - @Deprecated( - alternative="Table.fromCsvFile", - reason="Requires a heavy depencency just for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_excel_file") - static fun fromExcelFile( - path: String + @Pure + @PythonName("from_columns") + static fun fromColumns( + columns: union> ) -> table: Table /** - * Read data from a JSON file into a table. + * Create a table from a CSV file. * - * @param path The path to the JSON file. + * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". + * @param separator The separator between the values in the CSV file. * - * @result table The table created from the JSON file. + * @result table The created table. * * @example * pipeline example { - * val table = Table.fromJsonFile("path/to/file.json"); + * val result = Table.fromCsvFile("input.csv"); * } */ @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_json_file") - static fun fromJsonFile( - path: String + @PythonName("from_csv_file") + static fun fromCsvFile( + path: String, + separator: String = "," ) -> table: Table /** - * Create a table from a map of column names to column values. + * Create a table from a map that maps column names to column values. * * @param data The data. * @@ -146,964 +104,724 @@ pipeline example { * * @example * pipeline example { - * val table = Table.fromMap({"a": [1, 2], "b": [3, 4]}); + * val data = {"a'": [1, 2, 3], "b": [4, 5, 6]}; + * val result = Table.fromMap(data); * } */ @Pure @PythonName("from_dict") static fun fromMap( - data: Map> + data: Map> ) -> table: Table /** - * Return a table created from a list of columns. + * Create a table from a JSON file. * - * @param columns The columns to be combined. They need to have the same size. + * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". * - * @result table The generated table. + * @result table The created table. * * @example * pipeline example { - * val column1 = Column("a", [1, 2]); - * val column2 = Column("b", [3, 4]); - * val table = Table.fromColumns([column1, column2]); + * val result = Table.fromJsonFile("input.json"); * } */ - @Pure - @PythonName("from_columns") - static fun fromColumns( - columns: List + @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) + @PythonName("from_json_file") + static fun fromJsonFile( + path: String ) -> table: Table /** - * Return a table created from a list of rows. + * Create a table from a Parquet file. * - * @param rows The rows to be combined. They need to have a matching schema. + * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". * - * @result table The generated table. + * @result table The created table. * * @example * pipeline example { - * val row1 = Row({"a": 1, "b": 3}); - * val row2 = Row({"a": 2, "b": 4}); - * val table = Table.fromRows([row1, row2]); + * val result = Table.fromParquetFile("input.parquet"); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("from_rows") - static fun fromRows( - rows: List + @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) + @PythonName("from_parquet_file") + static fun fromParquetFile( + path: String ) -> table: Table /** - * Return a column with the data of the specified column. + * Return a new table with additional columns. * - * @param columnName The name of the column. - * - * @result column The column. + * **Notes:** * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = table.getColumn("a"); // Column("a", [1, 2]) - * } - */ - @Pure - @PythonName("get_column") - fun getColumn( - @PythonName("column_name") columnName: String - ) -> column: Column - - /** - * Return whether the table contains a given column. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @param columnName The name of the column. + * @param columns The columns to add. * - * @result hasColumn True if the column exists. + * @result newTable The table with the additional columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val hasColumn = table.hasColumn("a"); // true + * val table = Table({"a": [1, 2, 3]}); + * val newColumn = Column("b", [4, 5, 6]); + * val result = table.addColumns(newColumn); * } */ @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> hasColumn: Boolean + @PythonName("add_columns") + fun addColumns( + columns: union> + ) -> newTable: Table /** - * Return the type of the given column. + * Return a new table with an additional computed column. * - * @param columnName The name of the column to be queried. - * - * @result type The type of the column. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val type = table.getColumnType("a"); // Integer - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType - - /** - * Return the row at a specified index. + * **Note:** The original table is not modified. * - * @param index The index. + * @param name The name of the new column. + * @param computer The function that computes the values of the new column. * - * @result row The row of the table at the index. + * @result newTable The table with the computed column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val row = table.getRow(0); // Row({"a": 1, "b": 3}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.addComputedColumn("c", (row) -> row.getValue("a").add(row.getValue("b"))); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("get_row") - fun getRow( - index: Int - ) -> row: Row + @PythonName("add_computed_column") + fun addComputedColumn( + name: String, + computer: (row: Row) -> computedCell: Cell + ) -> newTable: Table /** - * Return a table with a number of statistical key values. + * Get a column from the table. * - * The original table is not modified. + * **Note:** This operation must fully load the data into memory, which can be expensive. * - * @result statistics The table with statistics. + * @param name The name of the column. + * + * @result column The column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val statistics = table.summarizeStatistics(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.getColumn("a"); + * // Column("a", [1, 2, 3]) * } */ @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: Table + @PythonName("get_column") + fun getColumn( + name: String + ) -> column: Column /** - * Return a new table with the provided column attached at the end. + * Get the data type of a column. * - * The original table is not modified. + * @param name The name of the column. * - * @result newTable The table with the column attached. + * @result type The data type of the column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = Column("c", [5, 6]); - * val newTable = table.addColumn(column); - * // Table({ - * // "a": [1, 2], - * // "b": [3, 4], - * // "c": [5, 6], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.getColumnType("a"); * } */ - @Deprecated( - alternative="Table.addColumns", - reason="No need for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("add_column") - fun addColumn( - column: Column - ) -> newTable: Table + @PythonName("get_column_type") + fun getColumnType( + name: String + ) -> type: DataType /** - * Return a new `Table` with multiple added columns. - * - * The original table is not modified. + * Check if the table has a column with a specific name. * - * @param columns The columns to be added. + * @param name The name of the column. * - * @result newTable A new table combining the original table and the given columns. + * @result hasColumn Whether the table has a column with the specified name. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column1 = Column("c", [5, 6]); - * val column2 = Column("d", [7, 8]); - * val newTable = table.addColumns([column1, column2]); - * // Table({ - * // "a": [1, 2], - * // "b": [3, 4], - * // "c": [5, 6], - * // "d": [7, 8], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.hasColumn("a"); // true * } */ @Pure - @PythonName("add_columns") - fun addColumns( - columns: union, Table> - ) -> newTable: Table + @PythonName("has_column") + fun hasColumn( + name: String + ) -> hasColumn: Boolean /** - * Return a new `Table` with an added Row attached. + * Return a new table without the specified columns. * - * If the table happens to be empty beforehand, respective columns will be added automatically. + * **Notes:** * - * The order of columns of the new row will be adjusted to the order of columns in the table. - * The new table will contain the merged schema. + * - The original table is not modified. + * - This method does not raise if a column does not exist. You can use it to ensure that the resulting table does + * not contain certain columns. * - * The original table is not modified. - * - * @param row The row to be added. + * @param names The names of the columns to remove. * - * @result newTable A new table with the added row at the end. + * @result newTable The table with the columns removed. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [4, 5]}); - * val row = Row({"a": 3, "b": 6}); - * val newTable = table.addRow(row); - * // Table({ - * // "a": [1, 2, 3], - * // "b": [4, 5, 6], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumns("a"); + * // Table({"b": [4, 5, 6]}) * } - */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("add_row") - fun addRow( - row: Row - ) -> newTable: Table - - /** - * Return a new `Table` with multiple added Rows attached. - * - * The order of columns of the new rows will be adjusted to the order of columns in the table. - * The new table will contain the merged schema. - * - * The original table is not modified. - * - * @param rows The rows to be added. - * - * @result newTable A new table which combines the original table and the given rows. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [5, 6]}); - * val row1 = Row({"a": 3, "b": 7}); - * val row2 = Row({"a": 4, "b": 8}); - * val newTable = table.addRows([row1, row2]); - * // Table({ - * // "a": [1, 2, 3, 4], - * // "b": [5, 6, 7, 8], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumns("c"); + * // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("add_rows") - fun addRows( - rows: union, Table> + @PythonName("remove_columns") + fun removeColumns( + names: union, String> ) -> newTable: Table /** - * Return a new table with rows filtered by Callable (e.g. lambda function). - * - * The original table is not modified. + * Return a new table with only the specified columns. * - * @param query A Callable that is applied to all rows. + * @param names The names of the columns to keep. * - * @result filteredTable A table containing only the rows filtered by the query. + * @result newTable The table with only the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val filteredTable = table.filterRows((row) -> - * row.getValue("a") as (Int) > 1 - * ); - * // Table({"a": [2], "b": [4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumnsExcept("a"); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeRows", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("filter_rows") - fun filterRows( - query: (row: Row) -> matches: Boolean - ) -> filteredTable: Table + @PythonName("remove_columns_except") + fun removeColumnsExcept( + names: union, String> + ) -> newTable: Table /** - * Return a map with copies of the output tables as values and the keys from the key_selector. + * Return a new table without columns that contain missing values. * - * The original table is not modified. + * **Notes:** * - * @param keySelector A Callable that is applied to all rows and returns the key of the group. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @result tablesByKey A map containing the new tables as values and the selected keys as keys. + * @result newTable The table without columns containing missing values. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val tablesByKey = table.groupRows((row) -> - * row.getValue("a") as (Int) <= 2 - * ); - * // { - * // true: Table({"a": [1, 2], "b": [4, 5]}), - * // false: Table({"a": [3], "b": [6]}), - * // } + * val table = Table({"a": [1, 2, 3], "b": [4, 5, null]}); + * val result = table.removeColumnsWithMissingValues(); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="None.", - reason="We'll provide a new solution with a more useful and efficient result.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("group_rows") - fun groupRows( - @PythonName("key_selector") keySelector: (row: Row) -> key: T - ) -> tablesByKey: Map + @PythonName("remove_columns_with_missing_values") + fun removeColumnsWithMissingValues() -> newTable: Table /** - * Return a new table with only the given column(s). - * - * The original table is not modified. - * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * Return a new table without non-numeric columns. * - * @param columnNames A list containing only the columns to be kept. + * **Note:** The original table is not modified. * - * @result projectedTable A table containing only the given column(s). + * @result newTable The table without non-numeric columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val projectedTable = table.keepOnlyColumns(["a"]); - * // Table({"a": [1, 2]}) + * val table = Table({"a": [1, 2, 3], "b": ["4", "5", "6"]}); + * val result = table.removeNonNumericColumns(); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeColumnsExcept", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("keep_only_columns") - fun keepOnlyColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table + @PythonName("remove_non_numeric_columns") + fun removeNonNumericColumns() -> newTable: Table /** - * Return a new table without the given column(s). - * - * The original table is not modified. + * Return a new table with a column renamed. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * **Note:** The original table is not modified. * - * @param columnNames A list containing all columns to be dropped. + * @param oldName The name of the column to rename. + * @param newName The new name of the column. * - * @result projectedTable A table without the given columns. + * @result newTable The table with the column renamed. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val projectedTable = table.removeColumns(["a"]); - * // Table({"b": [3, 4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.renameColumn("a", "c"); + * // Table({"c": [1, 2, 3], "b": [4, 5, 6]}) * } */ @Pure - @PythonName("remove_columns") - fun removeColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table + @PythonName("rename_column") + fun renameColumn( + @PythonName("old_name") oldName: String, + @PythonName("new_name") newName: String + ) -> newTable: Table /** - * Return a new table without the columns that contain missing values. + * Return a new table with a column replaced by zero or more columns. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * @param oldName The name of the column to replace. + * @param newColumns The new columns. * - * @result projectedTable A table without the columns that contain missing values. + * @result newTable The table with the column replaced. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val projectedTable = table.removeColumnsWithMissingValues(); - * // Table({"b": [3, 4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.replaceColumn("a", []); + * // Table({"b": [4, 5, 6]}) * } */ @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> projectedTable: Table + @PythonName("replace_column") + fun replaceColumn( + @PythonName("old_name") oldName: String, + @PythonName("new_columns") newColumns: union, Table> + ) -> newTable: Table /** - * Return a new table without the columns that contain non-numerical values. + * Return a new table with a column transformed. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * @param name The name of the column to transform. + * @param transformer The function that transforms the column. * - * @result projectedTable A table without the columns that contain non-numerical values. + * @result newTable The table with the transformed column. * * @example * pipeline example { - * val table = Table({"a": ["z", "y"], "b": [1, 2]}); - * val projectedTable = table.removeColumnsWithNonNumericalValues(); - * // Table({"b": [1, 2]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.transformColumn("a", (cell) -> cell.add(1)); + * // Table({"a": [2, 3, 4], "b": [4, 5, 6]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeNonNumericColumns", - reason="More concise name.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("remove_columns_with_non_numerical_values") - fun removeColumnsWithNonNumericalValues() -> projectedTable: Table + @PythonName("transform_column") + fun transformColumn( + name: String, + transformer: (cell: Cell) -> transformedCell: Cell + ) -> newTable: Table /** - * Return a new table with every duplicate row removed. + * Return a new table without duplicate rows. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result filteredTable The table with the duplicate rows removed. + * @result newTable The table without duplicate rows. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 1], "b": [3, 4, 3]}); - * val filteredTable = table.removeDuplicateRows(); - * // Table({"a": [1, 2], "b": [3, 4]}) + * val table = Table({"a": [1, 2, 2], "b": [4, 5, 5]}); + * val result = table.removeDuplicateRows(); + * // Table({"a": [1, 2], "b": [4, 5]}) * } */ @Pure @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> filteredTable: Table + fun removeDuplicateRows() -> newTable: Table /** - * Return a new table without the rows that contain missing values. + * Return a new table without rows that satisfy a condition. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result filteredTable A table without the rows that contain missing values. + * @param query The function that determines which rows to remove. + * + * @result newTable The table without the specified rows. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val filteredTable = table.removeRowsWithMissingValues(); - * // Table({"a": [1], "b": [3]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeRows((row) -> row.getValue("a").eq(2)); + * // Table({"a": [1, 3], "b": [4, 6]}) * } */ @Pure - @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues() -> filteredTable: Table + @PythonName("remove_rows") + fun removeRows( + query: (row: Row) -> shouldRemoveRow: Cell + ) -> newTable: Table /** - * Return a new table without those rows that contain at least one outlier. + * Return a new table without rows that satisfy a condition on a specific column. * - * We define an outlier as a value that has a distance of more than 3 standard deviations from the column mean. - * Missing values are not considered outliers. They are also ignored during the calculation of the standard - * deviation. + * **Note:** The original table is not modified. * - * The original table is not modified. + * @param name The name of the column. + * @param query The function that determines which rows to remove. * - * @result filteredTable A new table without rows containing outliers. + * @result newTable The table without the specified rows. * * @example * pipeline example { - * val table = Table({ - * "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - * "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3, 1000] - * }); - * val filteredTable = table.removeRowsWithOutliers(); - * // Table({ - * // "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - * // "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3] - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeRowsByColumn("a", (cell) -> cell.eq(2)); + * // Table({"a": [1, 3], "b": [4, 6]}) * } */ @Pure - @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers() -> filteredTable: Table + @PythonName("remove_rows_by_column") + fun removeRowsByColumn( + name: String, + query: (cell: Cell) -> shouldRemoveRow: Cell + ) -> newTable: Table /** - * Return a new `Table` with a single column renamed. + * Return a new table without rows containing missing values in the specified columns. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param oldName The old name of the target column. - * @param newName The new name of the target column. + * @param columnNames Names of the columns to consider. If null, all columns are considered. * - * @result newTable The Table with the renamed column. + * @result newTable The table without rows containing missing values in the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val newTable = table.renameColumn("a", "c"); - * // Table({"c": [1, 2], "b": [3, 4]}) + * val table = Table({"a": [1, null, 3], "b": [4, 5, null]}); + * val result = table.removeRowsWithMissingValues(); + * // Table({"a": [1], "b": [4]}) * } */ @Pure - @PythonName("rename_column") - fun renameColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_name") newName: String + @PythonName("remove_rows_with_missing_values") + fun removeRowsWithMissingValues( + @PythonName("column_names") columnNames: List? = null ) -> newTable: Table /** - * Return a new table with the specified old column replaced by a list of new columns. + * Return a new table without rows containing outliers in the specified columns. * - * The order of columns is kept. + * Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the + * data point from the mean of the column divided by the standard deviation of the column. If the z-score is + * greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the + * calculation of the z-score. * - * The original table is not modified. + * The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in + * `column_names`. * - * @param oldColumnName The name of the column to be replaced. - * @param newColumns The list of new columns replacing the old column. + * **Notes:** * - * @result newTable A table with the old column replaced by the new columns. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = Column("c", [5, 6]); - * val newTable = table.replaceColumn("a", [column]); - * // Table({"c": [5, 6], "b": [3, 4]}) - * } + * @param columnNames Names of the columns to consider. If null, all numeric columns are considered. + * @param zScoreThreshold The z-score threshold for detecting outliers. + * + * @result newTable The table without rows containing outliers in the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column1 = Column("c", [5, 6]); - * val column2 = Column("d", [7, 8]); - * val newTable = table.replaceColumn("a", [column1, column2]); - * // Table({"c": [5, 6], "d": [7, 8], "b": [3, 4]}) + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5, 6, 1000, null], + * "b": [1, 2, 3, 4, 5, 6, 7, 8], + * } + * ); + * val result = table.removeRowsWithOutliers(zScoreThreshold=2.0); + * // Table({"a": [1, 2, 3, 4, 5, 6, null], "b": [1, 2, 3, 4, 5, 6]}) * } */ @Pure - @PythonName("replace_column") - fun replaceColumn( - @PythonName("old_column_name") oldColumnName: String, - @PythonName("new_columns") newColumns: List + @PythonName("remove_rows_with_outliers") + fun removeRowsWithOutliers( + @PythonName("column_names") columnNames: List? = null, + @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 ) -> newTable: Table /** - * Return a new `Table` with randomly shuffled rows of this `Table`. + * Return a new table with the rows shuffled. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result shuffledTable The shuffled Table. + * @result newTable The table with the rows shuffled. * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val shuffledTable = table.shuffleRows(); + * val result = table.shuffleRows(); + * // Table({"a": [3, 2, 1], "b": [6, 5, 4]}) * } */ @Pure @PythonName("shuffle_rows") - fun shuffleRows() -> shuffledTable: Table + fun shuffleRows() -> newTable: Table /** - * Slice a part of the table into a new table. + * Return a new table with a slice of rows. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param start The first index of the range to be copied into a new table, None by default. - * @param end The last index of the range to be copied into a new table, None by default. - * @param step The step size used to iterate through the table, 1 by default. + * @param start The start index of the slice. + * @param length The length of the slice. If null, the slice contains all rows starting from `start`. Must greater than or + * equal to 0. * - * @result slicedTable The resulting table. + * @result newTable The table with the slice of rows. * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(start = 1); + * val result = table.sliceRows(start=1); * // Table({"a": [2, 3], "b": [5, 6]}) * } * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(end = 2); - * // Table({"a": [1, 2], "b": [4, 5]}) - * } - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(step = 2); - * // Table({"a": [1, 3], "b": [4, 6]}) + * val result = table.sliceRows(start=1, length=1); + * // Table({"a": [2], "b": [5]}) * } */ @Pure @PythonName("slice_rows") fun sliceRows( - start: Int? = null, - end: Int? = null, - step: Int = 1 - ) -> slicedTable: Table + start: Int = 0, + length: Int? = null + ) -> newTable: Table /** - * Sort the columns of a `Table` with the given comparator and return a new `Table`. + * Return a new table with the rows sorted. * - * The comparator is a function that takes two columns `col1` and `col2` and - * returns an integer: + * **Note:** The original table is not modified. * - * * If `col1` should be ordered before `col2`, the function should return a negative number. - * * If `col1` should be ordered after `col2`, the function should return a positive number. - * * If the original order of `col1` and `col2` should be kept, the function should return 0. + * @param keySelector The function that selects the key to sort by. + * @param descending Whether to sort in descending order. * - * If no comparator is given, the columns will be sorted alphabetically by their name. - * - * The original table is not modified. - * - * @param comparator The function used to compare two columns. - * - * @result sortedTable A new table with sorted columns. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortColumns((col1, col2) -> 1); - * // Table({"a": [1, 2], "b": [3, 4]}) - * } + * @result newTable The table with the rows sorted. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortColumns((col1, col2) -> -1); - * // Table({"b": [3, 4], "a": [1, 2]}) + * val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + * val result = table.sortRows((row) -> row.getValue("a").^sub(row.getValue("b"))); + * // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) * } */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (column1: Column, column2: Column) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows") + fun sortRows( + @PythonName("key_selector") keySelector: (row: Row) -> key: Cell, + descending: Boolean = false + ) -> newTable: Table /** - * Sort the rows of a `Table` with the given comparator and return a new `Table`. - * - * The comparator is a function that takes two rows `row1` and `row2` and - * returns an integer: - * - * * If `row1` should be ordered before `row2`, the function should return a negative number. - * * If `row1` should be ordered after `row2`, the function should return a positive number. - * * If the original order of `row1` and `row2` should be kept, the function should return 0. - * - * The original table is not modified. + * Return a new table with the rows sorted by a specific column. * - * @param comparator The function used to compare two rows. + * **Note:** The original table is not modified. * - * @result sortedTable A new table with sorted rows. + * @param name The name of the column to sort by. + * @param descending Whether to sort in descending order. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortRows((row1, row2) -> 1); - * // Table({"a": [1, 2], "b": [3, 4]}) - * } + * @result newTable The table with the rows sorted by the specified column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortRows((row1, row2) -> -1); - * // Table({"a": [2, 1], "b": [4, 3]}) + * val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + * val result = table.sortRowsByColumn("a"); + * // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.sortRows", - reason="Selecting a key is more ergonomic than a comparator.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("sort_rows") - fun sortRows( - comparator: (row1: Row, row2: Row) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows_by_column") + fun sortRowsByColumn( + name: String, + descending: Boolean = false + ) -> newTable: Table /** - * Split the table into two new tables. Consider using {@link Table.shuffleRows} before splitting to ensure a random - * distribution of rows in both tables. + * Create two tables by splitting the rows of the current table. * - * The original table is not modified. + * The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table + * contains the remaining rows. + * + * **Notes:** * - * @param ratioInFirst - * How many rows should be in the first table, expressed as a ratio of the total number of rows. Must be between 0 - * and 1. + * - The original table is not modified. + * - By default, the rows are shuffled before splitting. You can disable this by setting `shuffle` to false. * - * @result first The first table with the specified size. - * @result second The second table with the remaining rows. + * @param percentageInFirst The percentage of rows to include in the first table. Must be between 0 and 1. + * @param shuffle Whether to shuffle the rows before splitting. + * + * @result firstTable The first table. + * @result secondTable The second table. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}); - * val first, val second = table.splitRows(0.5); - * // first: Table({"a": [1, 2], "b": [5, 6]}) - * // second: Table({"a": [3, 4], "b": [7, 8]}) + * val table = Table({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}); + * val firstTable, val secondTable = table.splitRows(0.6); * } */ @Pure @PythonName("split_rows") fun splitRows( - @PythonName("percentage_in_first") ratioInFirst: Float - ) -> (first: Table, second: Table) + @PythonName("percentage_in_first") percentageInFirst: Float, + shuffle: Boolean = true + ) -> (firstTable: Table, secondTable: Table) /** - * Return a new `Table` with the provided column transformed by calling the provided transformer. + * Return a new table with the columns of another table added. * - * The original table is not modified. + * **Notes:** * - * @result transformedTable The table with the transformed column. + * - The original tables are not modified. + * - This operation must fully load the data into memory, which can be expensive. + * + * @param other The table to add as columns. + * + * @result newTable The table with the columns added. * * @example * pipeline example { - * val prices = Table({ - * "product": ["apple", "banana", "cherry"], - * "price": [ 100, 2, 4], - * }); - * val discountedPrices = prices.transformColumn("price", (row) -> - * row.getValue("price") as (Int) * 0.5 - * ); - * // Table({ - * // "product": ["apple", "banana", "cherry"], - * // "price": [ 50, 1, 2], - * // }) + * val table1 = Table({"a": [1, 2, 3]}); + * val table2 = Table({"b": [4, 5, 6]}); + * val result = table1.addTableAsColumns(table2); + * // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) * } */ @Pure - @PythonName("transform_column") - fun transformColumn( - name: String, - transformer: (row: Row) -> newColumnValue: Any? - ) -> transformedTable: Table + @PythonName("add_table_as_columns") + fun addTableAsColumns( + other: Table + ) -> newTable: Table /** - * Return a new `Table` with a learned transformation applied to this table. + * Return a new table with the rows of another table added. * - * The original table is not modified. + * **Notes:** * - * @param transformer The transformer which transforms the given table. + * - The original tables are not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @result transformedTable The transformed table. + * @param other The table to add as rows. + * + * @result newTable The table with the rows added. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val imputer = Imputer(Imputer.Strategy.Mean).fit(table, ["a"]); - * val transformedTable = table.transformTable(imputer); - * // Table({"a": [1, 1], "b": [3, 4]}) + * val table1 = Table({"a": [1, 2, 3]}); + * val table2 = Table({"a": [4, 5, 6]}); + * val result = table1.addTableAsRows(table2); + * // Table({"a": [1, 2, 3, 4, 5, 6]}) * } */ @Pure - @PythonName("transform_table") - fun transformTable( - transformer: TableTransformer - ) -> transformedTable: Table + @PythonName("add_table_as_rows") + fun addTableAsRows( + other: Table + ) -> newTable: Table /** - * Return a new `Table` with the inverted transformation applied by the given transformer. + * Return a new table inverse-transformed by a **fitted, invertible** transformer. * - * The original table is not modified. + * **Notes:** + * + * - The original table is not modified. + * - Depending on the transformer, this operation might fully load the data into memory, which can be expensive. * - * @param transformer A transformer that was fitted with columns, which are all present in the table. + * @param fittedTransformer The fitted, invertible transformer to apply. * - * @result originalTable The original table. + * @result newTable The inverse-transformed table. * * @example * pipeline example { - * val table = Table({"a": ["z", "y"], "b": [3, 4]}); - * val encoder = LabelEncoder().fit(table, ["a"]); - * val transformedTable = table.transformTable(encoder); - * val originalTable = transformedTable.inverseTransformTable(encoder); - * // Table({"a": ["z", "y"], "b": [3, 4]}) + * val table = Table({"a": [1, 2, 3]}); + * val transformer, val transformedTable = RangeScaler(min=0.0, max=1.0).fitAndTransform(table, ["a"]); + * val result = transformedTable.inverseTransformTable(transformer); + * // Table({"a": [1, 2, 3]}) * } */ @Pure @PythonName("inverse_transform_table") fun inverseTransformTable( - transformer: InvertibleTableTransformer - ) -> originalTable: Table + @PythonName("fitted_transformer") fittedTransformer: InvertibleTableTransformer + ) -> newTable: Table /** - * Plot a correlation heatmap for all numerical columns of this `Table`. + * Return a new table transformed by a **fitted** transformer. + * + * **Notes:** * - * @result correlationHeatmap The plot as an image. + * - The original table is not modified. + * - Depending on the transformer, this operation might fully load the data into memory, which can be expensive. + * + * @param fittedTransformer The fitted transformer to apply. + * + * @result newTable The transformed table. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val correlationHeatmap = table.plotCorrelationHeatmap(); + * val table = Table({"a": [1, 2, 3]}); + * val transformer = RangeScaler(min=0.0, max=1.0).fit(table, ["a"]); + * val result = table.transformTable(transformer); + * // Table({"a": [0, 0.5, 1]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.correlationHeatmap instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_correlation_heatmap") - fun plotCorrelationHeatmap() -> correlationHeatmap: Image - - /** - * Plot two columns against each other in a lineplot. - * - * If there are multiple x-values for a y-value, the resulting plot will consist of a line representing the mean - * and the lower-transparency area around the line representing the 95% confidence interval. - * - * @param xColumnName The column name of the column to be plotted on the x-Axis. - * @param yColumnName The column name of the column to be plotted on the y-Axis. - * - * @result lineplot The plot as an image. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val lineplot = table.plotLineplot("a", "b"); - * } - */ - @Deprecated( - alternative="Try ExperimentalTable.plot.lineplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_lineplot") - fun plotLineplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> lineplot: Image - - /** - * Plot two columns against each other in a scatterplot. - * - * @param xColumnName The column name of the column to be plotted on the x-Axis. - * @param yColumnName The column name of the column to be plotted on the y-Axis. - * - * @result scatterplot The plot as an image. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val scatterplot = table.plotScatterplot("a", "b"); - * } - */ - @Deprecated( - alternative="Try ExperimentalTable.plot.scatterplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_scatterplot") - fun plotScatterplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> scatterplot: Image + @PythonName("transform_table") + fun transformTable( + @PythonName("fitted_transformer") fittedTransformer: TableTransformer + ) -> newTable: Table /** - * Plot a boxplot for every numerical column. + * Return a table with important statistics about this table. * - * @result boxplots The plot as an image. + * @result statistics The table with statistics. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val boxplots = table.plotBoxplots(); + * val table = Table({"a": [1, 3]}); + * val result = table.summarizeStatistics(); * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.boxplots instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_boxplots") - fun plotBoxplots() -> boxplots: Image + @PythonName("summarize_statistics") + fun summarizeStatistics() -> statistics: Table /** - * Plot a histogram for every column. + * Return the data of the table as a list of columns. * - * @param numberOfBins The number of bins to use in the histogram. - * - * @result histograms The plot as an image. + * @result columns List of columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val histograms = table.plotHistograms(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val columns = table.toColumns(); * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.histograms instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_histograms") - fun plotHistograms( - @PythonName("number_of_bins") const numberOfBins: Int = 10 - ) -> histograms: Image where { - numberOfBins > 0 - } + @PythonName("to_columns") + fun toColumns() -> columns: List /** - * Write the data from the table into a CSV file. + * Write the table to a CSV file. * - * If the file and/or the directories do not exist they will be created. If the file already exists it will be - * overwritten. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @param path The path to the output file. + * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toCsvFile("path/to/file.csv"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toCsvFile("output.csv"); * } */ @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) @@ -1113,505 +831,344 @@ pipeline example { ) /** - * Write the data from the table into an Excel file. - * - * Valid file extensions are `.xls`, '.xlsx', `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. - * If the file and/or the directories do not exist, they will be created. If the file already exists, it will be - * overwritten. + * Return a map that maps column names to column values. * - * @param path The path to the output file. + * @result map Map representation of the table. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toExcelFile("path/to/file.xlsx"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.toMap(); + * // {"a": [1, 2, 3], "b": [4, 5, 6]} * } */ - @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) - @PythonName("to_excel_file") - fun toExcelFile( - path: String - ) + @Pure + @PythonName("to_dict") + fun toMap() -> map: Map> /** - * Write the data from the table into a JSON file. + * Write the table to a JSON file. * - * If the file and/or the directories do not exist, they will be created. If the file already exists it will be - * overwritten. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @param path The path to the output file. + * **Note:** This operation must fully load the data into memory, which can be expensive. + * + * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". + * @param orientation The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If + * "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but + * slower and less memory-efficient. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toJsonFile("path/to/file.json"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toJsonFile("output.json"); * } */ @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) @PythonName("to_json_file") fun toJsonFile( - path: String + path: String, + orientation: literal<"column", "row"> = "column" ) /** - * Return a map of column names to column values. - * - * @result map Map representation of the table. + * Write the table to a Parquet file. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val map = table.toMap(); - * // {"a": [1, 2], "b": [3, 4]} - * } - */ - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - - /** - * Return an HTML representation of the table. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @result html The generated HTML. + * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val html = table.toHtml(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toParquetFile("output.parquet"); * } */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" + @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) + @PythonName("to_parquet_file") + fun toParquetFile( + path: String ) - @Pure - @PythonName("to_html") - fun toHtml() -> html: String /** - * Return a list of the columns. + * Return a new `TabularDataset` with columns marked as a target, feature, or extra. * - * @result columns List of columns. + * - The target column is the column that a model should predict. + * - Feature columns are columns that a model should use to make predictions. + * - Extra columns are columns that are neither feature nor target. They can be used to provide additional context, + * like an ID column. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val columns = table.toColumns(); - * // [Column("a", [1, 2]), Column("b", [3, 4])] - * } - */ - @Pure - @PythonName("to_columns") - fun toColumns() -> columns: List - - /** - * Return a list of the rows. + * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns + * are specified, all columns except the target column are used as features. * - * @result rows List of rows. + * @param targetName Name of the target column. + * @param extraNames Names of the columns that are neither feature nor target. If null, no extra columns are used, i.e. all but + * the target column are used as features. + * + * @result dataset A new tabular dataset with the given target and feature names. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val rows = table.toRows(); - * // [Row({"a": 1, "b": 3}), Row({"a": 2, "b": 4})] + * val table = Table( + * { + * "item": ["apple", "milk", "beer"], + * "price": [1.10, 1.19, 1.79], + * "amount_bought": [74, 72, 51], + * } + * ); + * val dataset = table.toTabularDataset(targetName="amount_bought", extraNames=["item"]); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("to_rows") - fun toRows() -> rows: List + @PythonName("to_tabular_dataset") + fun toTabularDataset( + @PythonName("target_name") targetName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TabularDataset /** - * Return a new `TabularDataset` with columns marked as a target column or feature columns. + * Return a new `TimeSeriesDataset` with columns marked as a target column, time or feature columns. * * The original table is not modified. * - * @param targetName - * Name of the target column. + * @param targetName Name of the target column. + * @param timeName Name of the time column. + * @param extraNames Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but + * the target column are used as features. * - * @param extraNames - * Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the - * target column are used as features. - * - * @result dataset A new tabular dataset with the given target and extras. - * - * @example - * pipeline example { - * val table = Table({ - * "age": [23, 16], - * "survived": [ 0, 1], - * }); - * val dataset = table.toTabularDataset("survived"); - * } + * @result dataset A new time series dataset with the given target and feature names. * * @example * pipeline example { - * val table = Table({ - * "id": [ 1, 2], - * "age": [23, 16], - * "survived": [ 0, 1], - * }); - * val dataset = table.toTabularDataset("target", extraNames = ["id"]); + * val table = Table( + * { + * "day": [0, 1, 2], + * "price": [1.10, 1.19, 1.79], + * "amount_bought": [74, 72, 51], + * } + * ); + * val dataset = table.toTimeSeriesDataset(targetName="amount_bought", timeName= "day"); * } */ @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( + @PythonName("to_time_series_dataset") + fun toTimeSeriesDataset( @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List = [] - ) -> dataset: TabularDataset + @PythonName("time_name") timeName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TimeSeriesDataset } ``` -## `#!sds attr` columnNames {#safeds.data.tabular.containers.Table.columnNames data-toc-label='columnNames'} +## `#!sds attr` columnCount {#safeds.data.tabular.containers.Table.columnCount data-toc-label='columnCount'} -Return a list of all column names in this table. +The number of columns in the table. -**Type:** [`List`][safeds.lang.List] +**Type:** [`Int`][safeds.lang.Int] -**Examples:** +## `#!sds attr` columnNames {#safeds.data.tabular.containers.Table.columnNames data-toc-label='columnNames'} -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val columnNames = table.columnNames; // ["a", "b"] -} -``` +The names of the columns in the table. -## `#!sds attr` numberOfColumns {#safeds.data.tabular.containers.Table.numberOfColumns data-toc-label='numberOfColumns'} +**Type:** [`List`][safeds.lang.List] -Return the number of columns. +## `#!sds attr` plot {#safeds.data.tabular.containers.Table.plot data-toc-label='plot'} -**Type:** [`Int`][safeds.lang.Int] +The plotter for the table. -**Examples:** +**Type:** [`TablePlotter`][safeds.data.tabular.plotting.TablePlotter] -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val numberOfColumns = table.numberOfColumns; // 2 -} -``` +## `#!sds attr` rowCount {#safeds.data.tabular.containers.Table.rowCount data-toc-label='rowCount'} -## `#!sds attr` numberOfRows {#safeds.data.tabular.containers.Table.numberOfRows data-toc-label='numberOfRows'} +The number of rows in the table. -Return the number of rows. +**Note:** This operation must fully load the data into memory, which can be expensive. **Type:** [`Int`][safeds.lang.Int] -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val numberOfRows = table.numberOfRows; // 2 -} -``` - ## `#!sds attr` schema {#safeds.data.tabular.containers.Table.schema data-toc-label='schema'} -Return the schema of the table. +The schema of the table. **Type:** [`Schema`][safeds.data.tabular.typing.Schema] -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val `schema` = table.`schema`; -} -``` - -## :warning:{ title="Deprecated" } `#!sds fun` addColumn {#safeds.data.tabular.containers.Table.addColumn data-toc-label='addColumn'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +## `#!sds fun` addColumns {#safeds.data.tabular.containers.Table.addColumns data-toc-label='addColumns'} - - **Alternative:** Table.addColumns - - **Reason:** No need for two methods. +Return a new table with additional columns. -Return a new table with the provided column attached at the end. +**Notes:** -The original table is not modified. +- The original table is not modified. +- This operation must fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `column` | [`Column`][safeds.data.tabular.containers.Column] | - | - | +| `columns` | `#!sds union, List>>` | The columns to add. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the column attached. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the additional columns. | **Examples:** ```sds hl_lines="4" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val column = Column("c", [5, 6]); - val newTable = table.addColumn(column); - // Table({ - // "a": [1, 2], - // "b": [3, 4], - // "c": [5, 6], - // }) -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="319" - @Deprecated( - alternative="Table.addColumns", - reason="No need for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("add_column") - fun addColumn( - column: Column - ) -> newTable: Table - ``` - -## `#!sds fun` addColumns {#safeds.data.tabular.containers.Table.addColumns data-toc-label='addColumns'} - -Return a new `Table` with multiple added columns. - -The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columns` | `#!sds union>, Table>` | The columns to be added. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table combining the original table and the given columns. | - -**Examples:** - -```sds hl_lines="5" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val column1 = Column("c", [5, 6]); - val column2 = Column("d", [7, 8]); - val newTable = table.addColumns([column1, column2]); - // Table({ - // "a": [1, 2], - // "b": [3, 4], - // "c": [5, 6], - // "d": [7, 8], - // }) + val table = Table({"a": [1, 2, 3]}); + val newColumn = Column("b", [4, 5, 6]); + val result = table.addColumns(newColumn); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="354" + ```sds linenums="172" @Pure @PythonName("add_columns") fun addColumns( - columns: union, Table> + columns: union> ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` addRow {#safeds.data.tabular.containers.Table.addRow data-toc-label='addRow'} +## `#!sds fun` addComputedColumn {#safeds.data.tabular.containers.Table.addComputedColumn data-toc-label='addComputedColumn'} -!!! warning "Deprecated" +Return a new table with an additional computed column. - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. - -Return a new `Table` with an added Row attached. - -If the table happens to be empty beforehand, respective columns will be added automatically. - -The order of columns of the new row will be adjusted to the order of columns in the table. -The new table will contain the merged schema. - -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `row` | [`Row`][safeds.data.tabular.containers.Row] | The row to be added. | - | +| `name` | [`String`][safeds.lang.String] | The name of the new column. | - | +| `computer` | `#!sds (row: Row) -> (computedCell: Cell)` | The function that computes the values of the new column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table with the added row at the end. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the computed column. | **Examples:** -```sds hl_lines="4" +```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [4, 5]}); - val row = Row({"a": 3, "b": 6}); - val newTable = table.addRow(row); - // Table({ - // "a": [1, 2, 3], - // "b": [4, 5, 6], - // }) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.addComputedColumn("c", (row) -> row.getValue("a").add(row.getValue("b"))); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="385" - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="194" @Pure - @PythonName("add_row") - fun addRow( - row: Row + @PythonName("add_computed_column") + fun addComputedColumn( + name: String, + computer: (row: Row) -> computedCell: Cell ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` addRows {#safeds.data.tabular.containers.Table.addRows data-toc-label='addRows'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +## `#!sds fun` addTableAsColumns {#safeds.data.tabular.containers.Table.addTableAsColumns data-toc-label='addTableAsColumns'} - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. +Return a new table with the columns of another table added. -Return a new `Table` with multiple added Rows attached. +**Notes:** -The order of columns of the new rows will be adjusted to the order of columns in the table. -The new table will contain the merged schema. - -The original table is not modified. +- The original tables are not modified. +- This operation must fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `rows` | `#!sds union, Table>` | The rows to be added. | - | +| `other` | [`Table`][safeds.data.tabular.containers.Table] | The table to add as columns. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table which combines the original table and the given rows. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the columns added. | **Examples:** -```sds hl_lines="5" +```sds hl_lines="4" pipeline example { - val table = Table({"a": [1, 2], "b": [5, 6]}); - val row1 = Row({"a": 3, "b": 7}); - val row2 = Row({"a": 4, "b": 8}); - val newTable = table.addRows([row1, row2]); - // Table({ - // "a": [1, 2, 3, 4], - // "b": [5, 6, 7, 8], - // }) + val table1 = Table({"a": [1, 2, 3]}); + val table2 = Table({"b": [4, 5, 6]}); + val result = table1.addTableAsColumns(table2); + // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="421" - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="699" @Pure - @PythonName("add_rows") - fun addRows( - rows: union, Table> + @PythonName("add_table_as_columns") + fun addTableAsColumns( + other: Table ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` filterRows {#safeds.data.tabular.containers.Table.filterRows data-toc-label='filterRows'} - -!!! warning "Deprecated" +## `#!sds fun` addTableAsRows {#safeds.data.tabular.containers.Table.addTableAsRows data-toc-label='addTableAsRows'} - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +Return a new table with the rows of another table added. - - **Alternative:** Try ExperimentalTable.removeRows - - **Reason:** Users looked for a method with 'remove' in the name, so they missed this. +**Notes:** -Return a new table with rows filtered by Callable (e.g. lambda function). - -The original table is not modified. +- The original tables are not modified. +- This operation must fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `query` | `#!sds (row: Row) -> (matches: Boolean)` | A Callable that is applied to all rows. | - | +| `other` | [`Table`][safeds.data.tabular.containers.Table] | The table to add as rows. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `filteredTable` | [`Table`][safeds.data.tabular.containers.Table] | A table containing only the rows filtered by the query. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the rows added. | **Examples:** -```sds hl_lines="3" +```sds hl_lines="4" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val filteredTable = table.filterRows((row) -> - row.getValue("a") as (Int) > 1 - ); - // Table({"a": [2], "b": [4]}) + val table1 = Table({"a": [1, 2, 3]}); + val table2 = Table({"a": [4, 5, 6]}); + val result = table1.addTableAsRows(table2); + // Table({"a": [1, 2, 3, 4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="451" - @Deprecated( - alternative="Try ExperimentalTable.removeRows", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="725" @Pure - @PythonName("filter_rows") - fun filterRows( - query: (row: Row) -> matches: Boolean - ) -> filteredTable: Table + @PythonName("add_table_as_rows") + fun addTableAsRows( + other: Table + ) -> newTable: Table ``` ## `#!sds fun` getColumn {#safeds.data.tabular.containers.Table.getColumn data-toc-label='getColumn'} -Return a column with the data of the specified column. +Get a column from the table. + +**Note:** This operation must fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The name of the column. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** @@ -1623,776 +1180,516 @@ Return a column with the data of the specified column. ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val column = table.getColumn("a"); // Column("a", [1, 2]) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.getColumn("a"); + // Column("a", [1, 2, 3]) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="214" + ```sds linenums="217" @Pure @PythonName("get_column") fun getColumn( - @PythonName("column_name") columnName: String + name: String ) -> column: Column ``` ## `#!sds fun` getColumnType {#safeds.data.tabular.containers.Table.getColumnType data-toc-label='getColumnType'} -Return the type of the given column. +Get the data type of a column. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The name of the column to be queried. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `type` | [`ColumnType`][safeds.data.tabular.typing.ColumnType] | The type of the column. | +| `type` | [`DataType`][safeds.data.tabular.typing.DataType] | The data type of the column. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val type = table.getColumnType("a"); // Integer + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.getColumnType("a"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="252" + ```sds linenums="236" @Pure @PythonName("get_column_type") fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` getRow {#safeds.data.tabular.containers.Table.getRow data-toc-label='getRow'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. - -Return the row at a specified index. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `index` | [`Int`][safeds.lang.Int] | The index. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `row` | [`Row`][safeds.data.tabular.containers.Row] | The row of the table at the index. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val row = table.getRow(0); // Row({"a": 1, "b": 3}) -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="271" - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("get_row") - fun getRow( - index: Int - ) -> row: Row - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` groupRows {#safeds.data.tabular.containers.Table.groupRows data-toc-label='groupRows'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** We'll provide a new solution with a more useful and efficient result. - -Return a map with copies of the output tables as values and the keys from the key_selector. - -The original table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `keySelector` | `#!sds (row: Row) -> (key: T)` | A Callable that is applied to all rows and returns the key of the group. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `tablesByKey` | [`Map`][safeds.lang.Map] | A map containing the new tables as values and the selected keys as keys. | - -**Type parameters:** - -| Name | Upper Bound | Description | Default | -|------|-------------|-------------|---------| -| `T` | [`Any?`][safeds.lang.Any] | - | - | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - val tablesByKey = table.groupRows((row) -> - row.getValue("a") as (Int) <= 2 - ); - // { - // true: Table({"a": [1, 2], "b": [4, 5]}), - // false: Table({"a": [3], "b": [6]}), - // } -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="484" - @Deprecated( - alternative="None.", - reason="We'll provide a new solution with a more useful and efficient result.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("group_rows") - fun groupRows( - @PythonName("key_selector") keySelector: (row: Row) -> key: T - ) -> tablesByKey: Map + name: String + ) -> type: DataType ``` ## `#!sds fun` hasColumn {#safeds.data.tabular.containers.Table.hasColumn data-toc-label='hasColumn'} -Return whether the table contains a given column. +Check if the table has a column with a specific name. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The name of the column. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | True if the column exists. | +| `hasColumn` | [`Boolean`][safeds.lang.Boolean] | Whether the table has a column with the specified name. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val hasColumn = table.hasColumn("a"); // true + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.hasColumn("a"); // true } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="233" + ```sds linenums="255" @Pure @PythonName("has_column") fun hasColumn( - @PythonName("column_name") columnName: String + name: String ) -> hasColumn: Boolean ``` ## `#!sds fun` inverseTransformTable {#safeds.data.tabular.containers.Table.inverseTransformTable data-toc-label='inverseTransformTable'} -Return a new `Table` with the inverted transformation applied by the given transformer. +Return a new table inverse-transformed by a **fitted, invertible** transformer. -The original table is not modified. +**Notes:** + +- The original table is not modified. +- Depending on the transformer, this operation might fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `transformer` | [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] | A transformer that was fitted with columns, which are all present in the table. | - | +| `fittedTransformer` | [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] | The fitted, invertible transformer to apply. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The inverse-transformed table. | **Examples:** -```sds hl_lines="5" +```sds hl_lines="4" pipeline example { - val table = Table({"a": ["z", "y"], "b": [3, 4]}); - val encoder = LabelEncoder().fit(table, ["a"]); - val transformedTable = table.transformTable(encoder); - val originalTable = transformedTable.inverseTransformTable(encoder); - // Table({"a": ["z", "y"], "b": [3, 4]}) + val table = Table({"a": [1, 2, 3]}); + val transformer, val transformedTable = RangeScaler(min=0.0, max=1.0).fitAndTransform(table, ["a"]); + val result = transformedTable.inverseTransformTable(transformer); + // Table({"a": [1, 2, 3]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="960" + ```sds linenums="751" @Pure @PythonName("inverse_transform_table") fun inverseTransformTable( - transformer: InvertibleTableTransformer - ) -> originalTable: Table + @PythonName("fitted_transformer") fittedTransformer: InvertibleTableTransformer + ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` keepOnlyColumns {#safeds.data.tabular.containers.Table.keepOnlyColumns data-toc-label='keepOnlyColumns'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.removeColumnsExcept - - **Reason:** Users looked for a method with 'remove' in the name, so they missed this. +## `#!sds fun` removeColumns {#safeds.data.tabular.containers.Table.removeColumns data-toc-label='removeColumns'} -Return a new table with only the given column(s). +Return a new table without the specified columns. -The original table is not modified. +**Notes:** -Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. +- The original table is not modified. +- This method does not raise if a column does not exist. You can use it to ensure that the resulting table does + not contain certain columns. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnNames` | [`List`][safeds.lang.List] | A list containing only the columns to be kept. | - | +| `names` | `#!sds union, String>` | The names of the columns to remove. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `projectedTable` | [`Table`][safeds.data.tabular.containers.Table] | A table containing only the given column(s). | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the columns removed. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val projectedTable = table.keepOnlyColumns(["a"]); - // Table({"a": [1, 2]}) -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="514" - @Deprecated( - alternative="Try ExperimentalTable.removeColumnsExcept", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("keep_only_columns") - fun keepOnlyColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotBoxplots {#safeds.data.tabular.containers.Table.plotBoxplots data-toc-label='plotBoxplots'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.plot.boxplots instead. - - **Reason:** Groups all plotting methods in one place. - -Plot a boxplot for every numerical column. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `boxplots` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val boxplots = table.plotBoxplots(); -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="1055" - @Deprecated( - alternative="Try ExperimentalTable.plot.boxplots instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_boxplots") - fun plotBoxplots() -> boxplots: Image - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotCorrelationHeatmap {#safeds.data.tabular.containers.Table.plotCorrelationHeatmap data-toc-label='plotCorrelationHeatmap'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.plot.correlationHeatmap instead. - - **Reason:** Groups all plotting methods in one place. - -Plot a correlation heatmap for all numerical columns of this `Table`. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `correlationHeatmap` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val correlationHeatmap = table.plotCorrelationHeatmap(); -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="977" - @Deprecated( - alternative="Try ExperimentalTable.plot.correlationHeatmap instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_correlation_heatmap") - fun plotCorrelationHeatmap() -> correlationHeatmap: Image - ``` - -## :warning:{ title="Deprecated" } `#!sds fun` plotHistograms {#safeds.data.tabular.containers.Table.plotHistograms data-toc-label='plotHistograms'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.plot.histograms instead. - - **Reason:** Groups all plotting methods in one place. - -Plot a histogram for every column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to use in the histogram. | `#!sds 10` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `histograms` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.removeColumns("a"); + // Table({"b": [4, 5, 6]}) +} +``` ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val histograms = table.plotHistograms(); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.removeColumns("c"); + // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1078" - @Deprecated( - alternative="Try ExperimentalTable.plot.histograms instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="288" @Pure - @PythonName("plot_histograms") - fun plotHistograms( - @PythonName("number_of_bins") const numberOfBins: Int = 10 - ) -> histograms: Image where { - numberOfBins > 0 - } + @PythonName("remove_columns") + fun removeColumns( + names: union, String> + ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` plotLineplot {#safeds.data.tabular.containers.Table.plotLineplot data-toc-label='plotLineplot'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.plot.lineplot instead. - - **Reason:** Groups all plotting methods in one place. +## `#!sds fun` removeColumnsExcept {#safeds.data.tabular.containers.Table.removeColumnsExcept data-toc-label='removeColumnsExcept'} -Plot two columns against each other in a lineplot. - -If there are multiple x-values for a y-value, the resulting plot will consist of a line representing the mean -and the lower-transparency area around the line representing the 95% confidence interval. +Return a new table with only the specified columns. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `xColumnName` | [`String`][safeds.lang.String] | The column name of the column to be plotted on the x-Axis. | - | -| `yColumnName` | [`String`][safeds.lang.String] | The column name of the column to be plotted on the y-Axis. | - | +| `names` | `#!sds union, String>` | The names of the columns to keep. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `lineplot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with only the specified columns. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val lineplot = table.plotLineplot("a", "b"); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.removeColumnsExcept("a"); + // Table({"a": [1, 2, 3]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1004" - @Deprecated( - alternative="Try ExperimentalTable.plot.lineplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="308" @Pure - @PythonName("plot_lineplot") - fun plotLineplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> lineplot: Image + @PythonName("remove_columns_except") + fun removeColumnsExcept( + names: union, String> + ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` plotScatterplot {#safeds.data.tabular.containers.Table.plotScatterplot data-toc-label='plotScatterplot'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.plot.scatterplot instead. - - **Reason:** Groups all plotting methods in one place. +## `#!sds fun` removeColumnsWithMissingValues {#safeds.data.tabular.containers.Table.removeColumnsWithMissingValues data-toc-label='removeColumnsWithMissingValues'} -Plot two columns against each other in a scatterplot. +Return a new table without columns that contain missing values. -**Parameters:** +**Notes:** -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `xColumnName` | [`String`][safeds.lang.String] | The column name of the column to be plotted on the x-Axis. | - | -| `yColumnName` | [`String`][safeds.lang.String] | The column name of the column to be plotted on the y-Axis. | - | +- The original table is not modified. +- This operation must fully load the data into memory, which can be expensive. **Results:** | Name | Type | Description | |------|------|-------------| -| `scatterplot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without columns containing missing values. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val scatterplot = table.plotScatterplot("a", "b"); + val table = Table({"a": [1, 2, 3], "b": [4, 5, null]}); + val result = table.removeColumnsWithMissingValues(); + // Table({"a": [1, 2, 3]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1031" - @Deprecated( - alternative="Try ExperimentalTable.plot.scatterplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="331" @Pure - @PythonName("plot_scatterplot") - fun plotScatterplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> scatterplot: Image + @PythonName("remove_columns_with_missing_values") + fun removeColumnsWithMissingValues() -> newTable: Table ``` -## `#!sds fun` removeColumns {#safeds.data.tabular.containers.Table.removeColumns data-toc-label='removeColumns'} - -Return a new table without the given column(s). - -The original table is not modified. - -Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. +## `#!sds fun` removeDuplicateRows {#safeds.data.tabular.containers.Table.removeDuplicateRows data-toc-label='removeDuplicateRows'} -**Parameters:** +Return a new table without duplicate rows. -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `columnNames` | [`List`][safeds.lang.List] | A list containing all columns to be dropped. | - | +**Note:** The original table is not modified. **Results:** | Name | Type | Description | |------|------|-------------| -| `projectedTable` | [`Table`][safeds.data.tabular.containers.Table] | A table without the given columns. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without duplicate rows. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val projectedTable = table.removeColumns(["a"]); - // Table({"b": [3, 4]}) + val table = Table({"a": [1, 2, 2], "b": [4, 5, 5]}); + val result = table.removeDuplicateRows(); + // Table({"a": [1, 2], "b": [4, 5]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="544" + ```sds linenums="439" @Pure - @PythonName("remove_columns") - fun removeColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table + @PythonName("remove_duplicate_rows") + fun removeDuplicateRows() -> newTable: Table ``` -## `#!sds fun` removeColumnsWithMissingValues {#safeds.data.tabular.containers.Table.removeColumnsWithMissingValues data-toc-label='removeColumnsWithMissingValues'} - -Return a new table without the columns that contain missing values. +## `#!sds fun` removeNonNumericColumns {#safeds.data.tabular.containers.Table.removeNonNumericColumns data-toc-label='removeNonNumericColumns'} -The original table is not modified. +Return a new table without non-numeric columns. -Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. +**Note:** The original table is not modified. **Results:** | Name | Type | Description | |------|------|-------------| -| `projectedTable` | [`Table`][safeds.data.tabular.containers.Table] | A table without the columns that contain missing values. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without non-numeric columns. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, null], "b": [3, 4]}); - val projectedTable = table.removeColumnsWithMissingValues(); - // Table({"b": [3, 4]}) + val table = Table({"a": [1, 2, 3], "b": ["4", "5", "6"]}); + val result = table.removeNonNumericColumns(); + // Table({"a": [1, 2, 3]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="566" + ```sds linenums="349" @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> projectedTable: Table + @PythonName("remove_non_numeric_columns") + fun removeNonNumericColumns() -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` removeColumnsWithNonNumericalValues {#safeds.data.tabular.containers.Table.removeColumnsWithNonNumericalValues data-toc-label='removeColumnsWithNonNumericalValues'} - -!!! warning "Deprecated" +## `#!sds fun` removeRows {#safeds.data.tabular.containers.Table.removeRows data-toc-label='removeRows'} - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +Return a new table without rows that satisfy a condition. - - **Alternative:** Try ExperimentalTable.removeNonNumericColumns - - **Reason:** More concise name. +**Note:** The original table is not modified. -Return a new table without the columns that contain non-numerical values. - -The original table is not modified. +**Parameters:** -Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `query` | `#!sds (row: Row) -> (shouldRemoveRow: Cell)` | The function that determines which rows to remove. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `projectedTable` | [`Table`][safeds.data.tabular.containers.Table] | A table without the columns that contain non-numerical values. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without the specified rows. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": ["z", "y"], "b": [1, 2]}); - val projectedTable = table.removeColumnsWithNonNumericalValues(); - // Table({"b": [1, 2]}) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.removeRows((row) -> row.getValue("a").eq(2)); + // Table({"a": [1, 3], "b": [4, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="586" - @Deprecated( - alternative="Try ExperimentalTable.removeNonNumericColumns", - reason="More concise name.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="459" @Pure - @PythonName("remove_columns_with_non_numerical_values") - fun removeColumnsWithNonNumericalValues() -> projectedTable: Table + @PythonName("remove_rows") + fun removeRows( + query: (row: Row) -> shouldRemoveRow: Cell + ) -> newTable: Table ``` -## `#!sds fun` removeDuplicateRows {#safeds.data.tabular.containers.Table.removeDuplicateRows data-toc-label='removeDuplicateRows'} +## `#!sds fun` removeRowsByColumn {#safeds.data.tabular.containers.Table.removeRowsByColumn data-toc-label='removeRowsByColumn'} -Return a new table with every duplicate row removed. +Return a new table without rows that satisfy a condition on a specific column. -The original table is not modified. +**Note:** The original table is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | +| `query` | `#!sds (cell: Cell) -> (shouldRemoveRow: Cell)` | The function that determines which rows to remove. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `filteredTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the duplicate rows removed. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without the specified rows. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2, 1], "b": [3, 4, 3]}); - val filteredTable = table.removeDuplicateRows(); - // Table({"a": [1, 2], "b": [3, 4]}) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.removeRowsByColumn("a", (cell) -> cell.eq(2)); + // Table({"a": [1, 3], "b": [4, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="610" + ```sds linenums="482" @Pure - @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> filteredTable: Table + @PythonName("remove_rows_by_column") + fun removeRowsByColumn( + name: String, + query: (cell: Cell) -> shouldRemoveRow: Cell + ) -> newTable: Table ``` ## `#!sds fun` removeRowsWithMissingValues {#safeds.data.tabular.containers.Table.removeRowsWithMissingValues data-toc-label='removeRowsWithMissingValues'} -Return a new table without the rows that contain missing values. +Return a new table without rows containing missing values in the specified columns. -The original table is not modified. +**Note:** The original table is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `columnNames` | [`List?`][safeds.lang.List] | Names of the columns to consider. If null, all columns are considered. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `filteredTable` | [`Table`][safeds.data.tabular.containers.Table] | A table without the rows that contain missing values. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without rows containing missing values in the specified columns. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, null], "b": [3, 4]}); - val filteredTable = table.removeRowsWithMissingValues(); - // Table({"a": [1], "b": [3]}) + val table = Table({"a": [1, null, 3], "b": [4, 5, null]}); + val result = table.removeRowsWithMissingValues(); + // Table({"a": [1], "b": [4]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="628" + ```sds linenums="505" @Pure @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues() -> filteredTable: Table + fun removeRowsWithMissingValues( + @PythonName("column_names") columnNames: List? = null + ) -> newTable: Table ``` ## `#!sds fun` removeRowsWithOutliers {#safeds.data.tabular.containers.Table.removeRowsWithOutliers data-toc-label='removeRowsWithOutliers'} -Return a new table without those rows that contain at least one outlier. +Return a new table without rows containing outliers in the specified columns. -We define an outlier as a value that has a distance of more than 3 standard deviations from the column mean. -Missing values are not considered outliers. They are also ignored during the calculation of the standard -deviation. +Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the +data point from the mean of the column divided by the standard deviation of the column. If the z-score is +greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the +calculation of the z-score. -The original table is not modified. +The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in +`column_names`. + +**Notes:** + +- The original table is not modified. +- This operation must fully load the data into memory, which can be expensive. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `columnNames` | [`List?`][safeds.lang.List] | Names of the columns to consider. If null, all numeric columns are considered. | `#!sds null` | +| `zScoreThreshold` | [`Float`][safeds.lang.Float] | The z-score threshold for detecting outliers. | `#!sds 3.0` | **Results:** | Name | Type | Description | |------|------|-------------| -| `filteredTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table without rows containing outliers. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table without rows containing outliers in the specified columns. | **Examples:** -```sds hl_lines="6" +```sds hl_lines="8" pipeline example { - val table = Table({ - "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3, 1000] - }); - val filteredTable = table.removeRowsWithOutliers(); - // Table({ - // "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - // "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3] - // }) + val table = Table( + { + "a": [1, 2, 3, 4, 5, 6, 1000, null], + "b": [1, 2, 3, 4, 5, 6, 7, 8], + } + ); + val result = table.removeRowsWithOutliers(zScoreThreshold=2.0); + // Table({"a": [1, 2, 3, 4, 5, 6, null], "b": [1, 2, 3, 4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="656" + ```sds linenums="544" @Pure @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers() -> filteredTable: Table + fun removeRowsWithOutliers( + @PythonName("column_names") columnNames: List? = null, + @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 + ) -> newTable: Table ``` ## `#!sds fun` renameColumn {#safeds.data.tabular.containers.Table.renameColumn data-toc-label='renameColumn'} -Return a new `Table` with a single column renamed. +Return a new table with a column renamed. -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `oldName` | [`String`][safeds.lang.String] | The old name of the target column. | - | -| `newName` | [`String`][safeds.lang.String] | The new name of the target column. | - | +| `oldName` | [`String`][safeds.lang.String] | The name of the column to rename. | - | +| `newName` | [`String`][safeds.lang.String] | The new name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The Table with the renamed column. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the column renamed. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val newTable = table.renameColumn("a", "c"); - // Table({"c": [1, 2], "b": [3, 4]}) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.renameColumn("a", "c"); + // Table({"c": [1, 2, 3], "b": [4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="677" + ```sds linenums="370" @Pure @PythonName("rename_column") fun renameColumn( @@ -2403,319 +1700,250 @@ pipeline example { ## `#!sds fun` replaceColumn {#safeds.data.tabular.containers.Table.replaceColumn data-toc-label='replaceColumn'} -Return a new table with the specified old column replaced by a list of new columns. +Return a new table with a column replaced by zero or more columns. -The order of columns is kept. - -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `oldColumnName` | [`String`][safeds.lang.String] | The name of the column to be replaced. | - | -| `newColumns` | [`List>`][safeds.lang.List] | The list of new columns replacing the old column. | - | +| `oldName` | [`String`][safeds.lang.String] | The name of the column to replace. | - | +| `newColumns` | `#!sds union, List>, Table>` | The new columns. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | A table with the old column replaced by the new columns. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the column replaced. | **Examples:** -```sds hl_lines="4" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val column = Column("c", [5, 6]); - val newTable = table.replaceColumn("a", [column]); - // Table({"c": [5, 6], "b": [3, 4]}) -} -``` -```sds hl_lines="5" +```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val column1 = Column("c", [5, 6]); - val column2 = Column("d", [7, 8]); - val newTable = table.replaceColumn("a", [column1, column2]); - // Table({"c": [5, 6], "d": [7, 8], "b": [3, 4]}) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.replaceColumn("a", []); + // Table({"b": [4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="713" + ```sds linenums="394" @Pure @PythonName("replace_column") fun replaceColumn( - @PythonName("old_column_name") oldColumnName: String, - @PythonName("new_columns") newColumns: List + @PythonName("old_name") oldName: String, + @PythonName("new_columns") newColumns: union, Table> ) -> newTable: Table ``` ## `#!sds fun` shuffleRows {#safeds.data.tabular.containers.Table.shuffleRows data-toc-label='shuffleRows'} -Return a new `Table` with randomly shuffled rows of this `Table`. +Return a new table with the rows shuffled. -The original table is not modified. +**Note:** The original table is not modified. **Results:** | Name | Type | Description | |------|------|-------------| -| `shuffledTable` | [`Table`][safeds.data.tabular.containers.Table] | The shuffled Table. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the rows shuffled. | **Examples:** ```sds hl_lines="3" pipeline example { val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - val shuffledTable = table.shuffleRows(); + val result = table.shuffleRows(); + // Table({"a": [3, 2, 1], "b": [6, 5, 4]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="733" + ```sds linenums="565" @Pure @PythonName("shuffle_rows") - fun shuffleRows() -> shuffledTable: Table + fun shuffleRows() -> newTable: Table ``` ## `#!sds fun` sliceRows {#safeds.data.tabular.containers.Table.sliceRows data-toc-label='sliceRows'} -Slice a part of the table into a new table. +Return a new table with a slice of rows. -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `start` | [`Int?`][safeds.lang.Int] | The first index of the range to be copied into a new table, None by default. | `#!sds null` | -| `end` | [`Int?`][safeds.lang.Int] | The last index of the range to be copied into a new table, None by default. | `#!sds null` | -| `step` | [`Int`][safeds.lang.Int] | The step size used to iterate through the table, 1 by default. | `#!sds 1` | +| `start` | [`Int`][safeds.lang.Int] | The start index of the slice. | `#!sds 0` | +| `length` | [`Int?`][safeds.lang.Int] | The length of the slice. If null, the slice contains all rows starting from `start`. Must greater than or equal to 0. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `slicedTable` | [`Table`][safeds.data.tabular.containers.Table] | The resulting table. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the slice of rows. | **Examples:** ```sds hl_lines="3" pipeline example { val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - val slicedTable = table.sliceRows(start = 1); + val result = table.sliceRows(start=1); // Table({"a": [2, 3], "b": [5, 6]}) } ``` ```sds hl_lines="3" pipeline example { val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - val slicedTable = table.sliceRows(end = 2); - // Table({"a": [1, 2], "b": [4, 5]}) -} -``` -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - val slicedTable = table.sliceRows(step = 2); - // Table({"a": [1, 3], "b": [4, 6]}) + val result = table.sliceRows(start=1, length=1); + // Table({"a": [2], "b": [5]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="769" + ```sds linenums="594" @Pure @PythonName("slice_rows") fun sliceRows( - start: Int? = null, - end: Int? = null, - step: Int = 1 - ) -> slicedTable: Table + start: Int = 0, + length: Int? = null + ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` sortColumns {#safeds.data.tabular.containers.Table.sortColumns data-toc-label='sortColumns'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** No use case. +## `#!sds fun` sortRows {#safeds.data.tabular.containers.Table.sortRows data-toc-label='sortRows'} -Sort the columns of a `Table` with the given comparator and return a new `Table`. +Return a new table with the rows sorted. -The comparator is a function that takes two columns `col1` and `col2` and -returns an integer: - -* If `col1` should be ordered before `col2`, the function should return a negative number. -* If `col1` should be ordered after `col2`, the function should return a positive number. -* If the original order of `col1` and `col2` should be kept, the function should return 0. - -If no comparator is given, the columns will be sorted alphabetically by their name. - -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `comparator` | `#!sds (column1: Column, column2: Column) -> (comparison: Int)` | The function used to compare two columns. | - | +| `keySelector` | `#!sds (row: Row) -> (key: Cell)` | The function that selects the key to sort by. | - | +| `descending` | [`Boolean`][safeds.lang.Boolean] | Whether to sort in descending order. | `#!sds false` | **Results:** | Name | Type | Description | |------|------|-------------| -| `sortedTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table with sorted columns. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the rows sorted. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val sortedTable = table.sortColumns((col1, col2) -> 1); - // Table({"a": [1, 2], "b": [3, 4]}) -} -``` -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val sortedTable = table.sortColumns((col1, col2) -> -1); - // Table({"b": [3, 4], "a": [1, 2]}) + val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + val result = table.sortRows((row) -> row.getValue("a").^sub(row.getValue("b"))); + // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="809" - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="618" @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (column1: Column, column2: Column) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows") + fun sortRows( + @PythonName("key_selector") keySelector: (row: Row) -> key: Cell, + descending: Boolean = false + ) -> newTable: Table ``` -## :warning:{ title="Deprecated" } `#!sds fun` sortRows {#safeds.data.tabular.containers.Table.sortRows data-toc-label='sortRows'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Try ExperimentalTable.sortRows - - **Reason:** Selecting a key is more ergonomic than a comparator. +## `#!sds fun` sortRowsByColumn {#safeds.data.tabular.containers.Table.sortRowsByColumn data-toc-label='sortRowsByColumn'} -Sort the rows of a `Table` with the given comparator and return a new `Table`. +Return a new table with the rows sorted by a specific column. -The comparator is a function that takes two rows `row1` and `row2` and -returns an integer: - -* If `row1` should be ordered before `row2`, the function should return a negative number. -* If `row1` should be ordered after `row2`, the function should return a positive number. -* If the original order of `row1` and `row2` should be kept, the function should return 0. - -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `comparator` | `#!sds (row1: Row, row2: Row) -> (comparison: Int)` | The function used to compare two rows. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column to sort by. | - | +| `descending` | [`Boolean`][safeds.lang.Boolean] | Whether to sort in descending order. | `#!sds false` | **Results:** | Name | Type | Description | |------|------|-------------| -| `sortedTable` | [`Table`][safeds.data.tabular.containers.Table] | A new table with sorted rows. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the rows sorted by the specified column. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val sortedTable = table.sortRows((row1, row2) -> 1); - // Table({"a": [1, 2], "b": [3, 4]}) -} -``` -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val sortedTable = table.sortRows((row1, row2) -> -1); - // Table({"a": [2, 1], "b": [4, 3]}) + val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + val result = table.sortRowsByColumn("a"); + // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="851" - @Deprecated( - alternative="Try ExperimentalTable.sortRows", - reason="Selecting a key is more ergonomic than a comparator.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="642" @Pure - @PythonName("sort_rows") - fun sortRows( - comparator: (row1: Row, row2: Row) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows_by_column") + fun sortRowsByColumn( + name: String, + descending: Boolean = false + ) -> newTable: Table ``` ## `#!sds fun` splitRows {#safeds.data.tabular.containers.Table.splitRows data-toc-label='splitRows'} -Split the table into two new tables. Consider using [Table.shuffleRows][safeds.data.tabular.containers.Table.shuffleRows] before splitting to ensure a random -distribution of rows in both tables. +Create two tables by splitting the rows of the current table. -The original table is not modified. +The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table +contains the remaining rows. + +**Notes:** + +- The original table is not modified. +- By default, the rows are shuffled before splitting. You can disable this by setting `shuffle` to false. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `ratioInFirst` | [`Float`][safeds.lang.Float] | How many rows should be in the first table, expressed as a ratio of the total number of rows. Must be between 0 and 1. | - | +| `percentageInFirst` | [`Float`][safeds.lang.Float] | The percentage of rows to include in the first table. Must be between 0 and 1. | - | +| `shuffle` | [`Boolean`][safeds.lang.Boolean] | Whether to shuffle the rows before splitting. | `#!sds true` | **Results:** | Name | Type | Description | |------|------|-------------| -| `first` | [`Table`][safeds.data.tabular.containers.Table] | The first table with the specified size. | -| `second` | [`Table`][safeds.data.tabular.containers.Table] | The second table with the remaining rows. | +| `firstTable` | [`Table`][safeds.data.tabular.containers.Table] | The first table. | +| `secondTable` | [`Table`][safeds.data.tabular.containers.Table] | The second table. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}); - val first, val second = table.splitRows(0.5); - // first: Table({"a": [1, 2], "b": [5, 6]}) - // second: Table({"a": [3, 4], "b": [7, 8]}) + val table = Table({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}); + val firstTable, val secondTable = table.splitRows(0.6); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="884" + ```sds linenums="672" @Pure @PythonName("split_rows") fun splitRows( - @PythonName("percentage_in_first") ratioInFirst: Float - ) -> (first: Table, second: Table) + @PythonName("percentage_in_first") percentageInFirst: Float, + shuffle: Boolean = true + ) -> (firstTable: Table, secondTable: Table) ``` ## `#!sds fun` summarizeStatistics {#safeds.data.tabular.containers.Table.summarizeStatistics data-toc-label='summarizeStatistics'} -Return a table with a number of statistical key values. - -The original table is not modified. +Return a table with important statistics about this table. **Results:** @@ -2727,14 +1955,14 @@ The original table is not modified. ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val statistics = table.summarizeStatistics(); + val table = Table({"a": [1, 3]}); + val result = table.summarizeStatistics(); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="296" + ```sds linenums="794" @Pure @PythonName("summarize_statistics") fun summarizeStatistics() -> statistics: Table @@ -2742,7 +1970,7 @@ pipeline example { ## `#!sds fun` toColumns {#safeds.data.tabular.containers.Table.toColumns data-toc-label='toColumns'} -Return a list of the columns. +Return the data of the table as a list of columns. **Results:** @@ -2754,15 +1982,14 @@ Return a list of the columns. ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); val columns = table.toColumns(); - // [Column("a", [1, 2]), Column("b", [3, 4])] } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1202" + ```sds linenums="809" @Pure @PythonName("to_columns") fun toColumns() -> columns: List @@ -2770,29 +1997,29 @@ pipeline example { ## `#!sds fun` toCsvFile {#safeds.data.tabular.containers.Table.toCsvFile data-toc-label='toCsvFile'} -Write the data from the table into a CSV file. +Write the table to a CSV file. -If the file and/or the directories do not exist they will be created. If the file already exists it will be -overwritten. +If the file and/or the parent directories do not exist, they will be created. If the file exists already, it +will be overwritten. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the output file. | - | +| `path` | [`String`][safeds.lang.String] | The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". | - | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - table.toCsvFile("path/to/file.csv"); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + table.toCsvFile("output.csv"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1106" + ```sds linenums="827" @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) @PythonName("to_csv_file") fun toCsvFile( @@ -2800,183 +2027,156 @@ pipeline example { ) ``` -## `#!sds fun` toExcelFile {#safeds.data.tabular.containers.Table.toExcelFile data-toc-label='toExcelFile'} +## `#!sds fun` toJsonFile {#safeds.data.tabular.containers.Table.toJsonFile data-toc-label='toJsonFile'} + +Write the table to a JSON file. -Write the data from the table into an Excel file. +If the file and/or the parent directories do not exist, they will be created. If the file exists already, it +will be overwritten. -Valid file extensions are `.xls`, '.xlsx', `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. -If the file and/or the directories do not exist, they will be created. If the file already exists, it will be -overwritten. +**Note:** This operation must fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the output file. | - | +| `path` | [`String`][safeds.lang.String] | The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". | - | +| `orientation` | `#!sds literal<"column", "row">` | The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but slower and less memory-efficient. | `#!sds "column"` | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - table.toExcelFile("path/to/file.xlsx"); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + table.toJsonFile("output.json"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1127" + ```sds linenums="868" @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) - @PythonName("to_excel_file") - fun toExcelFile( - path: String + @PythonName("to_json_file") + fun toJsonFile( + path: String, + orientation: literal<"column", "row"> = "column" ) ``` -## :warning:{ title="Deprecated" } `#!sds fun` toHtml {#safeds.data.tabular.containers.Table.toHtml data-toc-label='toHtml'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** None. - - **Reason:** No use case. +## `#!sds fun` toMap {#safeds.data.tabular.containers.Table.toMap data-toc-label='toMap'} -Return an HTML representation of the table. +Return a map that maps column names to column values. **Results:** | Name | Type | Description | |------|------|-------------| -| `html` | [`String`][safeds.lang.String] | The generated HTML. | +| `map` | [`Map>`][safeds.lang.Map] | Map representation of the table. | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val html = table.toHtml(); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.toMap(); + // {"a": [1, 2, 3], "b": [4, 5, 6]} } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1180" - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="845" @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("to_dict") + fun toMap() -> map: Map> ``` -## `#!sds fun` toJsonFile {#safeds.data.tabular.containers.Table.toJsonFile data-toc-label='toJsonFile'} +## `#!sds fun` toParquetFile {#safeds.data.tabular.containers.Table.toParquetFile data-toc-label='toParquetFile'} -Write the data from the table into a JSON file. +Write the table to a Parquet file. -If the file and/or the directories do not exist, they will be created. If the file already exists it will be -overwritten. +If the file and/or the parent directories do not exist, they will be created. If the file exists already, it +will be overwritten. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the output file. | - | +| `path` | [`String`][safeds.lang.String] | The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". | - | **Examples:** ```sds hl_lines="3" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - table.toJsonFile("path/to/file.json"); + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + table.toParquetFile("output.parquet"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1147" + ```sds linenums="889" @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) - @PythonName("to_json_file") - fun toJsonFile( + @PythonName("to_parquet_file") + fun toParquetFile( path: String ) ``` -## `#!sds fun` toMap {#safeds.data.tabular.containers.Table.toMap data-toc-label='toMap'} - -Return a map of column names to column values. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `map` | [`Map>`][safeds.lang.Map] | Map representation of the table. | - -**Examples:** - -```sds hl_lines="3" -pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val map = table.toMap(); - // {"a": [1, 2], "b": [3, 4]} -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="1165" - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - ``` +## `#!sds fun` toTabularDataset {#safeds.data.tabular.containers.Table.toTabularDataset data-toc-label='toTabularDataset'} -## :warning:{ title="Deprecated" } `#!sds fun` toRows {#safeds.data.tabular.containers.Table.toRows data-toc-label='toRows'} +Return a new `TabularDataset` with columns marked as a target, feature, or extra. -!!! warning "Deprecated" +- The target column is the column that a model should predict. +- Feature columns are columns that a model should use to make predictions. +- Extra columns are columns that are neither feature nor target. They can be used to provide additional context, + like an ID column. - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns +are specified, all columns except the target column are used as features. - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. +**Parameters:** -Return a list of the rows. +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | +| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither feature nor target. If null, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `rows` | [`List`][safeds.lang.List] | List of rows. | +| `dataset` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A new tabular dataset with the given target and feature names. | **Examples:** -```sds hl_lines="3" +```sds hl_lines="9" pipeline example { - val table = Table({"a": [1, 2], "b": [3, 4]}); - val rows = table.toRows(); - // [Row({"a": 1, "b": 3}), Row({"a": 2, "b": 4})] + val table = Table( + { + "item": ["apple", "milk", "beer"], + "price": [1.10, 1.19, 1.79], + "amount_bought": [74, 72, 51], + } + ); + val dataset = table.toTabularDataset(targetName="amount_bought", extraNames=["item"]); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1218" - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) + ```sds linenums="924" @Pure - @PythonName("to_rows") - fun toRows() -> rows: List + @PythonName("to_tabular_dataset") + fun toTabularDataset( + @PythonName("target_name") targetName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TabularDataset ``` -## `#!sds fun` toTabularDataset {#safeds.data.tabular.containers.Table.toTabularDataset data-toc-label='toTabularDataset'} +## `#!sds fun` toTimeSeriesDataset {#safeds.data.tabular.containers.Table.toTimeSeriesDataset data-toc-label='toTimeSeriesDataset'} -Return a new `TabularDataset` with columns marked as a target column or feature columns. +Return a new `TimeSeriesDataset` with columns marked as a target column, time or feature columns. The original table is not modified. @@ -2985,280 +2185,223 @@ The original table is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `targetName` | [`String`][safeds.lang.String] | Name of the target column. | - | -| `extraNames` | [`List`][safeds.lang.List] | Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the target column are used as features. | `#!sds []` | +| `timeName` | [`String`][safeds.lang.String] | Name of the time column. | - | +| `extraNames` | [`List?`][safeds.lang.List] | Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but the target column are used as features. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `dataset` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A new tabular dataset with the given target and extras. | +| `dataset` | [`TimeSeriesDataset`][safeds.data.labeled.containers.TimeSeriesDataset] | A new time series dataset with the given target and feature names. | **Examples:** -```sds hl_lines="6" -pipeline example { - val table = Table({ - "age": [23, 16], - "survived": [ 0, 1], - }); - val dataset = table.toTabularDataset("survived"); -} -``` -```sds hl_lines="7" +```sds hl_lines="9" pipeline example { - val table = Table({ - "id": [ 1, 2], - "age": [23, 16], - "survived": [ 0, 1], - }); - val dataset = table.toTabularDataset("target", extraNames = ["id"]); + val table = Table( + { + "day": [0, 1, 2], + "price": [1.10, 1.19, 1.79], + "amount_bought": [74, 72, 51], + } + ); + val dataset = table.toTimeSeriesDataset(targetName="amount_bought", timeName= "day"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="1261" + ```sds linenums="955" @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( + @PythonName("to_time_series_dataset") + fun toTimeSeriesDataset( @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List = [] - ) -> dataset: TabularDataset + @PythonName("time_name") timeName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TimeSeriesDataset ``` ## `#!sds fun` transformColumn {#safeds.data.tabular.containers.Table.transformColumn data-toc-label='transformColumn'} -Return a new `Table` with the provided column transformed by calling the provided transformer. +Return a new table with a column transformed. -The original table is not modified. +**Note:** The original table is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | - | - | -| `transformer` | `#!sds (row: Row) -> (newColumnValue: Any?)` | - | - | +| `name` | [`String`][safeds.lang.String] | The name of the column to transform. | - | +| `transformer` | `#!sds (cell: Cell) -> (transformedCell: Cell)` | The function that transforms the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the transformed column. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The table with the transformed column. | **Examples:** -```sds hl_lines="6" +```sds hl_lines="3" pipeline example { - val prices = Table({ - "product": ["apple", "banana", "cherry"], - "price": [ 100, 2, 4], - }); - val discountedPrices = prices.transformColumn("price", (row) -> - row.getValue("price") as (Int) * 0.5 - ); - // Table({ - // "product": ["apple", "banana", "cherry"], - // "price": [ 50, 1, 2], - // }) + val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + val result = table.transformColumn("a", (cell) -> cell.add(1)); + // Table({"a": [2, 3, 4], "b": [4, 5, 6]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="912" + ```sds linenums="418" @Pure @PythonName("transform_column") fun transformColumn( name: String, - transformer: (row: Row) -> newColumnValue: Any? - ) -> transformedTable: Table + transformer: (cell: Cell) -> transformedCell: Cell + ) -> newTable: Table ``` ## `#!sds fun` transformTable {#safeds.data.tabular.containers.Table.transformTable data-toc-label='transformTable'} -Return a new `Table` with a learned transformation applied to this table. +Return a new table transformed by a **fitted** transformer. -The original table is not modified. +**Notes:** + +- The original table is not modified. +- Depending on the transformer, this operation might fully load the data into memory, which can be expensive. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `transformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The transformer which transforms the given table. | - | +| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer to apply. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `newTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | **Examples:** ```sds hl_lines="4" pipeline example { - val table = Table({"a": [1, null], "b": [3, 4]}); - val imputer = Imputer(Imputer.Strategy.Mean).fit(table, ["a"]); - val transformedTable = table.transformTable(imputer); - // Table({"a": [1, 1], "b": [3, 4]}) + val table = Table({"a": [1, 2, 3]}); + val transformer = RangeScaler(min=0.0, max=1.0).fit(table, ["a"]); + val result = table.transformTable(transformer); + // Table({"a": [0, 0.5, 1]}) } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="936" + ```sds linenums="777" @Pure @PythonName("transform_table") fun transformTable( - transformer: TableTransformer - ) -> transformedTable: Table + @PythonName("fitted_transformer") fittedTransformer: TableTransformer + ) -> newTable: Table ``` ## `#!sds static fun` fromColumns {#safeds.data.tabular.containers.Table.fromColumns data-toc-label='fromColumns'} -Return a table created from a list of columns. +Create a table from a list of columns. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `columns` | [`List>`][safeds.lang.List] | The columns to be combined. They need to have the same size. | - | +| `columns` | `#!sds union, List>>` | The columns. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | The generated table. | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | The created table. | **Examples:** ```sds hl_lines="4" pipeline example { - val column1 = Column("a", [1, 2]); - val column2 = Column("b", [3, 4]); - val table = Table.fromColumns([column1, column2]); + val a = Column("a", [1, 2, 3]); + val b = Column("b", [4, 5, 6]); + val result = Table.fromColumns([a, b]); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="169" + ```sds linenums="72" @Pure @PythonName("from_columns") static fun fromColumns( - columns: List + columns: union> ) -> table: Table ``` ## `#!sds static fun` fromCsvFile {#safeds.data.tabular.containers.Table.fromCsvFile data-toc-label='fromCsvFile'} -Read data from a CSV file into a table. +Create a table from a CSV file. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the CSV file. | - | +| `path` | [`String`][safeds.lang.String] | The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". | - | +| `separator` | [`String`][safeds.lang.String] | The separator between the values in the CSV file. | `#!sds ","` | **Results:** | Name | Type | Description | |------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | The table created from the CSV file. | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | The created table. | **Examples:** ```sds hl_lines="2" pipeline example { - val table = Table.fromCsvFile("path/to/file.csv"); + val result = Table.fromCsvFile("input.csv"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="87" + ```sds linenums="91" @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) @PythonName("from_csv_file") static fun fromCsvFile( - path: String - ) -> table: Table - ``` - -## :warning:{ title="Deprecated" } `#!sds static fun` fromExcelFile {#safeds.data.tabular.containers.Table.fromExcelFile data-toc-label='fromExcelFile'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. - - - **Alternative:** Table.fromCsvFile - - **Reason:** Requires a heavy depencency just for two methods. - -Read data from an Excel file into a table. - -Valid file extensions are `.xls`, `.xlsx`, `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the Excel file. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | The table created from the Excel file. | - -**Examples:** - -```sds hl_lines="2" -pipeline example { - val table = Table.fromExcelFile("path/to/file.xlsx"); -} -``` - -??? quote "Stub code in `Table.sdsstub`" - - ```sds linenums="107" - @Deprecated( - alternative="Table.fromCsvFile", - reason="Requires a heavy depencency just for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_excel_file") - static fun fromExcelFile( - path: String + path: String, + separator: String = "," ) -> table: Table ``` ## `#!sds static fun` fromJsonFile {#safeds.data.tabular.containers.Table.fromJsonFile data-toc-label='fromJsonFile'} -Read data from a JSON file into a table. +Create a table from a JSON file. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `path` | [`String`][safeds.lang.String] | The path to the JSON file. | - | +| `path` | [`String`][safeds.lang.String] | The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | The table created from the JSON file. | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | The created table. | **Examples:** ```sds hl_lines="2" pipeline example { - val table = Table.fromJsonFile("path/to/file.json"); + val result = Table.fromJsonFile("input.json"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="131" + ```sds linenums="129" @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) @PythonName("from_json_file") static fun fromJsonFile( @@ -3268,13 +2411,13 @@ pipeline example { ## `#!sds static fun` fromMap {#safeds.data.tabular.containers.Table.fromMap data-toc-label='fromMap'} -Create a table from a map of column names to column values. +Create a table from a map that maps column names to column values. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `data` | [`Map>`][safeds.lang.Map] | The data. | - | +| `data` | [`Map>`][safeds.lang.Map] | The data. | - | **Results:** @@ -3284,67 +2427,53 @@ Create a table from a map of column names to column values. **Examples:** -```sds hl_lines="2" +```sds hl_lines="3" pipeline example { - val table = Table.fromMap({"a": [1, 2], "b": [3, 4]}); + val data = {"a'": [1, 2, 3], "b": [4, 5, 6]}; + val result = Table.fromMap(data); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="149" + ```sds linenums="111" @Pure @PythonName("from_dict") static fun fromMap( - data: Map> + data: Map> ) -> table: Table ``` -## :warning:{ title="Deprecated" } `#!sds static fun` fromRows {#safeds.data.tabular.containers.Table.fromRows data-toc-label='fromRows'} - -!!! warning "Deprecated" - - This function is deprecated since version **0.15.0** and will be removed in version **0.16.0**. +## `#!sds static fun` fromParquetFile {#safeds.data.tabular.containers.Table.fromParquetFile data-toc-label='fromParquetFile'} - - **Alternative:** None. - - **Reason:** This interface cannot be implemented efficiently. - -Return a table created from a list of rows. +Create a table from a Parquet file. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `rows` | [`List`][safeds.lang.List] | The rows to be combined. They need to have a matching schema. | - | +| `path` | [`String`][safeds.lang.String] | The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `table` | [`Table`][safeds.data.tabular.containers.Table] | The generated table. | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | The created table. | **Examples:** -```sds hl_lines="4" +```sds hl_lines="2" pipeline example { - val row1 = Row({"a": 1, "b": 3}); - val row2 = Row({"a": 2, "b": 4}); - val table = Table.fromRows([row1, row2]); + val result = Table.fromParquetFile("input.parquet"); } ``` ??? quote "Stub code in `Table.sdsstub`" - ```sds linenums="189" - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("from_rows") - static fun fromRows( - rows: List + ```sds linenums="147" + @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) + @PythonName("from_parquet_file") + static fun fromParquetFile( + path: String ) -> table: Table ``` diff --git a/docs/api/safeds/data/tabular/plotting/ColumnPlotter.md b/docs/api/safeds/data/tabular/plotting/ColumnPlotter.md new file mode 100644 index 000000000..67143cb30 --- /dev/null +++ b/docs/api/safeds/data/tabular/plotting/ColumnPlotter.md @@ -0,0 +1,178 @@ +# `#!sds class` ColumnPlotter {#safeds.data.tabular.plotting.ColumnPlotter data-toc-label='ColumnPlotter'} + +A class that contains plotting methods for a column. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `column` | [`Column`][safeds.data.tabular.containers.Column] | The column to plot. | - | + +**Examples:** + +```sds +pipeline example { + val column = Column("test", [1, 2, 3]); + val plotter = column.plot; +} +``` + +??? quote "Stub code in `ColumnPlotter.sdsstub`" + + ```sds linenums="16" + class ColumnPlotter( + column: Column + ) { + /** + * Create a box plot for the values in the column. This is only possible for numeric columns. + * + * @result plot The box plot as an image. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3]); + * val boxplot = column.plot.boxPlot(); + * } + */ + @Pure + @PythonName("box_plot") + fun boxPlot() -> plot: Image + + /** + * Create a histogram for the values in the column. + * + * @param maxBinCount The maximum number of bins to use in the histogram. Default is 10. + * + * @result plot The plot as an image. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3]); + * val histogram = column.plot.histogram(); + * } + */ + @Pure + fun histogram( + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } + + /** + * Create a lag plot for the values in the column. + * + * @param lag The amount of lag. + * + * @result plot The plot as an image. + * + * @example + * pipeline example { + * val column = Column("values", [1, 2, 3, 4]); + * val image = column.plot.lagPlot(2); + * } + */ + @Pure + @PythonName("lag_plot") + fun lagPlot( + lag: Int + ) -> plot: Image + } + ``` + +## `#!sds fun` boxPlot {#safeds.data.tabular.plotting.ColumnPlotter.boxPlot data-toc-label='boxPlot'} + +Create a box plot for the values in the column. This is only possible for numeric columns. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `plot` | [`Image`][safeds.data.image.containers.Image] | The box plot as an image. | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("test", [1, 2, 3]); + val boxplot = column.plot.boxPlot(); +} +``` + +??? quote "Stub code in `ColumnPlotter.sdsstub`" + + ```sds linenums="30" + @Pure + @PythonName("box_plot") + fun boxPlot() -> plot: Image + ``` + +## `#!sds fun` histogram {#safeds.data.tabular.plotting.ColumnPlotter.histogram data-toc-label='histogram'} + +Create a histogram for the values in the column. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `maxBinCount` | [`Int`][safeds.lang.Int] | The maximum number of bins to use in the histogram. Default is 10. | `#!sds 10` | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `plot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("test", [1, 2, 3]); + val histogram = column.plot.histogram(); +} +``` + +??? quote "Stub code in `ColumnPlotter.sdsstub`" + + ```sds linenums="47" + @Pure + fun histogram( + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } + ``` + +## `#!sds fun` lagPlot {#safeds.data.tabular.plotting.ColumnPlotter.lagPlot data-toc-label='lagPlot'} + +Create a lag plot for the values in the column. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `lag` | [`Int`][safeds.lang.Int] | The amount of lag. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `plot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | + +**Examples:** + +```sds hl_lines="3" +pipeline example { + val column = Column("values", [1, 2, 3, 4]); + val image = column.plot.lagPlot(2); +} +``` + +??? quote "Stub code in `ColumnPlotter.sdsstub`" + + ```sds linenums="67" + @Pure + @PythonName("lag_plot") + fun lagPlot( + lag: Int + ) -> plot: Image + ``` diff --git a/docs/api/safeds/data/tabular/plotting/ExperimentalColumnPlotter.md b/docs/api/safeds/data/tabular/plotting/ExperimentalColumnPlotter.md deleted file mode 100644 index e6fd5c3d1..000000000 --- a/docs/api/safeds/data/tabular/plotting/ExperimentalColumnPlotter.md +++ /dev/null @@ -1,181 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalColumnPlotter {#safeds.data.tabular.plotting.ExperimentalColumnPlotter data-toc-label='ExperimentalColumnPlotter'} - -A class that contains plotting methods for a column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `column` | [`ExperimentalColumn`][safeds.data.tabular.containers.ExperimentalColumn] | The column to plot. | - | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // plotter = column.plot -} -``` - -??? quote "Stub code in `ExperimentalColumnPlotter.sdsstub`" - - ```sds linenums="18" - class ExperimentalColumnPlotter( - column: ExperimentalColumn - ) { - /** - * Create a box plot for the values in the column. This is only possible for numeric columns. - * - * @result boxPlot The box plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // boxplot = column.plot.box_plot() - * } - */ - @Pure - @PythonName("box_plot") - fun boxPlot() -> boxPlot: Image - - /** - * Create a histogram for the values in the column. - * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. - * - * @result histogram The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // histogram = column.plot.histogram() - * } - */ - @Pure - fun histogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> histogram: Image - - /** - * Create a lag plot for the values in the column. - * - * @param lag The amount of lag. - * - * @result lagPlot The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("values", [1, 2, 3, 4]) - * // image = column.plot.lag_plot(2) - * } - */ - @Pure - @PythonName("lag_plot") - fun lagPlot( - lag: Int - ) -> lagPlot: Image - } - ``` - -## `#!sds fun` boxPlot {#safeds.data.tabular.plotting.ExperimentalColumnPlotter.boxPlot data-toc-label='boxPlot'} - -Create a box plot for the values in the column. This is only possible for numeric columns. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `boxPlot` | [`Image`][safeds.data.image.containers.Image] | The box plot as an image. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // boxplot = column.plot.box_plot() -} -``` - -??? quote "Stub code in `ExperimentalColumnPlotter.sdsstub`" - - ```sds linenums="33" - @Pure - @PythonName("box_plot") - fun boxPlot() -> boxPlot: Image - ``` - -## `#!sds fun` histogram {#safeds.data.tabular.plotting.ExperimentalColumnPlotter.histogram data-toc-label='histogram'} - -Create a histogram for the values in the column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to use in the histogram. Default is 10. | `#!sds 10` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `histogram` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds hl_lines="4" -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("test", [1, 2, 3]) - // histogram = column.plot.histogram() -} -``` - -??? quote "Stub code in `ExperimentalColumnPlotter.sdsstub`" - - ```sds linenums="51" - @Pure - fun histogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> histogram: Image - ``` - -## `#!sds fun` lagPlot {#safeds.data.tabular.plotting.ExperimentalColumnPlotter.lagPlot data-toc-label='lagPlot'} - -Create a lag plot for the values in the column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `lag` | [`Int`][safeds.lang.Int] | The amount of lag. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `lagPlot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalColumn - // column = ExperimentalColumn("values", [1, 2, 3, 4]) - // image = column.plot.lag_plot(2) -} -``` - -??? quote "Stub code in `ExperimentalColumnPlotter.sdsstub`" - - ```sds linenums="70" - @Pure - @PythonName("lag_plot") - fun lagPlot( - lag: Int - ) -> lagPlot: Image - ``` diff --git a/docs/api/safeds/data/tabular/plotting/ExperimentalTablePlotter.md b/docs/api/safeds/data/tabular/plotting/TablePlotter.md similarity index 50% rename from docs/api/safeds/data/tabular/plotting/ExperimentalTablePlotter.md rename to docs/api/safeds/data/tabular/plotting/TablePlotter.md index 5444979d7..c33778de2 100644 --- a/docs/api/safeds/data/tabular/plotting/ExperimentalTablePlotter.md +++ b/docs/api/safeds/data/tabular/plotting/TablePlotter.md @@ -1,4 +1,4 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalTablePlotter {#safeds.data.tabular.plotting.ExperimentalTablePlotter data-toc-label='ExperimentalTablePlotter'} +# `#!sds class` TablePlotter {#safeds.data.tabular.plotting.TablePlotter data-toc-label='TablePlotter'} A class that contains plotting methods for a table. @@ -6,22 +6,22 @@ A class that contains plotting methods for a table. | Name | Type | Description | Default | |------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to plot. | - | +| `table` | [`Table`][safeds.data.tabular.containers.Table] | The table to plot. | - | **Examples:** ```sds pipeline example { - val table = ExperimentalTable({"test": [1, 2, 3]}); + val table = Table({"test": [1, 2, 3]}); val plotter = table.plot; } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="18" - class ExperimentalTablePlotter( - table: ExperimentalTable + ```sds linenums="17" + class TablePlotter( + table: Table ) { /** * Plot a boxplot for every numerical column. @@ -30,9 +30,8 @@ pipeline example { * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table({"a":[1, 2], "b": [3, 42]}) - * // image = table.plot_boxplots() + * val table = Table({"a":[1, 2], "b": [3, 42]}); + * val image = table.plot.boxPlots(); * } */ @Pure @@ -46,9 +45,8 @@ pipeline example { * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table.from_dict({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}) - * // image = table.plot_correlation_heatmap() + * val table = Table({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}); + * val image = table.plot.correlationHeatmap(); * } */ @Pure @@ -58,21 +56,22 @@ pipeline example { /** * Plot a histogram for every column. * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. + * @param maxBinCount The maximum number of bins to use in the histogram. Default is 10. * * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}) - * // image = table.plot_histograms() + * val table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}); + * val image = table.plot.histograms(); * } */ @Pure fun histograms( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } /** * Create a line plot for two columns in the table. @@ -80,18 +79,17 @@ pipeline example { * @param xName The name of the column to be plotted on the x-axis. * @param yName The name of the column to be plotted on the y-axis. * - * @result linePlot The plot as an image. + * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5], - * // "b": [2, 3, 4, 5, 6], - * // } - * // ) - * // image = table.plot.line_plot("a", "b") + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5], + * "b": [2, 3, 4, 5, 6], + * } + * ); + * val image = table.plot.linePlot("a", "b"); * } */ @Pure @@ -99,7 +97,7 @@ pipeline example { fun linePlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> linePlot: Image + ) -> plot: Image /** * Create a scatter plot for two columns in the table. @@ -107,18 +105,17 @@ pipeline example { * @param xName The name of the column to be plotted on the x-axis. * @param yName The name of the column to be plotted on the y-axis. * - * @result scatterPlot The plot as an image. + * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5], - * // "b": [2, 3, 4, 5, 6], - * // } - * // ) - * // image = table.plot.scatter_plot("a", "b") + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5], + * "b": [2, 3, 4, 5, 6], + * } + * ); + * val image = table.plot.scatterPlot("a", "b"); * } */ @Pure @@ -126,11 +123,11 @@ pipeline example { fun scatterPlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> scatterPlot: Image + ) -> plot: Image } ``` -## `#!sds fun` boxPlots {#safeds.data.tabular.plotting.ExperimentalTablePlotter.boxPlots data-toc-label='boxPlots'} +## `#!sds fun` boxPlots {#safeds.data.tabular.plotting.TablePlotter.boxPlots data-toc-label='boxPlots'} Plot a boxplot for every numerical column. @@ -142,23 +139,22 @@ Plot a boxplot for every numerical column. **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // from safeds.data.tabular.containers import Table - // table = Table({"a":[1, 2], "b": [3, 42]}) - // image = table.plot_boxplots() + val table = Table({"a":[1, 2], "b": [3, 42]}); + val image = table.plot.boxPlots(); } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="33" + ```sds linenums="31" @Pure @PythonName("box_plots") fun boxPlots() -> plot: Image ``` -## `#!sds fun` correlationHeatmap {#safeds.data.tabular.plotting.ExperimentalTablePlotter.correlationHeatmap data-toc-label='correlationHeatmap'} +## `#!sds fun` correlationHeatmap {#safeds.data.tabular.plotting.TablePlotter.correlationHeatmap data-toc-label='correlationHeatmap'} Plot a correlation heatmap for all numerical columns of this `Table`. @@ -170,23 +166,22 @@ Plot a correlation heatmap for all numerical columns of this `Table`. **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // from safeds.data.tabular.containers import Table - // table = Table.from_dict({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}) - // image = table.plot_correlation_heatmap() + val table = Table({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}); + val image = table.plot.correlationHeatmap(); } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="49" + ```sds linenums="46" @Pure @PythonName("correlation_heatmap") fun correlationHeatmap() -> plot: Image ``` -## `#!sds fun` histograms {#safeds.data.tabular.plotting.ExperimentalTablePlotter.histograms data-toc-label='histograms'} +## `#!sds fun` histograms {#safeds.data.tabular.plotting.TablePlotter.histograms data-toc-label='histograms'} Plot a histogram for every column. @@ -194,7 +189,7 @@ Plot a histogram for every column. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to use in the histogram. Default is 10. | `#!sds 10` | +| `maxBinCount` | [`Int`][safeds.lang.Int] | The maximum number of bins to use in the histogram. Default is 10. | `#!sds 10` | **Results:** @@ -204,24 +199,25 @@ Plot a histogram for every column. **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // from safeds.data.tabular.containers import Table - // table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}) - // image = table.plot_histograms() + val table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}); + val image = table.plot.histograms(); } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="67" + ```sds linenums="63" @Pure fun histograms( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } ``` -## `#!sds fun` linePlot {#safeds.data.tabular.plotting.ExperimentalTablePlotter.linePlot data-toc-label='linePlot'} +## `#!sds fun` linePlot {#safeds.data.tabular.plotting.TablePlotter.linePlot data-toc-label='linePlot'} Create a line plot for two columns in the table. @@ -236,35 +232,34 @@ Create a line plot for two columns in the table. | Name | Type | Description | |------|------|-------------| -| `linePlot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | +| `plot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | **Examples:** -```sds +```sds hl_lines="8" pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable( - // { - // "a": [1, 2, 3, 4, 5], - // "b": [2, 3, 4, 5, 6], - // } - // ) - // image = table.plot.line_plot("a", "b") + val table = Table( + { + "a": [1, 2, 3, 4, 5], + "b": [2, 3, 4, 5, 6], + } + ); + val image = table.plot.linePlot("a", "b"); } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="92" + ```sds linenums="89" @Pure @PythonName("line_plot") fun linePlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> linePlot: Image + ) -> plot: Image ``` -## `#!sds fun` scatterPlot {#safeds.data.tabular.plotting.ExperimentalTablePlotter.scatterPlot data-toc-label='scatterPlot'} +## `#!sds fun` scatterPlot {#safeds.data.tabular.plotting.TablePlotter.scatterPlot data-toc-label='scatterPlot'} Create a scatter plot for two columns in the table. @@ -279,30 +274,29 @@ Create a scatter plot for two columns in the table. | Name | Type | Description | |------|------|-------------| -| `scatterPlot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | +| `plot` | [`Image`][safeds.data.image.containers.Image] | The plot as an image. | **Examples:** -```sds +```sds hl_lines="8" pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable( - // { - // "a": [1, 2, 3, 4, 5], - // "b": [2, 3, 4, 5, 6], - // } - // ) - // image = table.plot.scatter_plot("a", "b") + val table = Table( + { + "a": [1, 2, 3, 4, 5], + "b": [2, 3, 4, 5, 6], + } + ); + val image = table.plot.scatterPlot("a", "b"); } ``` -??? quote "Stub code in `ExperimentalTablePlotter.sdsstub`" +??? quote "Stub code in `TablePlotter.sdsstub`" - ```sds linenums="119" + ```sds linenums="115" @Pure @PythonName("scatter_plot") fun scatterPlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> scatterPlot: Image + ) -> plot: Image ``` diff --git a/docs/api/safeds/data/tabular/transformation/Discretizer.md b/docs/api/safeds/data/tabular/transformation/Discretizer.md index 7afc8f46b..c0627e132 100644 --- a/docs/api/safeds/data/tabular/transformation/Discretizer.md +++ b/docs/api/safeds/data/tabular/transformation/Discretizer.md @@ -8,7 +8,7 @@ The Discretizer bins continuous data into intervals. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to be created. | `#!sds 5` | +| `binCount` | [`Int`][safeds.lang.Int] | The number of bins to be created. | `#!sds 5` | **Examples:** @@ -25,28 +25,57 @@ pipeline example { ```sds linenums="19" class Discretizer( - @PythonName("number_of_bins") const numberOfBins: Int = 5 + @PythonName("number_of_bins") const binCount: Int = 5 ) sub TableTransformer where { - numberOfBins >= 2 + binCount >= 2 } { + /** + * The number of bins to be created. + */ + @PythonName("number_of_bins") attr binCount: Int + /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Discretizer + ) -> fittedTransformer: Discretizer + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: Discretizer, transformedTable: Table) } ``` +## `#!sds attr` binCount {#safeds.data.tabular.transformation.Discretizer.binCount data-toc-label='binCount'} + +The number of bins to be created. + +**Type:** [`Int`][safeds.lang.Int] + ## `#!sds attr` isFitted {#safeds.data.tabular.transformation.Discretizer.isFitted data-toc-label='isFitted'} Whether the transformer is fitted. @@ -64,114 +93,60 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`Discretizer`][safeds.data.tabular.transformation.Discretizer] | The fitted transformer. | +| `fittedTransformer` | [`Discretizer`][safeds.data.tabular.transformation.Discretizer] | The fitted transformer. | ??? quote "Stub code in `Discretizer.sdsstub`" - ```sds linenums="34" + ```sds linenums="39" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Discretizer + ) -> fittedTransformer: Discretizer ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.Discretizer.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`Discretizer`][safeds.data.tabular.transformation.Discretizer] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `Discretizer.sdsstub`" - ```sds linenums="82" + ```sds linenums="56" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.Discretizer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.Discretizer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.Discretizer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: Discretizer, transformedTable: Table) ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.Discretizer.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -183,7 +158,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -191,5 +166,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalDiscretizer.md b/docs/api/safeds/data/tabular/transformation/ExperimentalDiscretizer.md deleted file mode 100644 index 702f8368b..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalDiscretizer.md +++ /dev/null @@ -1,182 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalDiscretizer {#safeds.data.tabular.transformation.ExperimentalDiscretizer data-toc-label='ExperimentalDiscretizer'} - -The Discretizer bins continuous data into intervals. - -**Parent type:** [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `numberOfBins` | [`Int`][safeds.lang.Int] | The number of bins to be created. | `#!sds 5` | - -??? quote "Stub code in `ExperimentalDiscretizer.sdsstub`" - - ```sds linenums="12" - class ExperimentalDiscretizer( - @PythonName("number_of_bins") numberOfBins: Int = 5 - ) sub ExperimentalTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalDiscretizer - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalDiscretizer.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalDiscretizer.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalDiscretizer`][safeds.data.tabular.transformation.ExperimentalDiscretizer] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalDiscretizer.sdsstub`" - - ```sds linenums="25" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalDiscretizer - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalDiscretizer.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalDiscretizer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalDiscretizer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalDiscretizer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalDiscretizer.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.md b/docs/api/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.md deleted file mode 100644 index 0b91790f9..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.md +++ /dev/null @@ -1,208 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalInvertibleTableTransformer {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer data-toc-label='ExperimentalInvertibleTableTransformer'} - -A `TableTransformer` that can also undo the learned transformation after it has been applied. - -**Parent type:** [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] - -**Inheritors:** - -- [`ExperimentalLabelEncoder`][safeds.data.tabular.transformation.ExperimentalLabelEncoder] -- [`ExperimentalOneHotEncoder`][safeds.data.tabular.transformation.ExperimentalOneHotEncoder] -- [`ExperimentalRangeScaler`][safeds.data.tabular.transformation.ExperimentalRangeScaler] -- [`ExperimentalStandardScaler`][safeds.data.tabular.transformation.ExperimentalStandardScaler] - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="10" - class ExperimentalInvertibleTableTransformer() sub ExperimentalTableTransformer { - /** - * Undo the learned transformation. - * - * The table is not modified. - * - * @param transformedTable The table to be transformed back to the original version. - * - * @result originalTable The original table. - */ - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="25" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalTableTransformer - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.inverseTransform data-toc-label='inverseTransform'} - -Undo the learned transformation. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to be transformed back to the original version. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `originalTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The original table. | - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalLabelEncoder.md b/docs/api/safeds/data/tabular/transformation/ExperimentalLabelEncoder.md deleted file mode 100644 index 31240f339..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalLabelEncoder.md +++ /dev/null @@ -1,202 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalLabelEncoder {#safeds.data.tabular.transformation.ExperimentalLabelEncoder data-toc-label='ExperimentalLabelEncoder'} - -The LabelEncoder encodes one or more given columns into labels. - -**Parent type:** [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] - -??? quote "Stub code in `ExperimentalLabelEncoder.sdsstub`" - - ```sds linenums="10" - class ExperimentalLabelEncoder() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalLabelEncoder - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalLabelEncoder`][safeds.data.tabular.transformation.ExperimentalLabelEncoder] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalLabelEncoder.sdsstub`" - - ```sds linenums="21" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalLabelEncoder - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.inverseTransform data-toc-label='inverseTransform'} - -Undo the learned transformation. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to be transformed back to the original version. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `originalTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The original table. | - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalLabelEncoder.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.md b/docs/api/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.md deleted file mode 100644 index 4cde15cda..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.md +++ /dev/null @@ -1,237 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalOneHotEncoder {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder data-toc-label='ExperimentalOneHotEncoder'} - -A way to deal with categorical features that is particularly useful for unordered (i.e. nominal) data. - -It replaces a column with a set of columns, each representing a unique value in the original column. The value of -each new column is 1 if the original column had that value, and 0 otherwise. Take the following table as an -example: - -| col1 | -|------| -| "a" | -| "b" | -| "c" | -| "a" | - -The one-hot encoding of this table is: - -| col1__a | col1__b | col1__c | -|---------|---------|---------| -| 1 | 0 | 0 | -| 0 | 1 | 0 | -| 0 | 0 | 1 | -| 1 | 0 | 0 | - -The name "one-hot" comes from the fact that each row has exactly one 1 in it, and the rest of the values are 0s. -One-hot encoding is closely related to dummy variable / indicator variables, which are used in statistics. - -**Parent type:** [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import Table - // from safeds.data.tabular.transformation import OneHotEncoder - // table = Table({"col1": ["a", "b", "c", "a"]}) - // transformer = OneHotEncoder() - // transformer.fit_and_transform(table, ["col1"])[1] -} -``` - -??? quote "Stub code in `ExperimentalOneHotEncoder.sdsstub`" - - ```sds linenums="42" - class ExperimentalOneHotEncoder() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalOneHotEncoder - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalOneHotEncoder`][safeds.data.tabular.transformation.ExperimentalOneHotEncoder] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalOneHotEncoder.sdsstub`" - - ```sds linenums="53" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalOneHotEncoder - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.inverseTransform data-toc-label='inverseTransform'} - -Undo the learned transformation. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to be transformed back to the original version. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `originalTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The original table. | - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalOneHotEncoder.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalRangeScaler.md b/docs/api/safeds/data/tabular/transformation/ExperimentalRangeScaler.md deleted file mode 100644 index 17bc0e292..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalRangeScaler.md +++ /dev/null @@ -1,212 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalRangeScaler {#safeds.data.tabular.transformation.ExperimentalRangeScaler data-toc-label='ExperimentalRangeScaler'} - -The RangeScaler transforms column values by scaling each value to a given range. - -**Parent type:** [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `min` | [`Float`][safeds.lang.Float] | The minimum of the new range after the transformation | `#!sds 0.0` | -| `max` | [`Float`][safeds.lang.Float] | The maximum of the new range after the transformation | `#!sds 1.0` | - -??? quote "Stub code in `ExperimentalRangeScaler.sdsstub`" - - ```sds linenums="13" - class ExperimentalRangeScaler( - @PythonName("min_") min: Float = 0.0, - @PythonName("max_") max: Float = 1.0 - ) sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalRangeScaler - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalRangeScaler.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalRangeScaler.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalRangeScaler`][safeds.data.tabular.transformation.ExperimentalRangeScaler] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalRangeScaler.sdsstub`" - - ```sds linenums="27" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalRangeScaler - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalRangeScaler.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalRangeScaler.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalRangeScaler.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalRangeScaler.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.ExperimentalRangeScaler.inverseTransform data-toc-label='inverseTransform'} - -Undo the learned transformation. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to be transformed back to the original version. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `originalTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The original table. | - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalRangeScaler.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalSimpleImputer.md b/docs/api/safeds/data/tabular/transformation/ExperimentalSimpleImputer.md deleted file mode 100644 index b08399812..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalSimpleImputer.md +++ /dev/null @@ -1,304 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalSimpleImputer {#safeds.data.tabular.transformation.ExperimentalSimpleImputer data-toc-label='ExperimentalSimpleImputer'} - -Replace missing values using the given strategy. - -**Parent type:** [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `strategy` | [`Strategy`][safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy] | How to replace missing values. | - | -| `valueToReplace` | `#!sds union` | The value that should be replaced. | `#!sds null` | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import Column, Table - // from safeds.data.tabular.transformation import Imputer - // - // table = Table.from_columns( - // [ - // Column("a", [1, 3, None]), - // Column("b", [None, 2, 3]), - // ], - // ) - // transformer = Imputer(Imputer.Strategy.Constant(0)) - // transformed_table = transformer.fit_and_transform(table) -} -``` - -??? quote "Stub code in `ExperimentalSimpleImputer.sdsstub`" - - ```sds linenums="28" - class ExperimentalSimpleImputer( - strategy: ExperimentalSimpleImputer.Strategy, - @PythonName("value_to_replace") valueToReplace: union = null - ) sub ExperimentalTableTransformer { - /** - * Various strategies to replace missing values. - */ - enum Strategy { - /** - * Replace missing values with the given constant value. - * - * @param value The value to replace missing values. - */ - Constant(value: Any) - - /** - * Replace missing values with the mean of each column. - */ - Mean - - /** - * Replace missing values with the median of each column. - */ - Median - - /** - * Replace missing values with the mode of each column. - */ - Mode - } - - /** - * The strategy used to replace missing values. - */ - attr strategy: ExperimentalSimpleImputer.Strategy - /** - * The value that should be replaced. - */ - @PythonName("value_to_replace") attr valueToReplace: Any - - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalSimpleImputer - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` strategy {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.strategy data-toc-label='strategy'} - -The strategy used to replace missing values. - -**Type:** [`Strategy`][safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy] - -## `#!sds attr` valueToReplace {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.valueToReplace data-toc-label='valueToReplace'} - -The value that should be replaced. - -**Type:** [`Any`][safeds.lang.Any] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalSimpleImputer`][safeds.data.tabular.transformation.ExperimentalSimpleImputer] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalSimpleImputer.sdsstub`" - - ```sds linenums="78" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalSimpleImputer - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` - -## `#!sds enum` Strategy {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy data-toc-label='Strategy'} - -Various strategies to replace missing values. - -??? quote "Stub code in `ExperimentalSimpleImputer.sdsstub`" - - ```sds linenums="35" - enum Strategy { - /** - * Replace missing values with the given constant value. - * - * @param value The value to replace missing values. - */ - Constant(value: Any) - - /** - * Replace missing values with the mean of each column. - */ - Mean - - /** - * Replace missing values with the median of each column. - */ - Median - - /** - * Replace missing values with the mode of each column. - */ - Mode - } - ``` - -### Constant {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy.Constant data-toc-label='Constant'} - -Replace missing values with the given constant value. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `value` | [`Any`][safeds.lang.Any] | The value to replace missing values. | - | - -### Mean {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy.Mean data-toc-label='Mean'} - -Replace missing values with the mean of each column. - -### Median {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy.Median data-toc-label='Median'} - -Replace missing values with the median of each column. - -### Mode {#safeds.data.tabular.transformation.ExperimentalSimpleImputer.Strategy.Mode data-toc-label='Mode'} - -Replace missing values with the mode of each column. diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalStandardScaler.md b/docs/api/safeds/data/tabular/transformation/ExperimentalStandardScaler.md deleted file mode 100644 index 14c056d32..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalStandardScaler.md +++ /dev/null @@ -1,202 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ExperimentalStandardScaler {#safeds.data.tabular.transformation.ExperimentalStandardScaler data-toc-label='ExperimentalStandardScaler'} - -The StandardScaler transforms column values to a range by removing the mean and scaling to unit variance. - -**Parent type:** [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] - -??? quote "Stub code in `ExperimentalStandardScaler.sdsstub`" - - ```sds linenums="10" - class ExperimentalStandardScaler() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalStandardScaler - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalStandardScaler.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalStandardScaler.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalStandardScaler`][safeds.data.tabular.transformation.ExperimentalStandardScaler] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalStandardScaler.sdsstub`" - - ```sds linenums="21" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalStandardScaler - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalStandardScaler.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalStandardScaler.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalStandardScaler.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalStandardScaler.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.ExperimentalStandardScaler.inverseTransform data-toc-label='inverseTransform'} - -Undo the learned transformation. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to be transformed back to the original version. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `originalTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The original table. | - -??? quote "Stub code in `ExperimentalInvertibleTableTransformer.sdsstub`" - - ```sds linenums="20" - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalStandardScaler.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/ExperimentalTableTransformer.md b/docs/api/safeds/data/tabular/transformation/ExperimentalTableTransformer.md deleted file mode 100644 index 16bb71982..000000000 --- a/docs/api/safeds/data/tabular/transformation/ExperimentalTableTransformer.md +++ /dev/null @@ -1,247 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ExperimentalTableTransformer {#safeds.data.tabular.transformation.ExperimentalTableTransformer data-toc-label='ExperimentalTableTransformer'} - -Learn a transformation for a set of columns in a `Table` and transform another `Table` with the same columns. - -**Inheritors:** - -- [`ExperimentalDiscretizer`][safeds.data.tabular.transformation.ExperimentalDiscretizer] -- [`ExperimentalInvertibleTableTransformer`][safeds.data.tabular.transformation.ExperimentalInvertibleTableTransformer] -- [`ExperimentalSimpleImputer`][safeds.data.tabular.transformation.ExperimentalSimpleImputer] - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="9" - class ExperimentalTableTransformer { - /** - * Whether the transformer is fitted. - */ - @PythonName("is_fitted") attr isFitted: Boolean - - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalTableTransformer - - /** - * Apply the learned transformation to a table. - * - * The table is not modified. - * - * @param table The table to which the learned transformation is applied. - * - * @result transformedTable The transformed table. - */ - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - - /** - * Get the names of all new columns that have been added by the transformer. - * - * @result addedColumns A list of names of the added columns, ordered as they will appear in the table. - */ - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - - /** - * Get the names of all columns that have been changed by the transformer. - * - * @result changedColumns A list of names of changed columns, ordered as they appear in the table. - */ - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - - /** - * Get the names of all columns that have been removed by the transformer. - * - * @result removedColumns A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. - */ - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - - /** - * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - * - * Neither the transformer nor the table are modified. - * - * @param table The table used to fit the transformer. The transformer is then applied to this table. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - * @result transformedTable The transformed table. - */ - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - } - ``` - -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.ExperimentalTableTransformer.isFitted data-toc-label='isFitted'} - -Whether the transformer is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.data.tabular.transformation.ExperimentalTableTransformer.fit data-toc-label='fit'} - -Learn a transformation for a set of columns in a table. - -This transformer is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedTransformer` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | The fitted transformer. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="25" - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalTableTransformer - ``` - -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.ExperimentalTableTransformer.fitAndTransform data-toc-label='fitAndTransform'} - -Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - -Neither the transformer nor the table are modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`ExperimentalTableTransformer`][safeds.data.tabular.transformation.ExperimentalTableTransformer] | - | -| `result2` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | - | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="83" - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.ExperimentalTableTransformer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `addedColumns` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="50" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.ExperimentalTableTransformer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `changedColumns` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="59" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.ExperimentalTableTransformer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `removedColumns` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="68" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.ExperimentalTableTransformer.transform data-toc-label='transform'} - -Apply the learned transformation to a table. - -The table is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `table` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The table to which the learned transformation is applied. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `transformedTable` | [`ExperimentalTable`][safeds.data.tabular.containers.ExperimentalTable] | The transformed table. | - -??? quote "Stub code in `ExperimentalTableTransformer.sdsstub`" - - ```sds linenums="40" - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - ``` diff --git a/docs/api/safeds/data/tabular/transformation/InvertibleTableTransformer.md b/docs/api/safeds/data/tabular/transformation/InvertibleTableTransformer.md index 50fd6ada1..35402e98b 100644 --- a/docs/api/safeds/data/tabular/transformation/InvertibleTableTransformer.md +++ b/docs/api/safeds/data/tabular/transformation/InvertibleTableTransformer.md @@ -1,9 +1,4 @@ ---- -search: - boost: 0.5 ---- - -# `#!sds abstract class` InvertibleTableTransformer {#safeds.data.tabular.transformation.InvertibleTableTransformer data-toc-label='InvertibleTableTransformer'} +# `#!sds class` InvertibleTableTransformer {#safeds.data.tabular.transformation.InvertibleTableTransformer data-toc-label='InvertibleTableTransformer'} A `TableTransformer` that can also undo the learned transformation after it has been applied. @@ -18,36 +13,58 @@ A `TableTransformer` that can also undo the learned transformation after it has ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="8" - class InvertibleTableTransformer sub TableTransformer { + ```sds linenums="9" + class InvertibleTableTransformer() sub TableTransformer { /** * Learn a transformation for a set of columns in a table. * + * **Note:** This transformer is not modified. + * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: InvertibleTableTransformer + ) -> fittedTransformer: InvertibleTableTransformer /** - * Undo the learned transformation. + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. * - * The table is not modified. + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: InvertibleTableTransformer, transformedTable: Table) + + /** + * Undo the learned transformation as well as possible. + * + * Column order and types may differ from the original table. Likewise, some values might not be restored. + * + * **Note:** The given table is not modified. * * @param transformedTable The table to be transformed back to the original version. * - * @result result1 The original table. + * @result originalTable The original table. */ @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table } ``` @@ -61,119 +78,69 @@ Whether the transformer is fitted. Learn a transformation for a set of columns in a table. +**Note:** This transformer is not modified. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] | The fitted transformer. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="17" + ```sds linenums="20" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: InvertibleTableTransformer + ) -> fittedTransformer: InvertibleTableTransformer ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.InvertibleTableTransformer.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="82" + ```sds linenums="37" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.InvertibleTableTransformer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.InvertibleTableTransformer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.InvertibleTableTransformer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: InvertibleTableTransformer, transformedTable: Table) ``` ## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.InvertibleTableTransformer.inverseTransform data-toc-label='inverseTransform'} -Undo the learned transformation. +Undo the learned transformation as well as possible. + +Column order and types may differ from the original table. Likewise, some values might not be restored. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -185,23 +152,23 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="32" + ```sds linenums="55" @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.InvertibleTableTransformer.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -213,7 +180,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -221,5 +188,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/LabelEncoder.md b/docs/api/safeds/data/tabular/transformation/LabelEncoder.md index ecc93bf05..1617f1aa5 100644 --- a/docs/api/safeds/data/tabular/transformation/LabelEncoder.md +++ b/docs/api/safeds/data/tabular/transformation/LabelEncoder.md @@ -4,6 +4,12 @@ The LabelEncoder encodes one or more given columns into labels. **Parent type:** [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `partialOrder` | [`List`][safeds.lang.List] | The partial order of the labels. The labels are encoded in the order of the given list. Additional values are encoded as the next integer after the last value in the list in the order they appear in the data. | `#!sds []` | + **Examples:** ```sds hl_lines="3" @@ -19,23 +25,43 @@ pipeline example { ??? quote "Stub code in `LabelEncoder.sdsstub`" - ```sds linenums="19" - class LabelEncoder() sub InvertibleTableTransformer { + ```sds linenums="22" + class LabelEncoder( + @PythonName("partial_order") partialOrder: List = [] + ) sub InvertibleTableTransformer { /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all non-numeric columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: LabelEncoder + ) -> fittedTransformer: LabelEncoder + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: LabelEncoder, transformedTable: Table) } ``` @@ -56,114 +82,62 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all non-numeric columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`LabelEncoder`][safeds.data.tabular.transformation.LabelEncoder] | The fitted transformer. | +| `fittedTransformer` | [`LabelEncoder`][safeds.data.tabular.transformation.LabelEncoder] | The fitted transformer. | ??? quote "Stub code in `LabelEncoder.sdsstub`" - ```sds linenums="30" + ```sds linenums="35" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: LabelEncoder + ) -> fittedTransformer: LabelEncoder ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.LabelEncoder.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`LabelEncoder`][safeds.data.tabular.transformation.LabelEncoder] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `LabelEncoder.sdsstub`" - ```sds linenums="82" + ```sds linenums="52" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.LabelEncoder.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.LabelEncoder.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.LabelEncoder.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: LabelEncoder, transformedTable: Table) ``` ## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.LabelEncoder.inverseTransform data-toc-label='inverseTransform'} -Undo the learned transformation. +Undo the learned transformation as well as possible. + +Column order and types may differ from the original table. Likewise, some values might not be restored. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -175,23 +149,23 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="32" + ```sds linenums="55" @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.LabelEncoder.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -203,7 +177,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -211,5 +185,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/OneHotEncoder.md b/docs/api/safeds/data/tabular/transformation/OneHotEncoder.md index e2be97d5e..840d33785 100644 --- a/docs/api/safeds/data/tabular/transformation/OneHotEncoder.md +++ b/docs/api/safeds/data/tabular/transformation/OneHotEncoder.md @@ -27,6 +27,12 @@ One-hot encoding is closely related to dummy variable / indicator variables, whi **Parent type:** [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `separator` | [`String`][safeds.lang.String] | The separator used to separate the original column name from the value in the new column names. | `#!sds "__"` | + **Examples:** ```sds hl_lines="3" @@ -42,23 +48,43 @@ pipeline example { ??? quote "Stub code in `OneHotEncoder.sdsstub`" - ```sds linenums="42" - class OneHotEncoder() sub InvertibleTableTransformer { + ```sds linenums="44" + class OneHotEncoder( + separator: String = "__" + ) sub InvertibleTableTransformer { /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: OneHotEncoder + ) -> fittedTransformer: OneHotEncoder + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: OneHotEncoder, transformedTable: Table) } ``` @@ -79,114 +105,62 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`OneHotEncoder`][safeds.data.tabular.transformation.OneHotEncoder] | The fitted transformer. | +| `fittedTransformer` | [`OneHotEncoder`][safeds.data.tabular.transformation.OneHotEncoder] | The fitted transformer. | ??? quote "Stub code in `OneHotEncoder.sdsstub`" - ```sds linenums="53" + ```sds linenums="57" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: OneHotEncoder + ) -> fittedTransformer: OneHotEncoder ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.OneHotEncoder.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`OneHotEncoder`][safeds.data.tabular.transformation.OneHotEncoder] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `OneHotEncoder.sdsstub`" - ```sds linenums="82" + ```sds linenums="74" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.OneHotEncoder.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.OneHotEncoder.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.OneHotEncoder.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: OneHotEncoder, transformedTable: Table) ``` ## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.OneHotEncoder.inverseTransform data-toc-label='inverseTransform'} -Undo the learned transformation. +Undo the learned transformation as well as possible. + +Column order and types may differ from the original table. Likewise, some values might not be restored. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -198,23 +172,23 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="32" + ```sds linenums="55" @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.OneHotEncoder.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -226,7 +200,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -234,5 +208,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/RangeScaler.md b/docs/api/safeds/data/tabular/transformation/RangeScaler.md index f5b6ee632..c4945a1bb 100644 --- a/docs/api/safeds/data/tabular/transformation/RangeScaler.md +++ b/docs/api/safeds/data/tabular/transformation/RangeScaler.md @@ -8,8 +8,8 @@ The RangeScaler transforms column values by scaling each value to a given range. | Name | Type | Description | Default | |------|------|-------------|---------| -| `minimum` | [`Float`][safeds.lang.Float] | The minimum of the new range after the transformation | `#!sds 0.0` | -| `maximum` | [`Float`][safeds.lang.Float] | The maximum of the new range after the transformation | `#!sds 1.0` | +| `min` | [`Float`][safeds.lang.Float] | The minimum of the new range after the transformation | `#!sds 0.0` | +| `max` | [`Float`][safeds.lang.Float] | The maximum of the new range after the transformation | `#!sds 1.0` | **Examples:** @@ -28,24 +28,51 @@ pipeline example { ```sds linenums="22" class RangeScaler( - const minimum: Float = 0.0, - const maximum: Float = 1.0 + const min: Float = 0.0, + const max: Float = 1.0 ) sub InvertibleTableTransformer { + /** + * The minimum of the new range after the transformation. + */ + attr min: Float + /** + * The maximum of the new range after the transformation. + */ + attr max: Float + /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all numeric columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: RangeScaler + ) -> fittedTransformer: RangeScaler + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: RangeScaler, transformedTable: Table) } ``` @@ -55,6 +82,18 @@ Whether the transformer is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] +## `#!sds attr` max {#safeds.data.tabular.transformation.RangeScaler.max data-toc-label='max'} + +The maximum of the new range after the transformation. + +**Type:** [`Float`][safeds.lang.Float] + +## `#!sds attr` min {#safeds.data.tabular.transformation.RangeScaler.min data-toc-label='min'} + +The minimum of the new range after the transformation. + +**Type:** [`Float`][safeds.lang.Float] + ## `#!sds fun` fit {#safeds.data.tabular.transformation.RangeScaler.fit data-toc-label='fit'} Learn a transformation for a set of columns in a table. @@ -66,114 +105,62 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all numeric columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`RangeScaler`][safeds.data.tabular.transformation.RangeScaler] | The fitted transformer. | +| `fittedTransformer` | [`RangeScaler`][safeds.data.tabular.transformation.RangeScaler] | The fitted transformer. | ??? quote "Stub code in `RangeScaler.sdsstub`" - ```sds linenums="36" + ```sds linenums="45" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: RangeScaler + ) -> fittedTransformer: RangeScaler ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.RangeScaler.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`RangeScaler`][safeds.data.tabular.transformation.RangeScaler] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `RangeScaler.sdsstub`" - ```sds linenums="82" + ```sds linenums="62" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.RangeScaler.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.RangeScaler.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.RangeScaler.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: RangeScaler, transformedTable: Table) ``` ## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.RangeScaler.inverseTransform data-toc-label='inverseTransform'} -Undo the learned transformation. +Undo the learned transformation as well as possible. + +Column order and types may differ from the original table. Likewise, some values might not be restored. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -185,23 +172,23 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="32" + ```sds linenums="55" @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.RangeScaler.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -213,7 +200,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -221,5 +208,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/Imputer.md b/docs/api/safeds/data/tabular/transformation/SimpleImputer.md similarity index 54% rename from docs/api/safeds/data/tabular/transformation/Imputer.md rename to docs/api/safeds/data/tabular/transformation/SimpleImputer.md index 7fb441f17..6aa8a9c82 100644 --- a/docs/api/safeds/data/tabular/transformation/Imputer.md +++ b/docs/api/safeds/data/tabular/transformation/SimpleImputer.md @@ -1,4 +1,4 @@ -# `#!sds class` Imputer {#safeds.data.tabular.transformation.Imputer data-toc-label='Imputer'} +# `#!sds class` SimpleImputer {#safeds.data.tabular.transformation.SimpleImputer data-toc-label='SimpleImputer'} Replace missing values with the given strategy. @@ -8,7 +8,7 @@ Replace missing values with the given strategy. | Name | Type | Description | Default | |------|------|-------------|---------| -| `strategy` | [`Strategy`][safeds.data.tabular.transformation.Imputer.Strategy] | The strategy used to impute missing values. Use the classes nested inside `Imputer.Strategy` to specify it. | - | +| `strategy` | [`Strategy`][safeds.data.tabular.transformation.SimpleImputer.Strategy] | The strategy used to impute missing values. | - | | `valueToReplace` | `#!sds union` | - | `#!sds null` | **Examples:** @@ -16,7 +16,7 @@ Replace missing values with the given strategy. ```sds hl_lines="3" pipeline example { val table = Table({"a": [1, null], "b": [3, 4]}); - val imputer = Imputer(Imputer.Strategy.Mean).fit(table, ["a"]); + val imputer = SimpleImputer(SimpleImputer.Strategy.Mean).fit(table, ["a"]); val transformedTable = imputer.transform(table); // Table({"a": [1, 1], "b": [3, 4]}) } @@ -24,17 +24,17 @@ pipeline example { ```sds hl_lines="3" pipeline example { val table = Table({"a": [1, null], "b": [3, 4]}); - val imputer = Imputer(Imputer.Strategy.Constant(0)).fit(table, ["a"]); + val imputer = SimpleImputer(SimpleImputer.Strategy.Constant(0)).fit(table, ["a"]); val transformedTable = imputer.transform(table); // Table({"a": [1, 0], "b": [3, 4]}) } ``` -??? quote "Stub code in `Imputer.sdsstub`" +??? quote "Stub code in `SimpleImputer.sdsstub`" ```sds linenums="27" - class Imputer( - strategy: Imputer.Strategy, + class SimpleImputer( + strategy: SimpleImputer.Strategy, @PythonName("value_to_replace") valueToReplace: union = null ) sub TableTransformer { /** @@ -46,28 +46,32 @@ pipeline example { * * @param value The value to replace missing values. */ + @PythonName("constant") Constant(value: Any) /** * Replace missing values with the mean of each column. */ + @PythonName("mean") Mean /** * Replace missing values with the median of each column. */ + @PythonName("median") Median /** * Replace missing values with the mode of each column. */ + @PythonName("mode") Mode } /** * The strategy used to replace missing values. */ - attr strategy: Imputer.Strategy + attr strategy: SimpleImputer.Strategy /** * The value that should be replaced. */ @@ -79,37 +83,55 @@ pipeline example { * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Imputer + ) -> fittedTransformer: SimpleImputer + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: SimpleImputer, transformedTable: Table) } ``` -## `#!sds attr` isFitted {#safeds.data.tabular.transformation.Imputer.isFitted data-toc-label='isFitted'} +## `#!sds attr` isFitted {#safeds.data.tabular.transformation.SimpleImputer.isFitted data-toc-label='isFitted'} Whether the transformer is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` strategy {#safeds.data.tabular.transformation.Imputer.strategy data-toc-label='strategy'} +## `#!sds attr` strategy {#safeds.data.tabular.transformation.SimpleImputer.strategy data-toc-label='strategy'} The strategy used to replace missing values. -**Type:** [`Strategy`][safeds.data.tabular.transformation.Imputer.Strategy] +**Type:** [`Strategy`][safeds.data.tabular.transformation.SimpleImputer.Strategy] -## `#!sds attr` valueToReplace {#safeds.data.tabular.transformation.Imputer.valueToReplace data-toc-label='valueToReplace'} +## `#!sds attr` valueToReplace {#safeds.data.tabular.transformation.SimpleImputer.valueToReplace data-toc-label='valueToReplace'} The value that should be replaced. **Type:** [`Any`][safeds.lang.Any] -## `#!sds fun` fit {#safeds.data.tabular.transformation.Imputer.fit data-toc-label='fit'} +## `#!sds fun` fit {#safeds.data.tabular.transformation.SimpleImputer.fit data-toc-label='fit'} Learn a transformation for a set of columns in a table. @@ -120,114 +142,60 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`Imputer`][safeds.data.tabular.transformation.Imputer] | The fitted transformer. | +| `fittedTransformer` | [`SimpleImputer`][safeds.data.tabular.transformation.SimpleImputer] | The fitted transformer. | -??? quote "Stub code in `Imputer.sdsstub`" +??? quote "Stub code in `SimpleImputer.sdsstub`" - ```sds linenums="77" + ```sds linenums="81" @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Imputer + ) -> fittedTransformer: SimpleImputer ``` -## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.Imputer.fitAndTransform data-toc-label='fitAndTransform'} +## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.SimpleImputer.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`SimpleImputer`][safeds.data.tabular.transformation.SimpleImputer] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `SimpleImputer.sdsstub`" - ```sds linenums="82" + ```sds linenums="98" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.Imputer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.Imputer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List + ) -> (fittedTransformer: SimpleImputer, transformedTable: Table) ``` -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.Imputer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List - ``` - -## `#!sds fun` transform {#safeds.data.tabular.transformation.Imputer.transform data-toc-label='transform'} +## `#!sds fun` transform {#safeds.data.tabular.transformation.SimpleImputer.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -239,7 +207,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -247,14 +215,14 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` -## `#!sds enum` Strategy {#safeds.data.tabular.transformation.Imputer.Strategy data-toc-label='Strategy'} +## `#!sds enum` Strategy {#safeds.data.tabular.transformation.SimpleImputer.Strategy data-toc-label='Strategy'} Various strategies to replace missing values. -??? quote "Stub code in `Imputer.sdsstub`" +??? quote "Stub code in `SimpleImputer.sdsstub`" ```sds linenums="34" enum Strategy { @@ -263,26 +231,30 @@ Various strategies to replace missing values. * * @param value The value to replace missing values. */ + @PythonName("constant") Constant(value: Any) /** * Replace missing values with the mean of each column. */ + @PythonName("mean") Mean /** * Replace missing values with the median of each column. */ + @PythonName("median") Median /** * Replace missing values with the mode of each column. */ + @PythonName("mode") Mode } ``` -### Constant {#safeds.data.tabular.transformation.Imputer.Strategy.Constant data-toc-label='Constant'} +### Constant {#safeds.data.tabular.transformation.SimpleImputer.Strategy.Constant data-toc-label='Constant'} Replace missing values with the given constant value. @@ -292,14 +264,14 @@ Replace missing values with the given constant value. |------|------|-------------|---------| | `value` | [`Any`][safeds.lang.Any] | The value to replace missing values. | - | -### Mean {#safeds.data.tabular.transformation.Imputer.Strategy.Mean data-toc-label='Mean'} +### Mean {#safeds.data.tabular.transformation.SimpleImputer.Strategy.Mean data-toc-label='Mean'} Replace missing values with the mean of each column. -### Median {#safeds.data.tabular.transformation.Imputer.Strategy.Median data-toc-label='Median'} +### Median {#safeds.data.tabular.transformation.SimpleImputer.Strategy.Median data-toc-label='Median'} Replace missing values with the median of each column. -### Mode {#safeds.data.tabular.transformation.Imputer.Strategy.Mode data-toc-label='Mode'} +### Mode {#safeds.data.tabular.transformation.SimpleImputer.Strategy.Mode data-toc-label='Mode'} Replace missing values with the mode of each column. diff --git a/docs/api/safeds/data/tabular/transformation/StandardScaler.md b/docs/api/safeds/data/tabular/transformation/StandardScaler.md index c7086a2c0..14c4f66e8 100644 --- a/docs/api/safeds/data/tabular/transformation/StandardScaler.md +++ b/docs/api/safeds/data/tabular/transformation/StandardScaler.md @@ -27,15 +27,33 @@ pipeline example { * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: StandardScaler + ) -> fittedTransformer: StandardScaler + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: StandardScaler, transformedTable: Table) } ``` @@ -56,13 +74,13 @@ This transformer is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`StandardScaler`][safeds.data.tabular.transformation.StandardScaler] | The fitted transformer. | +| `fittedTransformer` | [`StandardScaler`][safeds.data.tabular.transformation.StandardScaler] | The fitted transformer. | ??? quote "Stub code in `StandardScaler.sdsstub`" @@ -71,99 +89,47 @@ This transformer is not modified. fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: StandardScaler + ) -> fittedTransformer: StandardScaler ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.StandardScaler.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`StandardScaler`][safeds.data.tabular.transformation.StandardScaler] | The fitted transformer. | | `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | -??? quote "Stub code in `TableTransformer.sdsstub`" +??? quote "Stub code in `StandardScaler.sdsstub`" - ```sds linenums="82" + ```sds linenums="47" @Pure @PythonName("fit_and_transform") fun fitAndTransform( table: Table, @PythonName("column_names") columnNames: List? = null - ) -> (fittedTransformer: TableTransformer, transformedTable: Table) - ``` - -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.StandardScaler.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.StandardScaler.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.StandardScaler.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> (fittedTransformer: StandardScaler, transformedTable: Table) ``` ## `#!sds fun` inverseTransform {#safeds.data.tabular.transformation.StandardScaler.inverseTransform data-toc-label='inverseTransform'} -Undo the learned transformation. +Undo the learned transformation as well as possible. + +Column order and types may differ from the original table. Likewise, some values might not be restored. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -175,23 +141,23 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | +| `originalTable` | [`Table`][safeds.data.tabular.containers.Table] | The original table. | ??? quote "Stub code in `InvertibleTableTransformer.sdsstub`" - ```sds linenums="32" + ```sds linenums="55" @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table ``` ## `#!sds fun` transform {#safeds.data.tabular.transformation.StandardScaler.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -203,7 +169,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -211,5 +177,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/transformation/TableTransformer.md b/docs/api/safeds/data/tabular/transformation/TableTransformer.md index 128d15faf..4a5450a75 100644 --- a/docs/api/safeds/data/tabular/transformation/TableTransformer.md +++ b/docs/api/safeds/data/tabular/transformation/TableTransformer.md @@ -10,8 +10,9 @@ Learn a transformation for a set of columns in a `Table` and transform another ` **Inheritors:** - [`Discretizer`][safeds.data.tabular.transformation.Discretizer] -- [`Imputer`][safeds.data.tabular.transformation.Imputer] +- `#!sds Imputer` - [`InvertibleTableTransformer`][safeds.data.tabular.transformation.InvertibleTableTransformer] +- [`SimpleImputer`][safeds.data.tabular.transformation.SimpleImputer] ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -25,67 +26,40 @@ Learn a transformation for a set of columns in a `Table` and transform another ` /** * Learn a transformation for a set of columns in a table. * - * This transformer is not modified. + * **Note:** This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: TableTransformer + ) -> fittedTransformer: TableTransformer /** * Apply the learned transformation to a table. * - * The table is not modified. + * **Note:** The given table is not modified. * * @param table The table to which the learned transformation is applied. * - * @result result1 The transformed table. + * @result transformedTable The transformed table. */ @Pure fun transform( table: Table - ) -> result1: Table - - /** - * Get the names of all new columns that have been added by the transformer. - * - * @result result1 A list of names of the added columns, ordered as they will appear in the table. - */ - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - - /** - * Get the names of all columns that have been changed by the transformer. - * - * @result result1 A list of names of changed columns, ordered as they appear in the table. - */ - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - - /** - * Get the names of all columns that have been removed by the transformer. - * - * @result result1 A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. - */ - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> transformedTable: Table /** * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. * - * Neither the transformer nor the table are modified. + * **Note:** Neither this transformer nor the given table are modified. * * @param table The table used to fit the transformer. The transformer is then applied to this table. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * * @result fittedTransformer The fitted transformer. * @result transformedTable The transformed table. @@ -109,20 +83,20 @@ Whether the transformer is fitted. Learn a transformation for a set of columns in a table. -This transformer is not modified. +**Note:** This transformer is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | - | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | +| `fittedTransformer` | [`TableTransformer`][safeds.data.tabular.transformation.TableTransformer] | The fitted transformer. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -131,21 +105,21 @@ This transformer is not modified. fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: TableTransformer + ) -> fittedTransformer: TableTransformer ``` ## `#!sds fun` fitAndTransform {#safeds.data.tabular.transformation.TableTransformer.fitAndTransform data-toc-label='fitAndTransform'} Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. -Neither the transformer nor the table are modified. +**Note:** Neither this transformer nor the given table are modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| | `table` | [`Table`][safeds.data.tabular.containers.Table] | The table used to fit the transformer. The transformer is then applied to this table. | - | -| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `None`, all columns are used. | `#!sds null` | +| `columnNames` | [`List?`][safeds.lang.List] | The list of columns from the table used to fit the transformer. If `null`, all columns are used. | `#!sds null` | **Results:** @@ -156,7 +130,7 @@ Neither the transformer nor the table are modified. ??? quote "Stub code in `TableTransformer.sdsstub`" - ```sds linenums="82" + ```sds linenums="55" @Pure @PythonName("fit_and_transform") fun fitAndTransform( @@ -165,65 +139,11 @@ Neither the transformer nor the table are modified. ) -> (fittedTransformer: TableTransformer, transformedTable: Table) ``` -## `#!sds fun` getNamesOfAddedColumns {#safeds.data.tabular.transformation.TableTransformer.getNamesOfAddedColumns data-toc-label='getNamesOfAddedColumns'} - -Get the names of all new columns that have been added by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the added columns, ordered as they will appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfChangedColumns {#safeds.data.tabular.transformation.TableTransformer.getNamesOfChangedColumns data-toc-label='getNamesOfChangedColumns'} - -Get the names of all columns that have been changed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of changed columns, ordered as they appear in the table. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="58" - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - ``` - -## `#!sds fun` getNamesOfRemovedColumns {#safeds.data.tabular.transformation.TableTransformer.getNamesOfRemovedColumns data-toc-label='getNamesOfRemovedColumns'} - -Get the names of all columns that have been removed by the transformer. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`List`][safeds.lang.List] | A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. | - -??? quote "Stub code in `TableTransformer.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List - ``` - ## `#!sds fun` transform {#safeds.data.tabular.transformation.TableTransformer.transform data-toc-label='transform'} Apply the learned transformation to a table. -The table is not modified. +**Note:** The given table is not modified. **Parameters:** @@ -235,7 +155,7 @@ The table is not modified. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | +| `transformedTable` | [`Table`][safeds.data.tabular.containers.Table] | The transformed table. | ??? quote "Stub code in `TableTransformer.sdsstub`" @@ -243,5 +163,5 @@ The table is not modified. @Pure fun transform( table: Table - ) -> result1: Table + ) -> transformedTable: Table ``` diff --git a/docs/api/safeds/data/tabular/typing/ColumnType.md b/docs/api/safeds/data/tabular/typing/ColumnType.md deleted file mode 100644 index e10cd8cbe..000000000 --- a/docs/api/safeds/data/tabular/typing/ColumnType.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ColumnType {#safeds.data.tabular.typing.ColumnType data-toc-label='ColumnType'} - -Abstract base class for column types. - -**Examples:** - -```sds -pipeline example { - // TODO -} -``` - -??? quote "Stub code in `ColumnType.sdsstub`" - - ```sds linenums="14" - class ColumnType { - /** - * Return whether the given column type is nullable. - * - * @result result1 True if the column is nullable. - * - * @example - * pipeline example { - * // TODO - * } - */ - @Pure - @PythonName("is_nullable") - fun isNullable() -> result1: Boolean - - /** - * Return whether the given column type is numeric. - * - * @result result1 True if the column is numeric. - * - * @example - * pipeline example { - * // TODO - * } - */ - @Pure - @PythonName("is_numeric") - fun isNumeric() -> result1: Boolean - } - ``` - -## `#!sds fun` isNullable {#safeds.data.tabular.typing.ColumnType.isNullable data-toc-label='isNullable'} - -Return whether the given column type is nullable. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`Boolean`][safeds.lang.Boolean] | True if the column is nullable. | - -**Examples:** - -```sds -pipeline example { - // TODO -} -``` - -??? quote "Stub code in `ColumnType.sdsstub`" - - ```sds linenums="25" - @Pure - @PythonName("is_nullable") - fun isNullable() -> result1: Boolean - ``` - -## `#!sds fun` isNumeric {#safeds.data.tabular.typing.ColumnType.isNumeric data-toc-label='isNumeric'} - -Return whether the given column type is numeric. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `result1` | [`Boolean`][safeds.lang.Boolean] | True if the column is numeric. | - -**Examples:** - -```sds -pipeline example { - // TODO -} -``` - -??? quote "Stub code in `ColumnType.sdsstub`" - - ```sds linenums="39" - @Pure - @PythonName("is_numeric") - fun isNumeric() -> result1: Boolean - ``` diff --git a/docs/api/safeds/data/tabular/typing/DataType.md b/docs/api/safeds/data/tabular/typing/DataType.md new file mode 100644 index 000000000..3fe188c29 --- /dev/null +++ b/docs/api/safeds/data/tabular/typing/DataType.md @@ -0,0 +1,35 @@ +--- +search: + boost: 0.5 +--- + +# `#!sds abstract class` DataType {#safeds.data.tabular.typing.DataType data-toc-label='DataType'} + +The type of a column or cell in a table. + +??? quote "Stub code in `DataType.sdsstub`" + + ```sds linenums="6" + class DataType { + /** + * Whether the column type is numeric. + */ + @PythonName("is_numeric") attr isNumeric: Boolean + /** + * Whether the column type is temporal. + */ + @PythonName("is_temporal") attr isTemporal: Boolean + } + ``` + +## `#!sds attr` isNumeric {#safeds.data.tabular.typing.DataType.isNumeric data-toc-label='isNumeric'} + +Whether the column type is numeric. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds attr` isTemporal {#safeds.data.tabular.typing.DataType.isTemporal data-toc-label='isTemporal'} + +Whether the column type is temporal. + +**Type:** [`Boolean`][safeds.lang.Boolean] diff --git a/docs/api/safeds/data/tabular/typing/ExperimentalDataType.md b/docs/api/safeds/data/tabular/typing/ExperimentalDataType.md deleted file mode 100644 index 63249af30..000000000 --- a/docs/api/safeds/data/tabular/typing/ExperimentalDataType.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ExperimentalDataType {#safeds.data.tabular.typing.ExperimentalDataType data-toc-label='ExperimentalDataType'} - -The type of a column or cell in a table. - -??? quote "Stub code in `ExperimentalDataType.sdsstub`" - - ```sds linenums="7" - class ExperimentalDataType { - /** - * Whether the column type is numeric. - */ - @PythonName("is_numeric") attr isNumeric: Boolean - /** - * Whether the column type is temporal. - */ - @PythonName("is_temporal") attr isTemporal: Boolean - } - ``` - -## `#!sds attr` isNumeric {#safeds.data.tabular.typing.ExperimentalDataType.isNumeric data-toc-label='isNumeric'} - -Whether the column type is numeric. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` isTemporal {#safeds.data.tabular.typing.ExperimentalDataType.isTemporal data-toc-label='isTemporal'} - -Whether the column type is temporal. - -**Type:** [`Boolean`][safeds.lang.Boolean] diff --git a/docs/api/safeds/data/tabular/typing/ExperimentalSchema.md b/docs/api/safeds/data/tabular/typing/ExperimentalSchema.md deleted file mode 100644 index cc34508fc..000000000 --- a/docs/api/safeds/data/tabular/typing/ExperimentalSchema.md +++ /dev/null @@ -1,181 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` ExperimentalSchema {#safeds.data.tabular.typing.ExperimentalSchema data-toc-label='ExperimentalSchema'} - -The schema of a row or table. - -??? quote "Stub code in `ExperimentalSchema.sdsstub`" - - ```sds linenums="9" - class ExperimentalSchema { - /** - * Return a list of all column names contained in this schema. - */ - @PythonName("column_names") attr columnNames: List - - /** - * Return the type of the given column. - * - * @param name The name of the column. - * - * @result type The type of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // type_ = table.schema.get_column_type("A") - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Return whether the schema contains a given column. - * - * @param name The name of the column. - * - * @result contains True if the schema contains the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // table.schema.has_column("A") - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> contains: Boolean - - /** - * Return a dictionary that maps column names to column types. - * - * @result data Dictionary representation of the schema. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // dict_ = table.schema.to_dict() - * } - */ - @Pure - @PythonName("to_dict") - fun toDict() -> data: Map - } - ``` - -## `#!sds attr` columnNames {#safeds.data.tabular.typing.ExperimentalSchema.columnNames data-toc-label='columnNames'} - -Return a list of all column names contained in this schema. - -**Type:** [`List`][safeds.lang.List] - -## `#!sds fun` getColumnType {#safeds.data.tabular.typing.ExperimentalSchema.getColumnType data-toc-label='getColumnType'} - -Return the type of the given column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `type` | [`ExperimentalDataType`][safeds.data.tabular.typing.ExperimentalDataType] | The type of the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - // type_ = table.schema.get_column_type("A") -} -``` - -??? quote "Stub code in `ExperimentalSchema.sdsstub`" - - ```sds linenums="29" - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - ``` - -## `#!sds fun` hasColumn {#safeds.data.tabular.typing.ExperimentalSchema.hasColumn data-toc-label='hasColumn'} - -Return whether the schema contains a given column. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `name` | [`String`][safeds.lang.String] | The name of the column. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `contains` | [`Boolean`][safeds.lang.Boolean] | True if the schema contains the column. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - // table.schema.has_column("A") -} -``` - -??? quote "Stub code in `ExperimentalSchema.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> contains: Boolean - ``` - -## `#!sds fun` toDict {#safeds.data.tabular.typing.ExperimentalSchema.toDict data-toc-label='toDict'} - -Return a dictionary that maps column names to column types. - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `data` | [`Map`][safeds.lang.Map] | Dictionary representation of the schema. | - -**Examples:** - -```sds -pipeline example { - // from safeds.data.tabular.containers import ExperimentalTable - // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - // dict_ = table.schema.to_dict() -} -``` - -??? quote "Stub code in `ExperimentalSchema.sdsstub`" - - ```sds linenums="67" - @Pure - @PythonName("to_dict") - fun toDict() -> data: Map - ``` diff --git a/docs/api/safeds/data/tabular/typing/Schema.md b/docs/api/safeds/data/tabular/typing/Schema.md index 6c56677f7..807290e73 100644 --- a/docs/api/safeds/data/tabular/typing/Schema.md +++ b/docs/api/safeds/data/tabular/typing/Schema.md @@ -3,98 +3,80 @@ search: boost: 0.5 --- -# :test_tube:{ title="Experimental" } `#!sds abstract class` Schema {#safeds.data.tabular.typing.Schema data-toc-label='Schema'} +# `#!sds abstract class` Schema {#safeds.data.tabular.typing.Schema data-toc-label='Schema'} -Store column names and corresponding data types for a `Table` or `Row`. - -**Examples:** - -```sds -pipeline example { - // TODO -} -``` +The schema of a row or table. ??? quote "Stub code in `Schema.sdsstub`" - ```sds linenums="16" + ```sds linenums="8" class Schema { /** - * Return a list of all column names saved in this schema. - * - * @example - * pipeline example { - * // TODO - * } + * Return a list of all column names contained in this schema. */ @PythonName("column_names") attr columnNames: List /** - * Return whether the schema contains a given column. + * Return the type of the given column. * - * @param columnName The name of the column. + * @param name The name of the column. * - * @result result1 True if the schema contains the column. + * @result type The type of the column. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val type = table.^schema.getColumnType("A"); * } */ @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> result1: Boolean + @PythonName("get_column_type") + fun getColumnType( + name: String + ) -> type: DataType /** - * Return the type of the given column. + * Return whether the schema contains a given column. * - * @param columnName The name of the column. + * @param name The name of the column. * - * @result result1 The type of the column. + * @result contains True if the schema contains the column. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val contains = table.^schema.hasColumn("A"); // true * } */ @Pure - @PythonName("get_column_type") - fun getColumnType( - @PythonName("column_name") columnName: String - ) -> result1: ColumnType + @PythonName("has_column") + fun hasColumn( + name: String + ) -> contains: Boolean /** * Return a dictionary that maps column names to column types. * - * @result result1 Dictionary representation of the schema. + * @result data Dictionary representation of the schema. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val map = table.^schema.toMap(); * } */ @Pure @PythonName("to_dict") - fun toDict() -> result1: Map + fun toMap() -> data: Map } ``` ## `#!sds attr` columnNames {#safeds.data.tabular.typing.Schema.columnNames data-toc-label='columnNames'} -Return a list of all column names saved in this schema. +Return a list of all column names contained in this schema. **Type:** [`List`][safeds.lang.List] -**Examples:** - -```sds -pipeline example { - // TODO -} -``` - ## `#!sds fun` getColumnType {#safeds.data.tabular.typing.Schema.getColumnType data-toc-label='getColumnType'} Return the type of the given column. @@ -103,30 +85,31 @@ Return the type of the given column. | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The name of the column. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`ColumnType`][safeds.data.tabular.typing.ColumnType] | The type of the column. | +| `type` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the column. | **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // TODO + val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + val type = table.^schema.getColumnType("A"); } ``` ??? quote "Stub code in `Schema.sdsstub`" - ```sds linenums="57" + ```sds linenums="27" @Pure @PythonName("get_column_type") fun getColumnType( - @PythonName("column_name") columnName: String - ) -> result1: ColumnType + name: String + ) -> type: DataType ``` ## `#!sds fun` hasColumn {#safeds.data.tabular.typing.Schema.hasColumn data-toc-label='hasColumn'} @@ -137,33 +120,34 @@ Return whether the schema contains a given column. | Name | Type | Description | Default | |------|------|-------------|---------| -| `columnName` | [`String`][safeds.lang.String] | The name of the column. | - | +| `name` | [`String`][safeds.lang.String] | The name of the column. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `result1` | [`Boolean`][safeds.lang.Boolean] | True if the schema contains the column. | +| `contains` | [`Boolean`][safeds.lang.Boolean] | True if the schema contains the column. | **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // TODO + val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + val contains = table.^schema.hasColumn("A"); // true } ``` ??? quote "Stub code in `Schema.sdsstub`" - ```sds linenums="39" + ```sds linenums="46" @Pure @PythonName("has_column") fun hasColumn( - @PythonName("column_name") columnName: String - ) -> result1: Boolean + name: String + ) -> contains: Boolean ``` -## `#!sds fun` toDict {#safeds.data.tabular.typing.Schema.toDict data-toc-label='toDict'} +## `#!sds fun` toMap {#safeds.data.tabular.typing.Schema.toMap data-toc-label='toMap'} Return a dictionary that maps column names to column types. @@ -171,20 +155,21 @@ Return a dictionary that maps column names to column types. | Name | Type | Description | |------|------|-------------| -| `result1` | [`Map`][safeds.lang.Map] | Dictionary representation of the schema. | +| `data` | [`Map`][safeds.lang.Map] | Dictionary representation of the schema. | **Examples:** -```sds +```sds hl_lines="3" pipeline example { - // TODO + val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + val map = table.^schema.toMap(); } ``` ??? quote "Stub code in `Schema.sdsstub`" - ```sds linenums="73" + ```sds linenums="63" @Pure @PythonName("to_dict") - fun toDict() -> result1: Map + fun toMap() -> data: Map ``` diff --git a/docs/api/safeds/ml/classical/SupervisedModel.md b/docs/api/safeds/ml/classical/SupervisedModel.md new file mode 100644 index 000000000..133ba5e53 --- /dev/null +++ b/docs/api/safeds/ml/classical/SupervisedModel.md @@ -0,0 +1,236 @@ +--- +search: + boost: 0.5 +--- + +# `#!sds abstract class` SupervisedModel {#safeds.ml.classical.SupervisedModel data-toc-label='SupervisedModel'} + +A model for supervised learning tasks. + +**Inheritors:** + +- [`Classifier`][safeds.ml.classical.classification.Classifier] +- [`Regressor`][safeds.ml.classical.regression.Regressor] + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="11" + class SupervisedModel { + /** + * Whether the model is fitted. + */ + @PythonName("is_fitted") attr isFitted: Boolean + + /** + * Create a copy of this model and fit it with the given training data. + * + * **Note:** This model is not modified. + * + * @param trainingSet The training data containing the features and target. + * + * @result fittedModel The fitted model. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedModel: SupervisedModel + + /** + * Predict the target values on the given dataset. + * + * **Note:** The model must be fitted. + * + * @param dataset The dataset containing at least the features. + * + * @result prediction The given dataset with an additional column for the predicted target values. + */ + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + + /** + * Return the names of the feature columns. + * + * **Note:** The model must be fitted. + * + * @result featureNames The names of the feature columns. + */ + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + + /** + * Return the schema of the feature columns. + * + * **Note:** The model must be fitted. + * + * @result featureSchema The schema of the feature columns. + */ + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + + /** + * Return the name of the target column. + * + * **Note:** The model must be fitted. + * + * @result targetName The name of the target column. + */ + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + + /** + * Return the type of the target column. + * + * **Note:** The model must be fitted. + * + * @result targetType The type of the target column. + */ + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + } + ``` + +## `#!sds attr` isFitted {#safeds.ml.classical.SupervisedModel.isFitted data-toc-label='isFitted'} + +Whether the model is fitted. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds fun` fit {#safeds.ml.classical.SupervisedModel.fit data-toc-label='fit'} + +Create a copy of this model and fit it with the given training data. + +**Note:** This model is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the features and target. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedModel` | [`SupervisedModel`][safeds.ml.classical.SupervisedModel] | The fitted model. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="26" + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedModel: SupervisedModel + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.SupervisedModel.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.SupervisedModel.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.SupervisedModel.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.SupervisedModel.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + +## `#!sds fun` predict {#safeds.ml.classical.SupervisedModel.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + ``` diff --git a/docs/api/safeds/ml/classical/classification/AdaBoostClassifier.md b/docs/api/safeds/ml/classical/classification/AdaBoostClassifier.md index 2307e5f08..6ea5d4978 100644 --- a/docs/api/safeds/ml/classical/classification/AdaBoostClassifier.md +++ b/docs/api/safeds/ml/classical/classification/AdaBoostClassifier.md @@ -9,7 +9,7 @@ Ada Boost classification. | Name | Type | Description | Default | |------|------|-------------|---------| | `learner` | [`Classifier`][safeds.ml.classical.classification.Classifier] | The learner from which the boosted ensemble is built. | `#!sds DecisionTreeClassifier()` | -| `maximumNumberOfLearners` | [`Int`][safeds.lang.Int] | The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Has to be greater than 0. | `#!sds 50` | +| `maxLearnerCount` | [`Int`][safeds.lang.Int] | The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Has to be greater than 0. | `#!sds 50` | | `learningRate` | [`Float`][safeds.lang.Float] | Weight applied to each classifier at each boosting iteration. A higher learning rate increases the contribution of each classifier. Has to be greater than 0. | `#!sds 1.0` | **Examples:** @@ -18,7 +18,7 @@ Ada Boost classification. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val classifier = AdaBoostClassifier(maximumNumberOfLearners = 100).fit(training); + val classifier = AdaBoostClassifier(maxLearnerCount = 100).fit(training); val accuracy = classifier.accuracy(test); } ``` @@ -28,10 +28,10 @@ pipeline example { ```sds linenums="24" class AdaBoostClassifier( learner: Classifier = DecisionTreeClassifier(), - @PythonName("maximum_number_of_learners") const maximumNumberOfLearners: Int = 50, + @PythonName("maximum_number_of_learners") const maxLearnerCount: Int = 50, @PythonName("learning_rate") const learningRate: Float = 1.0 ) sub Classifier where { - maximumNumberOfLearners >= 1, + maxLearnerCount >= 1, learningRate > 0.0 } { /** @@ -41,7 +41,7 @@ pipeline example { /** * Get the maximum number of learners in the ensemble. */ - @PythonName("maximum_number_of_learners") attr maximumNumberOfLearners: Int + @PythonName("maximum_number_of_learners") attr maxLearnerCount: Int /** * Get the learning rate. */ @@ -58,14 +58,14 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: AdaBoostClassifier } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.AdaBoostClassifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -81,7 +81,7 @@ Get the learning rate. **Type:** [`Float`][safeds.lang.Float] -## `#!sds attr` maximumNumberOfLearners {#safeds.ml.classical.classification.AdaBoostClassifier.maximumNumberOfLearners data-toc-label='maximumNumberOfLearners'} +## `#!sds attr` maxLearnerCount {#safeds.ml.classical.classification.AdaBoostClassifier.maxLearnerCount data-toc-label='maxLearnerCount'} Get the maximum number of learners in the ensemble. @@ -91,51 +91,61 @@ Get the maximum number of learners in the ensemble. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.AdaBoostClassifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` @@ -150,7 +160,7 @@ This classifier is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -163,59 +173,146 @@ This classifier is not modified. ```sds linenums="54" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: AdaBoostClassifier ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.AdaBoostClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.AdaBoostClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.AdaBoostClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.AdaBoostClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` precision {#safeds.ml.classical.classification.AdaBoostClassifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.AdaBoostClassifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -223,25 +320,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -250,11 +352,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -265,11 +369,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/Classifier.md b/docs/api/safeds/ml/classical/classification/Classifier.md index 8693ee45b..429b5b82b 100644 --- a/docs/api/safeds/ml/classical/classification/Classifier.md +++ b/docs/api/safeds/ml/classical/classification/Classifier.md @@ -5,7 +5,9 @@ search: # `#!sds abstract class` Classifier {#safeds.ml.classical.classification.Classifier data-toc-label='Classifier'} -Abstract base class for all classifiers. +A model for classification tasks. + +**Parent type:** [`SupervisedModel`][safeds.ml.classical.SupervisedModel] **Inheritors:** @@ -13,48 +15,21 @@ Abstract base class for all classifiers. - [`DecisionTreeClassifier`][safeds.ml.classical.classification.DecisionTreeClassifier] - [`GradientBoostingClassifier`][safeds.ml.classical.classification.GradientBoostingClassifier] - [`KNearestNeighborsClassifier`][safeds.ml.classical.classification.KNearestNeighborsClassifier] -- [`LogisticRegressionClassifier`][safeds.ml.classical.classification.LogisticRegressionClassifier] +- [`LogisticClassifier`][safeds.ml.classical.classification.LogisticClassifier] +- `#!sds LogisticRegressionClassifier` - [`RandomForestClassifier`][safeds.ml.classical.classification.RandomForestClassifier] -- [`SupportVectorMachineClassifier`][safeds.ml.classical.classification.SupportVectorMachineClassifier] +- [`SupportVectorClassifier`][safeds.ml.classical.classification.SupportVectorClassifier] +- `#!sds SupportVectorMachineClassifier` ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="9" - class Classifier { - /** - * Whether the classifier is fitted. - */ - @PythonName("is_fitted") attr isFitted: Boolean - - /** - * Create a copy of this classifier and fit it with the given training data. - * - * This classifier is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedClassifier The fitted classifier. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: Classifier - - /** - * Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - * - * @param dataset The dataset containing the feature vectors. - * - * @result prediction A dataset containing the given feature vectors and the predicted target vector. - */ - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - + ```sds linenums="10" + class Classifier sub SupervisedModel { /** * Summarize the classifier's metrics on the given data. * + * **Note:** The model must be fitted. + * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * @@ -63,73 +38,90 @@ Abstract base class for all classifiers. @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table /** * Compute the accuracy of the classifier on the given data. * + * The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the + * better. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. + * * @param validationOrTestSet The validation or test set. * - * @result accuracy The calculated accuracy score, i.e. the percentage of equal data. + * @result accuracy The classifier's accuracy. */ @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float /** - * Compute the classifier's precision on the given data. + * Compute the classifier's F₁ score on the given data. + * + * The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the + * classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result precision The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. - * Return 1 if no positive predictions are made. + * @result f1Score The classifier's F₁ score. */ @Pure - fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("f1_score") + fun f1Score( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> precision: Float + ) -> f1Score: Float /** - * Compute the classifier's recall on the given data. + * Compute the classifier's precision on the given data. + * + * The precision is the proportion of positive predictions that were correct. The **higher** the precision, the + * better the classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result recall The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. - * Return 1 if there are no positive expectations. + * @result precision The classifier's precision. */ @Pure - fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + fun precision( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> recall: Float + ) -> precision: Float /** - * Compute the classifier's $F_1$-score on the given data. + * Compute the classifier's recall on the given data. + * + * The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the + * better the classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result f1Score The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. - * Return 1 if there are no positive expectations and predictions. + * @result recall The classifier's recall. */ @Pure - @PythonName("f1_score") - fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + fun recall( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> f1Score: Float + ) -> recall: Float } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.Classifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -137,131 +129,228 @@ Whether the classifier is fitted. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.Classifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` ## `#!sds fun` fit {#safeds.ml.classical.classification.Classifier.fit data-toc-label='fit'} -Create a copy of this classifier and fit it with the given training data. +Create a copy of this model and fit it with the given training data. -This classifier is not modified. +**Note:** This model is not modified. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the features and target. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedClassifier` | [`Classifier`][safeds.ml.classical.classification.Classifier] | The fitted classifier. | +| `fittedModel` | [`SupervisedModel`][safeds.ml.classical.SupervisedModel] | The fitted model. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="24" + ```sds linenums="26" @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: Classifier + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedModel: SupervisedModel + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.Classifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.Classifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.Classifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.Classifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType ``` ## `#!sds fun` precision {#safeds.ml.classical.classification.Classifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.Classifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -269,25 +358,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -296,11 +390,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -311,11 +407,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/DecisionTreeClassifier.md b/docs/api/safeds/ml/classical/classification/DecisionTreeClassifier.md index a6bddec57..a01cbf1c6 100644 --- a/docs/api/safeds/ml/classical/classification/DecisionTreeClassifier.md +++ b/docs/api/safeds/ml/classical/classification/DecisionTreeClassifier.md @@ -8,8 +8,8 @@ Decision tree classification. | Name | Type | Description | Default | |------|------|-------------|---------| -| `maximumDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | -| `minimumNumberOfSamplesInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | +| `maxDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | +| `minSampleCountInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | **Examples:** @@ -24,21 +24,21 @@ pipeline example { ??? quote "Stub code in `DecisionTreeClassifier.sdsstub`" - ```sds linenums="23" + ```sds linenums="20" class DecisionTreeClassifier( - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1 + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1 ) sub Classifier where { - minimumNumberOfSamplesInLeaves > 0 + minSampleCountInLeaves > 0 } { /** * The maximum depth of the tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of the tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -51,24 +51,24 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: DecisionTreeClassifier } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.DecisionTreeClassifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` maximumDepth {#safeds.ml.classical.classification.DecisionTreeClassifier.maximumDepth data-toc-label='maximumDepth'} +## `#!sds attr` maxDepth {#safeds.ml.classical.classification.DecisionTreeClassifier.maxDepth data-toc-label='maxDepth'} The maximum depth of the tree. **Type:** [`Int?`][safeds.lang.Int] -## `#!sds attr` minimumNumberOfSamplesInLeaves {#safeds.ml.classical.classification.DecisionTreeClassifier.minimumNumberOfSamplesInLeaves data-toc-label='minimumNumberOfSamplesInLeaves'} +## `#!sds attr` minSampleCountInLeaves {#safeds.ml.classical.classification.DecisionTreeClassifier.minSampleCountInLeaves data-toc-label='minSampleCountInLeaves'} The minimum number of samples that must remain in the leaves of the tree. @@ -78,51 +78,61 @@ The minimum number of samples that must remain in the leaves of the tree. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.DecisionTreeClassifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` @@ -137,7 +147,7 @@ This classifier is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -147,62 +157,149 @@ This classifier is not modified. ??? quote "Stub code in `DecisionTreeClassifier.sdsstub`" - ```sds linenums="47" + ```sds linenums="44" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: DecisionTreeClassifier ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.DecisionTreeClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.DecisionTreeClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.DecisionTreeClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.DecisionTreeClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` precision {#safeds.ml.classical.classification.DecisionTreeClassifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.DecisionTreeClassifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -210,25 +307,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -237,11 +339,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -252,11 +356,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/GradientBoostingClassifier.md b/docs/api/safeds/ml/classical/classification/GradientBoostingClassifier.md index 7c2e1963d..ecce32044 100644 --- a/docs/api/safeds/ml/classical/classification/GradientBoostingClassifier.md +++ b/docs/api/safeds/ml/classical/classification/GradientBoostingClassifier.md @@ -8,7 +8,7 @@ Gradient boosting classification. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfTrees` | [`Int`][safeds.lang.Int] | The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large number usually results in better performance. | `#!sds 100` | +| `treeCount` | [`Int`][safeds.lang.Int] | The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large number usually results in better performance. | `#!sds 100` | | `learningRate` | [`Float`][safeds.lang.Float] | The larger the value, the more the model is influenced by each additional tree. If the learning rate is too low, the model might underfit. If the learning rate is too high, the model might overfit. | `#!sds 0.1` | **Examples:** @@ -17,7 +17,7 @@ Gradient boosting classification. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val classifier = GradientBoostingClassifier(numberOfTrees = 50).fit(training); + val classifier = GradientBoostingClassifier(treeCount = 50).fit(training); val accuracy = classifier.accuracy(test); } ``` @@ -26,16 +26,16 @@ pipeline example { ```sds linenums="23" class GradientBoostingClassifier( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, + @PythonName("number_of_trees") const treeCount: Int = 100, @PythonName("learning_rate") const learningRate: Float = 0.1 ) sub Classifier where { - numberOfTrees >= 1, + treeCount >= 1, learningRate > 0.0 } { /** * Get the number of trees (estimators) in the ensemble. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * Get the learning rate. */ @@ -52,14 +52,14 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: GradientBoostingClassifier } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.GradientBoostingClassifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -69,7 +69,7 @@ Get the learning rate. **Type:** [`Float`][safeds.lang.Float] -## `#!sds attr` numberOfTrees {#safeds.ml.classical.classification.GradientBoostingClassifier.numberOfTrees data-toc-label='numberOfTrees'} +## `#!sds attr` treeCount {#safeds.ml.classical.classification.GradientBoostingClassifier.treeCount data-toc-label='treeCount'} Get the number of trees (estimators) in the ensemble. @@ -79,51 +79,61 @@ Get the number of trees (estimators) in the ensemble. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.GradientBoostingClassifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` @@ -138,7 +148,7 @@ This classifier is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -151,59 +161,146 @@ This classifier is not modified. ```sds linenums="48" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: GradientBoostingClassifier ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.GradientBoostingClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.GradientBoostingClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.GradientBoostingClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.GradientBoostingClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` precision {#safeds.ml.classical.classification.GradientBoostingClassifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.GradientBoostingClassifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -211,25 +308,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -238,11 +340,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -253,11 +357,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/KNearestNeighborsClassifier.md b/docs/api/safeds/ml/classical/classification/KNearestNeighborsClassifier.md index 5b078fa72..66d04bfe3 100644 --- a/docs/api/safeds/ml/classical/classification/KNearestNeighborsClassifier.md +++ b/docs/api/safeds/ml/classical/classification/KNearestNeighborsClassifier.md @@ -8,7 +8,7 @@ K-nearest-neighbors classification. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfNeighbors` | [`Int`][safeds.lang.Int] | The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and less than or equal to the sample size (validated when calling `fit`). | - | +| `neighborCount` | [`Int`][safeds.lang.Int] | The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and less than or equal to the sample size (validated when calling `fit`). | - | **Examples:** @@ -25,14 +25,14 @@ pipeline example { ```sds linenums="21" class KNearestNeighborsClassifier( - @PythonName("number_of_neighbors") const numberOfNeighbors: Int + @PythonName("number_of_neighbors") const neighborCount: Int ) sub Classifier where { - numberOfNeighbors >= 1 + neighborCount >= 1 } { /** * Get the number of neighbors used for interpolation. */ - @PythonName("number_of_neighbors") attr numberOfNeighbors: Int + @PythonName("number_of_neighbors") attr neighborCount: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -45,18 +45,18 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: KNearestNeighborsClassifier } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.KNearestNeighborsClassifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` numberOfNeighbors {#safeds.ml.classical.classification.KNearestNeighborsClassifier.numberOfNeighbors data-toc-label='numberOfNeighbors'} +## `#!sds attr` neighborCount {#safeds.ml.classical.classification.KNearestNeighborsClassifier.neighborCount data-toc-label='neighborCount'} Get the number of neighbors used for interpolation. @@ -66,51 +66,61 @@ Get the number of neighbors used for interpolation. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.KNearestNeighborsClassifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` @@ -125,7 +135,7 @@ This classifier is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -138,59 +148,146 @@ This classifier is not modified. ```sds linenums="40" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: KNearestNeighborsClassifier ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.KNearestNeighborsClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.KNearestNeighborsClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.KNearestNeighborsClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.KNearestNeighborsClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` precision {#safeds.ml.classical.classification.KNearestNeighborsClassifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.KNearestNeighborsClassifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -198,25 +295,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -225,11 +327,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -240,11 +344,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/LogisticClassifier.md b/docs/api/safeds/ml/classical/classification/LogisticClassifier.md new file mode 100644 index 000000000..ff3e7f689 --- /dev/null +++ b/docs/api/safeds/ml/classical/classification/LogisticClassifier.md @@ -0,0 +1,333 @@ +# `#!sds class` LogisticClassifier {#safeds.ml.classical.classification.LogisticClassifier data-toc-label='LogisticClassifier'} + +Regularized logistic regression. + +**Parent type:** [`Classifier`][safeds.ml.classical.classification.Classifier] + +**Examples:** + +```sds hl_lines="4" +pipeline example { + val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); + val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); + val classifier = LogisticClassifier().fit(training); + val accuracy = classifier.accuracy(test); +} +``` + +??? quote "Stub code in `LogisticClassifier.sdsstub`" + + ```sds linenums="18" + class LogisticClassifier() sub Classifier { + /** + * Create a copy of this classifier and fit it with the given training data. + * + * This classifier is not modified. + * + * @param trainingSet The training data containing the feature and target vectors. + * + * @result fittedClassifier The fitted classifier. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: LogisticClassifier + } + ``` + +## `#!sds attr` isFitted {#safeds.ml.classical.classification.LogisticClassifier.isFitted data-toc-label='isFitted'} + +Whether the model is fitted. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds fun` accuracy {#safeds.ml.classical.classification.LogisticClassifier.accuracy data-toc-label='accuracy'} + +Compute the accuracy of the classifier on the given data. + +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="40" + @Pure + fun accuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> accuracy: Float + ``` + +## `#!sds fun` f1Score {#safeds.ml.classical.classification.LogisticClassifier.f1Score data-toc-label='f1Score'} + +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="58" + @Pure + @PythonName("f1_score") + fun f1Score( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> f1Score: Float + ``` + +## `#!sds fun` fit {#safeds.ml.classical.classification.LogisticClassifier.fit data-toc-label='fit'} + +Create a copy of this classifier and fit it with the given training data. + +This classifier is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedClassifier` | [`LogisticClassifier`][safeds.ml.classical.classification.LogisticClassifier] | The fitted classifier. | + +??? quote "Stub code in `LogisticClassifier.sdsstub`" + + ```sds linenums="28" + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: LogisticClassifier + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.LogisticClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.LogisticClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.LogisticClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.LogisticClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + +## `#!sds fun` precision {#safeds.ml.classical.classification.LogisticClassifier.precision data-toc-label='precision'} + +Compute the classifier's precision on the given data. + +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="78" + @Pure + fun precision( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> precision: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.classification.LogisticClassifier.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + ``` + +## `#!sds fun` recall {#safeds.ml.classical.classification.LogisticClassifier.recall data-toc-label='recall'} + +Compute the classifier's recall on the given data. + +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="97" + @Pure + fun recall( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> recall: Float + ``` + +## `#!sds fun` summarizeMetrics {#safeds.ml.classical.classification.LogisticClassifier.summarizeMetrics data-toc-label='summarizeMetrics'} + +Summarize the classifier's metrics on the given data. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the classifier's metrics. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="21" + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> metrics: Table + ``` diff --git a/docs/api/safeds/ml/classical/classification/LogisticRegressionClassifier.md b/docs/api/safeds/ml/classical/classification/LogisticRegressionClassifier.md deleted file mode 100644 index d8ef3c928..000000000 --- a/docs/api/safeds/ml/classical/classification/LogisticRegressionClassifier.md +++ /dev/null @@ -1,229 +0,0 @@ -# `#!sds class` LogisticRegressionClassifier {#safeds.ml.classical.classification.LogisticRegressionClassifier data-toc-label='LogisticRegressionClassifier'} - -Regularized logistic regression. - -**Parent type:** [`Classifier`][safeds.ml.classical.classification.Classifier] - -**Examples:** - -```sds hl_lines="4" -pipeline example { - val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); - val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val classifier = LogisticRegressionClassifier().fit(training); - val accuracy = classifier.accuracy(test); -} -``` - -??? quote "Stub code in `LogisticRegressionClassifier.sdsstub`" - - ```sds linenums="18" - class LogisticRegressionClassifier() sub Classifier { - /** - * Create a copy of this classifier and fit it with the given training data. - * - * This classifier is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedClassifier The fitted classifier. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: LogisticRegressionClassifier - } - ``` - -## `#!sds attr` isFitted {#safeds.ml.classical.classification.LogisticRegressionClassifier.isFitted data-toc-label='isFitted'} - -Whether the classifier is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` accuracy {#safeds.ml.classical.classification.LogisticRegressionClassifier.accuracy data-toc-label='accuracy'} - -Compute the accuracy of the classifier on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="63" - @Pure - fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> accuracy: Float - ``` - -## `#!sds fun` f1Score {#safeds.ml.classical.classification.LogisticRegressionClassifier.f1Score data-toc-label='f1Score'} - -Compute the classifier's $F_1$-score on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="107" - @Pure - @PythonName("f1_score") - fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> f1Score: Float - ``` - -## `#!sds fun` fit {#safeds.ml.classical.classification.LogisticRegressionClassifier.fit data-toc-label='fit'} - -Create a copy of this classifier and fit it with the given training data. - -This classifier is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedClassifier` | [`LogisticRegressionClassifier`][safeds.ml.classical.classification.LogisticRegressionClassifier] | The fitted classifier. | - -??? quote "Stub code in `LogisticRegressionClassifier.sdsstub`" - - ```sds linenums="28" - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: LogisticRegressionClassifier - ``` - -## `#!sds fun` precision {#safeds.ml.classical.classification.LogisticRegressionClassifier.precision data-toc-label='precision'} - -Compute the classifier's precision on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="77" - @Pure - fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> precision: Float - ``` - -## `#!sds fun` predict {#safeds.ml.classical.classification.LogisticRegressionClassifier.predict data-toc-label='predict'} - -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="36" - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - ``` - -## `#!sds fun` recall {#safeds.ml.classical.classification.LogisticRegressionClassifier.recall data-toc-label='recall'} - -Compute the classifier's recall on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="92" - @Pure - fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> recall: Float - ``` - -## `#!sds fun` summarizeMetrics {#safeds.ml.classical.classification.LogisticRegressionClassifier.summarizeMetrics data-toc-label='summarizeMetrics'} - -Summarize the classifier's metrics on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the classifier's metrics. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> metrics: Table - ``` diff --git a/docs/api/safeds/ml/classical/classification/RandomForestClassifier.md b/docs/api/safeds/ml/classical/classification/RandomForestClassifier.md index 9b7ac2224..8236c72f7 100644 --- a/docs/api/safeds/ml/classical/classification/RandomForestClassifier.md +++ b/docs/api/safeds/ml/classical/classification/RandomForestClassifier.md @@ -8,9 +8,9 @@ Random forest classification. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfTrees` | [`Int`][safeds.lang.Int] | The number of trees to be used in the random forest. Has to be greater than 0. | `#!sds 100` | -| `maximumDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If None, the depth is not limited. Has to be greater than 0. | `#!sds null` | -| `minimumNumberOfSamplesInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | +| `treeCount` | [`Int`][safeds.lang.Int] | The number of trees to be used in the random forest. Has to be greater than 0. | `#!sds 100` | +| `maxDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | +| `minSampleCountInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | **Examples:** @@ -18,7 +18,7 @@ Random forest classification. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val classifier = RandomForestClassifier(numberOfTrees = 10).fit(training); + val classifier = RandomForestClassifier(treeCount = 10).fit(training); val accuracy = classifier.accuracy(test); } ``` @@ -27,25 +27,25 @@ pipeline example { ```sds linenums="22" class RandomForestClassifier( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1, + @PythonName("number_of_trees") const treeCount: Int = 100, + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1, ) sub Classifier where { - numberOfTrees > 0, - minimumNumberOfSamplesInLeaves > 0, + treeCount > 0, + minSampleCountInLeaves > 0, } { /** * Get the number of trees used in the random forest. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * The maximum depth of each tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of each tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -58,30 +58,30 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: RandomForestClassifier } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.classification.RandomForestClassifier.isFitted data-toc-label='isFitted'} -Whether the classifier is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` maximumDepth {#safeds.ml.classical.classification.RandomForestClassifier.maximumDepth data-toc-label='maximumDepth'} +## `#!sds attr` maxDepth {#safeds.ml.classical.classification.RandomForestClassifier.maxDepth data-toc-label='maxDepth'} The maximum depth of each tree. **Type:** [`Int?`][safeds.lang.Int] -## `#!sds attr` minimumNumberOfSamplesInLeaves {#safeds.ml.classical.classification.RandomForestClassifier.minimumNumberOfSamplesInLeaves data-toc-label='minimumNumberOfSamplesInLeaves'} +## `#!sds attr` minSampleCountInLeaves {#safeds.ml.classical.classification.RandomForestClassifier.minSampleCountInLeaves data-toc-label='minSampleCountInLeaves'} The minimum number of samples that must remain in the leaves of each tree. **Type:** [`Int`][safeds.lang.Int] -## `#!sds attr` numberOfTrees {#safeds.ml.classical.classification.RandomForestClassifier.numberOfTrees data-toc-label='numberOfTrees'} +## `#!sds attr` treeCount {#safeds.ml.classical.classification.RandomForestClassifier.treeCount data-toc-label='treeCount'} Get the number of trees used in the random forest. @@ -91,51 +91,61 @@ Get the number of trees used in the random forest. Compute the accuracy of the classifier on the given data. +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="63" + ```sds linenums="40" @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float ``` ## `#!sds fun` f1Score {#safeds.ml.classical.classification.RandomForestClassifier.f1Score data-toc-label='f1Score'} -Compute the classifier's $F_1$-score on the given data. +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="107" + ```sds linenums="58" @Pure @PythonName("f1_score") fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> f1Score: Float ``` @@ -150,7 +160,7 @@ This classifier is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -163,59 +173,146 @@ This classifier is not modified. ```sds linenums="52" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: RandomForestClassifier ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.RandomForestClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.RandomForestClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.RandomForestClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.RandomForestClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` precision {#safeds.ml.classical.classification.RandomForestClassifier.precision data-toc-label='precision'} Compute the classifier's precision on the given data. +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="77" + ```sds linenums="78" @Pure fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> precision: Float ``` ## `#!sds fun` predict {#safeds.ml.classical.classification.RandomForestClassifier.predict data-toc-label='predict'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Predict the target values on the given dataset. + +**Note:** The model must be fitted. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | -??? quote "Stub code in `Classifier.sdsstub`" +??? quote "Stub code in `SupervisedModel.sdsstub`" - ```sds linenums="36" + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -223,25 +320,30 @@ Predict a target vector using a dataset containing feature vectors. The model ha Compute the classifier's recall on the given data. +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="92" + ```sds linenums="97" @Pure fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> recall: Float ``` @@ -250,11 +352,13 @@ Compute the classifier's recall on the given data. Summarize the classifier's metrics on the given data. +**Note:** The model must be fitted. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | | `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | **Results:** @@ -265,11 +369,11 @@ Summarize the classifier's metrics on the given data. ??? quote "Stub code in `Classifier.sdsstub`" - ```sds linenums="49" + ```sds linenums="21" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/classification/SupportVectorClassifier.md b/docs/api/safeds/ml/classical/classification/SupportVectorClassifier.md new file mode 100644 index 000000000..2cdd88581 --- /dev/null +++ b/docs/api/safeds/ml/classical/classification/SupportVectorClassifier.md @@ -0,0 +1,461 @@ +# `#!sds class` SupportVectorClassifier {#safeds.ml.classical.classification.SupportVectorClassifier data-toc-label='SupportVectorClassifier'} + +Support vector machine for classification. + +**Parent type:** [`Classifier`][safeds.ml.classical.classification.Classifier] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `c` | [`Float`][safeds.lang.Float] | The strength of regularization. Must be greater than 0. | `#!sds 1.0` | +| `kernel` | [`Kernel`][safeds.ml.classical.classification.SupportVectorClassifier.Kernel] | The type of kernel to be used. Defaults to a radial basis function kernel. | `#!sds SupportVectorClassifier.Kernel.RadialBasisFunction` | + +**Examples:** + +```sds hl_lines="4 5" +pipeline example { + val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); + val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); + val classifier = SupportVectorClassifier( + kernel = SupportVectorClassifier.Kernel.Linear + ).fit(training); + val accuracy = classifier.accuracy(test); +} +``` + +??? quote "Stub code in `SupportVectorClassifier.sdsstub`" + + ```sds linenums="23" + class SupportVectorClassifier( + const c: Float = 1.0, + kernel: SupportVectorClassifier.Kernel = SupportVectorClassifier.Kernel.RadialBasisFunction + ) sub Classifier where { + c > 0.0 + } { + /** + * The kernel functions that can be used in the support vector machine. + */ + enum Kernel { + /** + * A linear kernel. + */ + @PythonName("linear") + Linear + + /** + * A polynomial kernel. + * + * @param degree The degree of the polynomial. + */ + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } + + /** + * A sigmoid kernel. + */ + @PythonName("sigmoid") + Sigmoid + + /** + * A radial basis function kernel. + */ + @PythonName("radial_basis_function") + RadialBasisFunction + } + + /** + * Get the regularization strength. + */ + attr c: Float + /** + * Get the type of kernel used. + */ + attr kernel: SupportVectorClassifier.Kernel + + /** + * Create a copy of this classifier and fit it with the given training data. + * + * This classifier is not modified. + * + * @param trainingSet The training data containing the feature and target vectors. + * + * @result fittedClassifier The fitted classifier. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: SupportVectorClassifier + } + ``` + +## `#!sds attr` c {#safeds.ml.classical.classification.SupportVectorClassifier.c data-toc-label='c'} + +Get the regularization strength. + +**Type:** [`Float`][safeds.lang.Float] + +## `#!sds attr` isFitted {#safeds.ml.classical.classification.SupportVectorClassifier.isFitted data-toc-label='isFitted'} + +Whether the model is fitted. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds attr` kernel {#safeds.ml.classical.classification.SupportVectorClassifier.kernel data-toc-label='kernel'} + +Get the type of kernel used. + +**Type:** [`Kernel`][safeds.ml.classical.classification.SupportVectorClassifier.Kernel] + +## `#!sds fun` accuracy {#safeds.ml.classical.classification.SupportVectorClassifier.accuracy data-toc-label='accuracy'} + +Compute the accuracy of the classifier on the given data. + +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `accuracy` | [`Float`][safeds.lang.Float] | The classifier's accuracy. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="40" + @Pure + fun accuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> accuracy: Float + ``` + +## `#!sds fun` f1Score {#safeds.ml.classical.classification.SupportVectorClassifier.f1Score data-toc-label='f1Score'} + +Compute the classifier's F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `f1Score` | [`Float`][safeds.lang.Float] | The classifier's F₁ score. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="58" + @Pure + @PythonName("f1_score") + fun f1Score( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> f1Score: Float + ``` + +## `#!sds fun` fit {#safeds.ml.classical.classification.SupportVectorClassifier.fit data-toc-label='fit'} + +Create a copy of this classifier and fit it with the given training data. + +This classifier is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedClassifier` | [`SupportVectorClassifier`][safeds.ml.classical.classification.SupportVectorClassifier] | The fitted classifier. | + +??? quote "Stub code in `SupportVectorClassifier.sdsstub`" + + ```sds linenums="80" + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: SupportVectorClassifier + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.classification.SupportVectorClassifier.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.classification.SupportVectorClassifier.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.classification.SupportVectorClassifier.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.classification.SupportVectorClassifier.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + +## `#!sds fun` precision {#safeds.ml.classical.classification.SupportVectorClassifier.precision data-toc-label='precision'} + +Compute the classifier's precision on the given data. + +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `precision` | [`Float`][safeds.lang.Float] | The classifier's precision. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="78" + @Pure + fun precision( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> precision: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.classification.SupportVectorClassifier.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + ``` + +## `#!sds fun` recall {#safeds.ml.classical.classification.SupportVectorClassifier.recall data-toc-label='recall'} + +Compute the classifier's recall on the given data. + +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `recall` | [`Float`][safeds.lang.Float] | The classifier's recall. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="97" + @Pure + fun recall( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> recall: Float + ``` + +## `#!sds fun` summarizeMetrics {#safeds.ml.classical.classification.SupportVectorClassifier.summarizeMetrics data-toc-label='summarizeMetrics'} + +Summarize the classifier's metrics on the given data. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the classifier's metrics. | + +??? quote "Stub code in `Classifier.sdsstub`" + + ```sds linenums="21" + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("positive_class") positiveClass: Any + ) -> metrics: Table + ``` + +## `#!sds enum` Kernel {#safeds.ml.classical.classification.SupportVectorClassifier.Kernel data-toc-label='Kernel'} + +The kernel functions that can be used in the support vector machine. + +??? quote "Stub code in `SupportVectorClassifier.sdsstub`" + + ```sds linenums="32" + enum Kernel { + /** + * A linear kernel. + */ + @PythonName("linear") + Linear + + /** + * A polynomial kernel. + * + * @param degree The degree of the polynomial. + */ + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } + + /** + * A sigmoid kernel. + */ + @PythonName("sigmoid") + Sigmoid + + /** + * A radial basis function kernel. + */ + @PythonName("radial_basis_function") + RadialBasisFunction + } + ``` + +### Linear {#safeds.ml.classical.classification.SupportVectorClassifier.Kernel.Linear data-toc-label='Linear'} + +A linear kernel. + +### Polynomial {#safeds.ml.classical.classification.SupportVectorClassifier.Kernel.Polynomial data-toc-label='Polynomial'} + +A polynomial kernel. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `degree` | [`Int`][safeds.lang.Int] | The degree of the polynomial. | - | + +### RadialBasisFunction {#safeds.ml.classical.classification.SupportVectorClassifier.Kernel.RadialBasisFunction data-toc-label='RadialBasisFunction'} + +A radial basis function kernel. + +### Sigmoid {#safeds.ml.classical.classification.SupportVectorClassifier.Kernel.Sigmoid data-toc-label='Sigmoid'} + +A sigmoid kernel. diff --git a/docs/api/safeds/ml/classical/classification/SupportVectorMachineClassifier.md b/docs/api/safeds/ml/classical/classification/SupportVectorMachineClassifier.md deleted file mode 100644 index 30fec0b4f..000000000 --- a/docs/api/safeds/ml/classical/classification/SupportVectorMachineClassifier.md +++ /dev/null @@ -1,345 +0,0 @@ -# `#!sds class` SupportVectorMachineClassifier {#safeds.ml.classical.classification.SupportVectorMachineClassifier data-toc-label='SupportVectorMachineClassifier'} - -Support vector machine. - -**Parent type:** [`Classifier`][safeds.ml.classical.classification.Classifier] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `c` | [`Float`][safeds.lang.Float] | The strength of regularization. Must be strictly positive. | `#!sds 1.0` | -| `kernel` | [`Kernel`][safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel] | The type of kernel to be used. Defaults to None. | `#!sds SupportVectorMachineClassifier.Kernel.RadialBasisFunction` | - -**Examples:** - -```sds hl_lines="4 5" -pipeline example { - val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); - val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val classifier = SupportVectorMachineClassifier( - kernel = SupportVectorMachineClassifier.Kernel.Linear - ).fit(training); - val accuracy = classifier.accuracy(test); -} -``` - -??? quote "Stub code in `SupportVectorMachineClassifier.sdsstub`" - - ```sds linenums="23" - class SupportVectorMachineClassifier( - const c: Float = 1.0, - kernel: SupportVectorMachineClassifier.Kernel = SupportVectorMachineClassifier.Kernel.RadialBasisFunction - ) sub Classifier where { - c > 0.0 - } { - /** - * The kernel functions that can be used in the support vector machine. - */ - enum Kernel { - /** - * A linear kernel. - */ - Linear - - /** - * A polynomial kernel. - * - * @param degree The degree of the polynomial. - */ - Polynomial(degree: Int) - - /** - * A sigmoid kernel. - */ - Sigmoid - - /** - * A radial basis function kernel. - */ - RadialBasisFunction - } - - /** - * Get the regularization strength. - */ - attr c: Float - /** - * Get the type of kernel used. - */ - attr kernel: SupportVectorMachineClassifier.Kernel - - /** - * Create a copy of this classifier and fit it with the given training data. - * - * This classifier is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedClassifier The fitted classifier. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: SupportVectorMachineClassifier - } - ``` - -## `#!sds attr` c {#safeds.ml.classical.classification.SupportVectorMachineClassifier.c data-toc-label='c'} - -Get the regularization strength. - -**Type:** [`Float`][safeds.lang.Float] - -## `#!sds attr` isFitted {#safeds.ml.classical.classification.SupportVectorMachineClassifier.isFitted data-toc-label='isFitted'} - -Whether the classifier is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` kernel {#safeds.ml.classical.classification.SupportVectorMachineClassifier.kernel data-toc-label='kernel'} - -Get the type of kernel used. - -**Type:** [`Kernel`][safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel] - -## `#!sds fun` accuracy {#safeds.ml.classical.classification.SupportVectorMachineClassifier.accuracy data-toc-label='accuracy'} - -Compute the accuracy of the classifier on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy score, i.e. the percentage of equal data. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="63" - @Pure - fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> accuracy: Float - ``` - -## `#!sds fun` f1Score {#safeds.ml.classical.classification.SupportVectorMachineClassifier.f1Score data-toc-label='f1Score'} - -Compute the classifier's $F_1$-score on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `f1Score` | [`Float`][safeds.lang.Float] | The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. Return 1 if there are no positive expectations and predictions. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="107" - @Pure - @PythonName("f1_score") - fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> f1Score: Float - ``` - -## `#!sds fun` fit {#safeds.ml.classical.classification.SupportVectorMachineClassifier.fit data-toc-label='fit'} - -Create a copy of this classifier and fit it with the given training data. - -This classifier is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedClassifier` | [`SupportVectorMachineClassifier`][safeds.ml.classical.classification.SupportVectorMachineClassifier] | The fitted classifier. | - -??? quote "Stub code in `SupportVectorMachineClassifier.sdsstub`" - - ```sds linenums="74" - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: SupportVectorMachineClassifier - ``` - -## `#!sds fun` precision {#safeds.ml.classical.classification.SupportVectorMachineClassifier.precision data-toc-label='precision'} - -Compute the classifier's precision on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `precision` | [`Float`][safeds.lang.Float] | The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. Return 1 if no positive predictions are made. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="77" - @Pure - fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> precision: Float - ``` - -## `#!sds fun` predict {#safeds.ml.classical.classification.SupportVectorMachineClassifier.predict data-toc-label='predict'} - -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="36" - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - ``` - -## `#!sds fun` recall {#safeds.ml.classical.classification.SupportVectorMachineClassifier.recall data-toc-label='recall'} - -Compute the classifier's recall on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `recall` | [`Float`][safeds.lang.Float] | The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. Return 1 if there are no positive expectations. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="92" - @Pure - fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> recall: Float - ``` - -## `#!sds fun` summarizeMetrics {#safeds.ml.classical.classification.SupportVectorMachineClassifier.summarizeMetrics data-toc-label='summarizeMetrics'} - -Summarize the classifier's metrics on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | -| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the classifier's metrics. | - -??? quote "Stub code in `Classifier.sdsstub`" - - ```sds linenums="49" - @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, - @PythonName("positive_class") positiveClass: Any - ) -> metrics: Table - ``` - -## `#!sds enum` Kernel {#safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel data-toc-label='Kernel'} - -The kernel functions that can be used in the support vector machine. - -??? quote "Stub code in `SupportVectorMachineClassifier.sdsstub`" - - ```sds linenums="32" - enum Kernel { - /** - * A linear kernel. - */ - Linear - - /** - * A polynomial kernel. - * - * @param degree The degree of the polynomial. - */ - Polynomial(degree: Int) - - /** - * A sigmoid kernel. - */ - Sigmoid - - /** - * A radial basis function kernel. - */ - RadialBasisFunction - } - ``` - -### Linear {#safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel.Linear data-toc-label='Linear'} - -A linear kernel. - -### Polynomial {#safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel.Polynomial data-toc-label='Polynomial'} - -A polynomial kernel. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `degree` | [`Int`][safeds.lang.Int] | The degree of the polynomial. | - | - -### RadialBasisFunction {#safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel.RadialBasisFunction data-toc-label='RadialBasisFunction'} - -A radial basis function kernel. - -### Sigmoid {#safeds.ml.classical.classification.SupportVectorMachineClassifier.Kernel.Sigmoid data-toc-label='Sigmoid'} - -A sigmoid kernel. diff --git a/docs/api/safeds/ml/classical/regression/AdaBoostRegressor.md b/docs/api/safeds/ml/classical/regression/AdaBoostRegressor.md index bb903560c..272adbb94 100644 --- a/docs/api/safeds/ml/classical/regression/AdaBoostRegressor.md +++ b/docs/api/safeds/ml/classical/regression/AdaBoostRegressor.md @@ -9,7 +9,7 @@ Ada Boost regression. | Name | Type | Description | Default | |------|------|-------------|---------| | `learner` | [`Regressor`][safeds.ml.classical.regression.Regressor] | The learner from which the boosted ensemble is built. | `#!sds DecisionTreeRegressor()` | -| `maximumNumberOfLearners` | [`Int`][safeds.lang.Int] | The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Has to be greater than 0. | `#!sds 50` | +| `maxLearnerCount` | [`Int`][safeds.lang.Int] | The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Has to be greater than 0. | `#!sds 50` | | `learningRate` | [`Float`][safeds.lang.Float] | Weight applied to each regressor at each boosting iteration. A higher learning rate increases the contribution of each regressor. Has to be greater than 0. | `#!sds 1.0` | **Examples:** @@ -18,7 +18,7 @@ Ada Boost regression. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = AdaBoostRegressor(maximumNumberOfLearners = 100).fit(training); + val regressor = AdaBoostRegressor(maxLearnerCount = 100).fit(training); val meanSquaredError = regressor.meanSquaredError(test); } ``` @@ -28,10 +28,10 @@ pipeline example { ```sds linenums="24" class AdaBoostRegressor( learner: Regressor = DecisionTreeRegressor(), - @PythonName("maximum_number_of_learners") const maximumNumberOfLearners: Int = 50, + @PythonName("maximum_number_of_learners") const maxLearnerCount: Int = 50, @PythonName("learning_rate") const learningRate: Float = 1.0 ) sub Regressor where { - maximumNumberOfLearners >= 1, + maxLearnerCount >= 1, learningRate > 0.0 } { /** @@ -41,7 +41,7 @@ pipeline example { /** * Get the maximum number of learners in the ensemble. */ - @PythonName("maximum_number_of_learners") attr maximumNumberOfLearners: Int + @PythonName("maximum_number_of_learners") attr maxLearnerCount: Int /** * Get the learning rate. */ @@ -58,14 +58,14 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: AdaBoostRegressor } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.AdaBoostRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -81,12 +81,53 @@ Get the learning rate. **Type:** [`Float`][safeds.lang.Float] -## `#!sds attr` maximumNumberOfLearners {#safeds.ml.classical.regression.AdaBoostRegressor.maximumNumberOfLearners data-toc-label='maximumNumberOfLearners'} +## `#!sds attr` maxLearnerCount {#safeds.ml.classical.regression.AdaBoostRegressor.maxLearnerCount data-toc-label='maxLearnerCount'} Get the maximum number of learners in the ensemble. **Type:** [`Int`][safeds.lang.Int] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.AdaBoostRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.AdaBoostRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -97,7 +138,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -110,84 +151,240 @@ This regressor is not modified. ```sds linenums="54" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: AdaBoostRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.AdaBoostRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.AdaBoostRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.AdaBoostRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.AdaBoostRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.AdaBoostRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.AdaBoostRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.AdaBoostRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.AdaBoostRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.AdaBoostRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.AdaBoostRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -199,7 +396,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -209,10 +406,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/DecisionTreeRegressor.md b/docs/api/safeds/ml/classical/regression/DecisionTreeRegressor.md index 05fe32be2..3cf0dbf58 100644 --- a/docs/api/safeds/ml/classical/regression/DecisionTreeRegressor.md +++ b/docs/api/safeds/ml/classical/regression/DecisionTreeRegressor.md @@ -8,8 +8,8 @@ Decision tree regression. | Name | Type | Description | Default | |------|------|-------------|---------| -| `maximumDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | -| `minimumNumberOfSamplesInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | +| `maxDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | +| `minSampleCountInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | **Examples:** @@ -26,19 +26,19 @@ pipeline example { ```sds linenums="21" class DecisionTreeRegressor( - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1 + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1 ) sub Regressor where { - minimumNumberOfSamplesInLeaves > 0 + minSampleCountInLeaves > 0 } { /** * The maximum depth of the tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of the tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -51,29 +51,70 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: DecisionTreeRegressor } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.DecisionTreeRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` maximumDepth {#safeds.ml.classical.regression.DecisionTreeRegressor.maximumDepth data-toc-label='maximumDepth'} +## `#!sds attr` maxDepth {#safeds.ml.classical.regression.DecisionTreeRegressor.maxDepth data-toc-label='maxDepth'} The maximum depth of the tree. **Type:** [`Int?`][safeds.lang.Int] -## `#!sds attr` minimumNumberOfSamplesInLeaves {#safeds.ml.classical.regression.DecisionTreeRegressor.minimumNumberOfSamplesInLeaves data-toc-label='minimumNumberOfSamplesInLeaves'} +## `#!sds attr` minSampleCountInLeaves {#safeds.ml.classical.regression.DecisionTreeRegressor.minSampleCountInLeaves data-toc-label='minSampleCountInLeaves'} The minimum number of samples that must remain in the leaves of the tree. **Type:** [`Int`][safeds.lang.Int] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.DecisionTreeRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.DecisionTreeRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -84,7 +125,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -97,84 +138,240 @@ This regressor is not modified. ```sds linenums="45" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: DecisionTreeRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.DecisionTreeRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.DecisionTreeRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.DecisionTreeRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.DecisionTreeRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.DecisionTreeRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.DecisionTreeRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.DecisionTreeRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.DecisionTreeRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.DecisionTreeRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.DecisionTreeRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -186,7 +383,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -196,10 +393,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/ElasticNetRegressor.md b/docs/api/safeds/ml/classical/regression/ElasticNetRegressor.md index 72843bec7..83b9c30f9 100644 --- a/docs/api/safeds/ml/classical/regression/ElasticNetRegressor.md +++ b/docs/api/safeds/ml/classical/regression/ElasticNetRegressor.md @@ -53,7 +53,7 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: ElasticNetRegressor } ``` @@ -66,7 +66,7 @@ Get the regularization of the model. ## `#!sds attr` isFitted {#safeds.ml.classical.regression.ElasticNetRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -76,6 +76,47 @@ Get the ratio between Lasso and Ridge regularization. **Type:** [`Float`][safeds.lang.Float] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.ElasticNetRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.ElasticNetRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -86,7 +127,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -99,84 +140,240 @@ This regressor is not modified. ```sds linenums="48" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: ElasticNetRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.ElasticNetRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.ElasticNetRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.ElasticNetRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.ElasticNetRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.ElasticNetRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.ElasticNetRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.ElasticNetRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.ElasticNetRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.ElasticNetRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) of the regressor on the given data. -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.ElasticNetRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -188,7 +385,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -198,10 +395,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/GradientBoostingRegressor.md b/docs/api/safeds/ml/classical/regression/GradientBoostingRegressor.md index 647e4964c..23e56ddb0 100644 --- a/docs/api/safeds/ml/classical/regression/GradientBoostingRegressor.md +++ b/docs/api/safeds/ml/classical/regression/GradientBoostingRegressor.md @@ -8,7 +8,7 @@ Gradient boosting regression. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfTrees` | [`Int`][safeds.lang.Int] | The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large number usually results in better performance. | `#!sds 100` | +| `treeCount` | [`Int`][safeds.lang.Int] | The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large number usually results in better performance. | `#!sds 100` | | `learningRate` | [`Float`][safeds.lang.Float] | The larger the value, the more the model is influenced by each additional tree. If the learning rate is too low, the model might underfit. If the learning rate is too high, the model might overfit. | `#!sds 0.1` | **Examples:** @@ -17,7 +17,7 @@ Gradient boosting regression. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = GradientBoostingRegressor(numberOfTrees = 50).fit(training); + val regressor = GradientBoostingRegressor(treeCount = 50).fit(training); val meanSquaredError = regressor.meanSquaredError(test); } ``` @@ -26,16 +26,16 @@ pipeline example { ```sds linenums="23" class GradientBoostingRegressor( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, + @PythonName("number_of_trees") const treeCount: Int = 100, @PythonName("learning_rate") const learningRate: Float = 0.1 ) sub Regressor where { - numberOfTrees >= 1, + treeCount >= 1, learningRate > 0.0 } { /** * Get the number of trees (estimators) in the ensemble. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * Get the learning rate. */ @@ -52,14 +52,14 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: GradientBoostingRegressor } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.GradientBoostingRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] @@ -69,12 +69,53 @@ Get the learning rate. **Type:** [`Float`][safeds.lang.Float] -## `#!sds attr` numberOfTrees {#safeds.ml.classical.regression.GradientBoostingRegressor.numberOfTrees data-toc-label='numberOfTrees'} +## `#!sds attr` treeCount {#safeds.ml.classical.regression.GradientBoostingRegressor.treeCount data-toc-label='treeCount'} Get the number of trees (estimators) in the ensemble. **Type:** [`Int`][safeds.lang.Int] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.GradientBoostingRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.GradientBoostingRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -85,7 +126,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -98,84 +139,240 @@ This regressor is not modified. ```sds linenums="48" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: GradientBoostingRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.GradientBoostingRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.GradientBoostingRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.GradientBoostingRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.GradientBoostingRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.GradientBoostingRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.GradientBoostingRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.GradientBoostingRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.GradientBoostingRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.GradientBoostingRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) of the regressor on the given data. -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.GradientBoostingRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -187,7 +384,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -197,10 +394,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/KNearestNeighborsRegressor.md b/docs/api/safeds/ml/classical/regression/KNearestNeighborsRegressor.md index c8b1c668b..e57b34f76 100644 --- a/docs/api/safeds/ml/classical/regression/KNearestNeighborsRegressor.md +++ b/docs/api/safeds/ml/classical/regression/KNearestNeighborsRegressor.md @@ -8,7 +8,7 @@ K-nearest-neighbors regression. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfNeighbors` | [`Int`][safeds.lang.Int] | The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and less than or equal to the sample size (validated when calling `fit`). | - | +| `neighborCount` | [`Int`][safeds.lang.Int] | The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and less than or equal to the sample size (validated when calling `fit`). | - | **Examples:** @@ -16,7 +16,7 @@ K-nearest-neighbors regression. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = KNearestNeighborsRegressor(numberOfNeighbors = 5).fit(training); + val regressor = KNearestNeighborsRegressor(neighborCount = 5).fit(training); val meanSquaredError = regressor.meanSquaredError(test); } ``` @@ -25,14 +25,14 @@ pipeline example { ```sds linenums="21" class KNearestNeighborsRegressor( - @PythonName("number_of_neighbors") const numberOfNeighbors: Int + @PythonName("number_of_neighbors") const neighborCount: Int ) sub Regressor where { - numberOfNeighbors >= 1 + neighborCount >= 1 } { /** * Get the number of neighbors used for interpolation. */ - @PythonName("number_of_neighbors") attr numberOfNeighbors: Int + @PythonName("number_of_neighbors") attr neighborCount: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -45,23 +45,64 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: KNearestNeighborsRegressor } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.KNearestNeighborsRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` numberOfNeighbors {#safeds.ml.classical.regression.KNearestNeighborsRegressor.numberOfNeighbors data-toc-label='numberOfNeighbors'} +## `#!sds attr` neighborCount {#safeds.ml.classical.regression.KNearestNeighborsRegressor.neighborCount data-toc-label='neighborCount'} Get the number of neighbors used for interpolation. **Type:** [`Int`][safeds.lang.Int] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.KNearestNeighborsRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.KNearestNeighborsRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -72,7 +113,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -85,84 +126,240 @@ This regressor is not modified. ```sds linenums="40" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: KNearestNeighborsRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.KNearestNeighborsRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.KNearestNeighborsRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.KNearestNeighborsRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.KNearestNeighborsRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.KNearestNeighborsRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.KNearestNeighborsRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.KNearestNeighborsRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.KNearestNeighborsRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.KNearestNeighborsRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) of the regressor on the given data. -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.KNearestNeighborsRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -174,7 +371,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -184,10 +381,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/LassoRegressor.md b/docs/api/safeds/ml/classical/regression/LassoRegressor.md index 87f53b864..6c2ffccb3 100644 --- a/docs/api/safeds/ml/classical/regression/LassoRegressor.md +++ b/docs/api/safeds/ml/classical/regression/LassoRegressor.md @@ -45,7 +45,7 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: LassoRegressor } ``` @@ -58,10 +58,51 @@ Get the regularization of the model. ## `#!sds attr` isFitted {#safeds.ml.classical.regression.LassoRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.LassoRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.LassoRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -72,7 +113,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -85,84 +126,240 @@ This regressor is not modified. ```sds linenums="39" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: LassoRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.LassoRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.LassoRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.LassoRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.LassoRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.LassoRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.LassoRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.LassoRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.LassoRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.LassoRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.LassoRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -174,7 +371,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -184,10 +381,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/LinearRegressionRegressor.md b/docs/api/safeds/ml/classical/regression/LinearRegressionRegressor.md deleted file mode 100644 index cf1ff3d5b..000000000 --- a/docs/api/safeds/ml/classical/regression/LinearRegressionRegressor.md +++ /dev/null @@ -1,172 +0,0 @@ -# `#!sds class` LinearRegressionRegressor {#safeds.ml.classical.regression.LinearRegressionRegressor data-toc-label='LinearRegressionRegressor'} - -Linear regression. - -**Parent type:** [`Regressor`][safeds.ml.classical.regression.Regressor] - -**Examples:** - -```sds hl_lines="4" -pipeline example { - val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); - val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = LinearRegressionRegressor().fit(training); - val meanSquaredError = regressor.meanSquaredError(test); -} -``` - -??? quote "Stub code in `LinearRegressionRegressor.sdsstub`" - - ```sds linenums="18" - class LinearRegressionRegressor() sub Regressor { - /** - * Create a copy of this regressor and fit it with the given training data. - * - * This regressor is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedRegressor The fitted regressor. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: LinearRegressionRegressor - } - ``` - -## `#!sds attr` isFitted {#safeds.ml.classical.regression.LinearRegressionRegressor.isFitted data-toc-label='isFitted'} - -Whether the regressor is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds fun` fit {#safeds.ml.classical.regression.LinearRegressionRegressor.fit data-toc-label='fit'} - -Create a copy of this regressor and fit it with the given training data. - -This regressor is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedRegressor` | [`LinearRegressionRegressor`][safeds.ml.classical.regression.LinearRegressionRegressor] | The fitted regressor. | - -??? quote "Stub code in `LinearRegressionRegressor.sdsstub`" - - ```sds linenums="28" - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: LinearRegressionRegressor - ``` - -## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.LinearRegressionRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} - -Compute the mean absolute error (MAE) of the regressor on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="61" - @Pure - @PythonName("mean_absolute_error") - fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanAbsoluteError: Float - ``` - -## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.LinearRegressionRegressor.meanSquaredError data-toc-label='meanSquaredError'} - -Compute the mean squared error (MSE) on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="74" - @Pure - @PythonName("mean_squared_error") - fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanSquaredError: Float - ``` - -## `#!sds fun` predict {#safeds.ml.classical.regression.LinearRegressionRegressor.predict data-toc-label='predict'} - -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="36" - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - ``` - -## `#!sds fun` summarizeMetrics {#safeds.ml.classical.regression.LinearRegressionRegressor.summarizeMetrics data-toc-label='summarizeMetrics'} - -Summarize the regressor's metrics on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the regressor's metrics. | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="48" - @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> metrics: Table - ``` diff --git a/docs/api/safeds/ml/classical/regression/LinearRegressor.md b/docs/api/safeds/ml/classical/regression/LinearRegressor.md new file mode 100644 index 000000000..465b1ea60 --- /dev/null +++ b/docs/api/safeds/ml/classical/regression/LinearRegressor.md @@ -0,0 +1,369 @@ +# `#!sds class` LinearRegressor {#safeds.ml.classical.regression.LinearRegressor data-toc-label='LinearRegressor'} + +Linear regression. + +**Parent type:** [`Regressor`][safeds.ml.classical.regression.Regressor] + +**Examples:** + +```sds hl_lines="4" +pipeline example { + val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); + val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); + val regressor = LinearRegressor().fit(training); + val meanSquaredError = regressor.meanSquaredError(test); +} +``` + +??? quote "Stub code in `LinearRegressor.sdsstub`" + + ```sds linenums="18" + class LinearRegressor() sub Regressor { + /** + * Create a copy of this regressor and fit it with the given training data. + * + * This regressor is not modified. + * + * @param trainingSet The training data containing the feature and target vectors. + * + * @result fittedRegressor The fitted regressor. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: LinearRegressor + } + ``` + +## `#!sds attr` isFitted {#safeds.ml.classical.regression.LinearRegressor.isFitted data-toc-label='isFitted'} + +Whether the model is fitted. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.LinearRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + +## `#!sds fun` fit {#safeds.ml.classical.regression.LinearRegressor.fit data-toc-label='fit'} + +Create a copy of this regressor and fit it with the given training data. + +This regressor is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedRegressor` | [`LinearRegressor`][safeds.ml.classical.regression.LinearRegressor] | The fitted regressor. | + +??? quote "Stub code in `LinearRegressor.sdsstub`" + + ```sds linenums="28" + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: LinearRegressor + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.LinearRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.LinearRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.LinearRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.LinearRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + +## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.LinearRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} + +Compute the mean absolute error (MAE) of the regressor on the given data. + +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("mean_absolute_error") + fun meanAbsoluteError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanAbsoluteError: Float + ``` + +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.LinearRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + +## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.LinearRegressor.meanSquaredError data-toc-label='meanSquaredError'} + +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="103" + @Pure + @PythonName("mean_squared_error") + fun meanSquaredError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanSquaredError: Float + ``` + +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.LinearRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.LinearRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + ``` + +## `#!sds fun` summarizeMetrics {#safeds.ml.classical.regression.LinearRegressor.summarizeMetrics data-toc-label='summarizeMetrics'} + +Summarize the regressor's metrics on the given data. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the regressor's metrics. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="18" + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> metrics: Table + ``` diff --git a/docs/api/safeds/ml/classical/regression/RandomForestRegressor.md b/docs/api/safeds/ml/classical/regression/RandomForestRegressor.md index b877160e7..a07d5e977 100644 --- a/docs/api/safeds/ml/classical/regression/RandomForestRegressor.md +++ b/docs/api/safeds/ml/classical/regression/RandomForestRegressor.md @@ -8,9 +8,9 @@ Random forest regression. | Name | Type | Description | Default | |------|------|-------------|---------| -| `numberOfTrees` | [`Int`][safeds.lang.Int] | The number of trees to be used in the random forest. Has to be greater than 0. | `#!sds 100` | -| `maximumDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If None, the depth is not limited. Has to be greater than 0. | `#!sds null` | -| `minimumNumberOfSamplesInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | +| `treeCount` | [`Int`][safeds.lang.Int] | The number of trees to be used in the random forest. Has to be greater than 0. | `#!sds 100` | +| `maxDepth` | [`Int?`][safeds.lang.Int] | The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. | `#!sds null` | +| `minSampleCountInLeaves` | [`Int`][safeds.lang.Int] | The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. | `#!sds 1` | **Examples:** @@ -18,7 +18,7 @@ Random forest regression. pipeline example { val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = RandomForestRegressor(numberOfTrees = 10).fit(training); + val regressor = RandomForestRegressor(treeCount = 10).fit(training); val meanSquaredError = regressor.meanSquaredError(test); } ``` @@ -27,25 +27,25 @@ pipeline example { ```sds linenums="22" class RandomForestRegressor( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1, + @PythonName("number_of_trees") const treeCount: Int = 100, + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1, ) sub Regressor where { - numberOfTrees > 0, - minimumNumberOfSamplesInLeaves > 0, + treeCount > 0, + minSampleCountInLeaves > 0, } { /** * Get the number of trees used in the random forest. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * The maximum depth of each tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of each tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -58,35 +58,76 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RandomForestRegressor } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.RandomForestRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds attr` maximumDepth {#safeds.ml.classical.regression.RandomForestRegressor.maximumDepth data-toc-label='maximumDepth'} +## `#!sds attr` maxDepth {#safeds.ml.classical.regression.RandomForestRegressor.maxDepth data-toc-label='maxDepth'} The maximum depth of each tree. **Type:** [`Int?`][safeds.lang.Int] -## `#!sds attr` minimumNumberOfSamplesInLeaves {#safeds.ml.classical.regression.RandomForestRegressor.minimumNumberOfSamplesInLeaves data-toc-label='minimumNumberOfSamplesInLeaves'} +## `#!sds attr` minSampleCountInLeaves {#safeds.ml.classical.regression.RandomForestRegressor.minSampleCountInLeaves data-toc-label='minSampleCountInLeaves'} The minimum number of samples that must remain in the leaves of each tree. **Type:** [`Int`][safeds.lang.Int] -## `#!sds attr` numberOfTrees {#safeds.ml.classical.regression.RandomForestRegressor.numberOfTrees data-toc-label='numberOfTrees'} +## `#!sds attr` treeCount {#safeds.ml.classical.regression.RandomForestRegressor.treeCount data-toc-label='treeCount'} Get the number of trees used in the random forest. **Type:** [`Int`][safeds.lang.Int] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.RandomForestRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.RandomForestRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -97,7 +138,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -110,84 +151,240 @@ This regressor is not modified. ```sds linenums="52" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RandomForestRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.RandomForestRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.RandomForestRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.RandomForestRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.RandomForestRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.RandomForestRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.RandomForestRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.RandomForestRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.RandomForestRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.RandomForestRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.RandomForestRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -199,7 +396,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -209,10 +406,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/Regressor.md b/docs/api/safeds/ml/classical/regression/Regressor.md index db20aca28..b265ff0e0 100644 --- a/docs/api/safeds/ml/classical/regression/Regressor.md +++ b/docs/api/safeds/ml/classical/regression/Regressor.md @@ -5,7 +5,9 @@ search: # `#!sds abstract class` Regressor {#safeds.ml.classical.regression.Regressor data-toc-label='Regressor'} -Abstract base class for all regressors. +A model for regression tasks. + +**Parent type:** [`SupervisedModel`][safeds.ml.classical.SupervisedModel] **Inheritors:** @@ -15,194 +17,438 @@ Abstract base class for all regressors. - [`GradientBoostingRegressor`][safeds.ml.classical.regression.GradientBoostingRegressor] - [`KNearestNeighborsRegressor`][safeds.ml.classical.regression.KNearestNeighborsRegressor] - [`LassoRegressor`][safeds.ml.classical.regression.LassoRegressor] -- [`LinearRegressionRegressor`][safeds.ml.classical.regression.LinearRegressionRegressor] +- `#!sds LinearRegressionRegressor` +- [`LinearRegressor`][safeds.ml.classical.regression.LinearRegressor] - [`RandomForestRegressor`][safeds.ml.classical.regression.RandomForestRegressor] - [`RidgeRegressor`][safeds.ml.classical.regression.RidgeRegressor] -- [`SupportVectorMachineRegressor`][safeds.ml.classical.regression.SupportVectorMachineRegressor] +- `#!sds SupportVectorMachineRegressor` +- [`SupportVectorRegressor`][safeds.ml.classical.regression.SupportVectorRegressor] ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="9" - class Regressor { + ```sds linenums="10" + class Regressor sub SupervisedModel { /** - * Whether the regressor is fitted. + * Summarize the regressor's metrics on the given data. + * + * @param validationOrTestSet The validation or test set. + * + * @result metrics A table containing the regressor's metrics. */ - @PythonName("is_fitted") attr isFitted: Boolean + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> metrics: Table /** - * Create a copy of this regressor and fit it with the given training data. + * Compute the coefficient of determination (R²) of the regressor on the given data. * - * This regressor is not modified. + * The coefficient of determination compares the regressor's predictions to another model that always predicts the + * mean of the target values. It is a measure of how well the regressor explains the variance in the target values. * - * @param trainingSet The training data containing the feature and target vectors. + * The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity + * to 1.0. You can interpret the coefficient of determination as follows: * - * @result fittedRegressor The fitted regressor. + * | R² | Interpretation | + * | ---------- | ------------------------------------------------------------------------------------------ | + * | 1.0 | The model perfectly predicts the target values. Did you overfit? | + * | (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | + * | 0.0 | The model is as good as predicting the mean of the target values. Try something else. | + * | (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + * + * **Note:** Some other libraries call this metric `r2_score`. + * + * @param validationOrTestSet The validation or test set. + * + * @result coefficientOfDetermination The coefficient of determination of the regressor. */ @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: Regressor + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float /** - * Predict a target vector using a dataset containing feature vectors. The model has to be trained first. + * Compute the mean absolute error (MAE) of the regressor on the given data. * - * @param dataset The dataset containing the feature vectors. + * The mean absolute error is the average of the absolute differences between the predicted and expected target + * values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive + * infinity. * - * @result prediction A dataset containing the given feature vectors and the predicted target vector. + * @param validationOrTestSet The validation or test set. + * + * @result meanAbsoluteError The mean absolute error of the regressor. */ @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset + @PythonName("mean_absolute_error") + fun meanAbsoluteError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanAbsoluteError: Float /** - * Summarize the regressor's metrics on the given data. + * Compute the mean directional accuracy (MDA) of the regressor on the given data. + * + * This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) + * matches the expected direction. The mean directional accuracy is the proportion of correctly predicted + * directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to + * 1.0. + * + * This metric is useful for time series data, where the order of the target values has a meaning. It is not useful + * for other types of data. Because of this, it is not included in the `summarize_metrics` method. * * @param validationOrTestSet The validation or test set. * - * @result metrics A table containing the regressor's metrics. + * @result meanDirectionalAccuracy The mean directional accuracy of the regressor. */ @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> metrics: Table + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float /** - * Compute the mean absolute error (MAE) of the regressor on the given data. + * Compute the mean squared error (MSE) of the regressor on the given data. + * + * The mean squared error is the average of the squared differences between the predicted and expected target + * values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * **Note:** To get the root mean squared error (RMSE), take the square root of the result. * * @param validationOrTestSet The validation or test set. * - * @result meanAbsoluteError The calculated mean absolute error (the average of the distance of each individual row). + * @result meanSquaredError The mean squared error of the regressor. */ @Pure - @PythonName("mean_absolute_error") - fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanAbsoluteError: Float + @PythonName("mean_squared_error") + fun meanSquaredError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanSquaredError: Float /** - * Compute the mean squared error (MSE) on the given data. + * Compute the median absolute deviation (MAD) of the regressor on the given data. + * + * The median absolute deviation is the median of the absolute differences between the predicted and expected + * target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to + * positive infinity. * * @param validationOrTestSet The validation or test set. * - * @result meanSquaredError The calculated mean squared error (the average of the distance of each individual row squared). + * @result medianAbsoluteDeviation The median absolute deviation of the regressor. */ @Pure - @PythonName("mean_squared_error") - fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanSquaredError: Float + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float } ``` ## `#!sds attr` isFitted {#safeds.ml.classical.regression.Regressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] -## `#!sds fun` fit {#safeds.ml.classical.regression.Regressor.fit data-toc-label='fit'} +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.Regressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: -Create a copy of this regressor and fit it with the given training data. +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | -This regressor is not modified. +**Note:** Some other libraries call this metric `r2_score`. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `fittedRegressor` | [`Regressor`][safeds.ml.classical.regression.Regressor] | The fitted regressor. | +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="24" + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + +## `#!sds fun` fit {#safeds.ml.classical.regression.Regressor.fit data-toc-label='fit'} + +Create a copy of this model and fit it with the given training data. + +**Note:** This model is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the features and target. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedModel` | [`SupervisedModel`][safeds.ml.classical.SupervisedModel] | The fitted model. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="26" @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: Regressor + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedModel: SupervisedModel + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.Regressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.Regressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.Regressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.Regressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType ``` ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.Regressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.Regressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.Regressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.Regressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.Regressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.Regressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -214,7 +460,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -224,10 +470,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/RidgeRegressor.md b/docs/api/safeds/ml/classical/regression/RidgeRegressor.md index 54419e9ee..2b9979384 100644 --- a/docs/api/safeds/ml/classical/regression/RidgeRegressor.md +++ b/docs/api/safeds/ml/classical/regression/RidgeRegressor.md @@ -45,7 +45,7 @@ pipeline example { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RidgeRegressor } ``` @@ -58,10 +58,51 @@ Get the regularization of the model. ## `#!sds attr` isFitted {#safeds.ml.classical.regression.RidgeRegressor.isFitted data-toc-label='isFitted'} -Whether the regressor is fitted. +Whether the model is fitted. **Type:** [`Boolean`][safeds.lang.Boolean] +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.RidgeRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + ## `#!sds fun` fit {#safeds.ml.classical.regression.RidgeRegressor.fit data-toc-label='fit'} Create a copy of this regressor and fit it with the given training data. @@ -72,7 +113,7 @@ This regressor is not modified. | Name | Type | Description | Default | |------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | **Results:** @@ -85,84 +126,240 @@ This regressor is not modified. ```sds linenums="39" @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RidgeRegressor ``` +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.RidgeRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.RidgeRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.RidgeRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.RidgeRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + ## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.RidgeRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} Compute the mean absolute error (MAE) of the regressor on the given data. +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="61" + ```sds linenums="63" @Pure @PythonName("mean_absolute_error") fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanAbsoluteError: Float ``` +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.RidgeRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + ## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.RidgeRegressor.meanSquaredError data-toc-label='meanSquaredError'} -Compute the mean squared error (MSE) on the given data. +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="74" + ```sds linenums="103" @Pure @PythonName("mean_squared_error") fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> meanSquaredError: Float ``` -## `#!sds fun` predict {#safeds.ml.classical.regression.RidgeRegressor.predict data-toc-label='predict'} +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.RidgeRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. **Parameters:** | Name | Type | Description | Default | |------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** | Name | Type | Description | |------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="36" + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.RidgeRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" @Pure fun predict( - dataset: union + dataset: union ) -> prediction: TabularDataset ``` @@ -174,7 +371,7 @@ Summarize the regressor's metrics on the given data. | Name | Type | Description | Default | |------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | **Results:** @@ -184,10 +381,10 @@ Summarize the regressor's metrics on the given data. ??? quote "Stub code in `Regressor.sdsstub`" - ```sds linenums="48" + ```sds linenums="18" @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> metrics: Table ``` diff --git a/docs/api/safeds/ml/classical/regression/SupportVectorMachineRegressor.md b/docs/api/safeds/ml/classical/regression/SupportVectorMachineRegressor.md deleted file mode 100644 index ad32fc469..000000000 --- a/docs/api/safeds/ml/classical/regression/SupportVectorMachineRegressor.md +++ /dev/null @@ -1,288 +0,0 @@ -# `#!sds class` SupportVectorMachineRegressor {#safeds.ml.classical.regression.SupportVectorMachineRegressor data-toc-label='SupportVectorMachineRegressor'} - -Support vector machine. - -**Parent type:** [`Regressor`][safeds.ml.classical.regression.Regressor] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `c` | [`Float`][safeds.lang.Float] | The strength of regularization. Must be strictly positive. | `#!sds 1.0` | -| `kernel` | [`Kernel`][safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel] | The type of kernel to be used. Defaults to None. | `#!sds SupportVectorMachineRegressor.Kernel.RadialBasisFunction` | - -**Examples:** - -```sds hl_lines="4 5" -pipeline example { - val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); - val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - val regressor = SupportVectorMachineRegressor( - kernel = SupportVectorMachineRegressor.Kernel.Linear - ).fit(training); - val meanSquaredError = regressor.meanSquaredError(test); -} -``` - -??? quote "Stub code in `SupportVectorMachineRegressor.sdsstub`" - - ```sds linenums="23" - class SupportVectorMachineRegressor( - const c: Float = 1.0, - kernel: SupportVectorMachineRegressor.Kernel = SupportVectorMachineRegressor.Kernel.RadialBasisFunction - ) sub Regressor where { - c > 0.0 - } { - /** - * The kernel functions that can be used in the support vector machine. - */ - enum Kernel { - /** - * A linear kernel. - */ - Linear - - /** - * A polynomial kernel. - * - * @param degree The degree of the polynomial. - */ - Polynomial(degree: Int) - - /** - * A sigmoid kernel. - */ - Sigmoid - - /** - * A radial basis function kernel. - */ - RadialBasisFunction - } - - /** - * Get the regularization strength. - */ - attr c: Float - /** - * Get the type of kernel used. - */ - attr kernel: SupportVectorMachineRegressor.Kernel - - /** - * Create a copy of this regressor and fit it with the given training data. - * - * This regressor is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedRegressor The fitted regressor. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: SupportVectorMachineRegressor - } - ``` - -## `#!sds attr` c {#safeds.ml.classical.regression.SupportVectorMachineRegressor.c data-toc-label='c'} - -Get the regularization strength. - -**Type:** [`Float`][safeds.lang.Float] - -## `#!sds attr` isFitted {#safeds.ml.classical.regression.SupportVectorMachineRegressor.isFitted data-toc-label='isFitted'} - -Whether the regressor is fitted. - -**Type:** [`Boolean`][safeds.lang.Boolean] - -## `#!sds attr` kernel {#safeds.ml.classical.regression.SupportVectorMachineRegressor.kernel data-toc-label='kernel'} - -Get the type of kernel used. - -**Type:** [`Kernel`][safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel] - -## `#!sds fun` fit {#safeds.ml.classical.regression.SupportVectorMachineRegressor.fit data-toc-label='fit'} - -Create a copy of this regressor and fit it with the given training data. - -This regressor is not modified. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `trainingSet` | `#!sds union` | The training data containing the feature and target vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `fittedRegressor` | [`SupportVectorMachineRegressor`][safeds.ml.classical.regression.SupportVectorMachineRegressor] | The fitted regressor. | - -??? quote "Stub code in `SupportVectorMachineRegressor.sdsstub`" - - ```sds linenums="74" - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: SupportVectorMachineRegressor - ``` - -## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.SupportVectorMachineRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} - -Compute the mean absolute error (MAE) of the regressor on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error (the average of the distance of each individual row). | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="61" - @Pure - @PythonName("mean_absolute_error") - fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanAbsoluteError: Float - ``` - -## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.SupportVectorMachineRegressor.meanSquaredError data-toc-label='meanSquaredError'} - -Compute the mean squared error (MSE) on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error (the average of the distance of each individual row squared). | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="74" - @Pure - @PythonName("mean_squared_error") - fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanSquaredError: Float - ``` - -## `#!sds fun` predict {#safeds.ml.classical.regression.SupportVectorMachineRegressor.predict data-toc-label='predict'} - -Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `dataset` | `#!sds union` | The dataset containing the feature vectors. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | A dataset containing the given feature vectors and the predicted target vector. | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="36" - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - ``` - -## `#!sds fun` summarizeMetrics {#safeds.ml.classical.regression.SupportVectorMachineRegressor.summarizeMetrics data-toc-label='summarizeMetrics'} - -Summarize the regressor's metrics on the given data. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | - -**Results:** - -| Name | Type | Description | -|------|------|-------------| -| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the regressor's metrics. | - -??? quote "Stub code in `Regressor.sdsstub`" - - ```sds linenums="48" - @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> metrics: Table - ``` - -## `#!sds enum` Kernel {#safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel data-toc-label='Kernel'} - -The kernel functions that can be used in the support vector machine. - -??? quote "Stub code in `SupportVectorMachineRegressor.sdsstub`" - - ```sds linenums="32" - enum Kernel { - /** - * A linear kernel. - */ - Linear - - /** - * A polynomial kernel. - * - * @param degree The degree of the polynomial. - */ - Polynomial(degree: Int) - - /** - * A sigmoid kernel. - */ - Sigmoid - - /** - * A radial basis function kernel. - */ - RadialBasisFunction - } - ``` - -### Linear {#safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel.Linear data-toc-label='Linear'} - -A linear kernel. - -### Polynomial {#safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel.Polynomial data-toc-label='Polynomial'} - -A polynomial kernel. - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `degree` | [`Int`][safeds.lang.Int] | The degree of the polynomial. | - | - -### RadialBasisFunction {#safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel.RadialBasisFunction data-toc-label='RadialBasisFunction'} - -A radial basis function kernel. - -### Sigmoid {#safeds.ml.classical.regression.SupportVectorMachineRegressor.Kernel.Sigmoid data-toc-label='Sigmoid'} - -A sigmoid kernel. diff --git a/docs/api/safeds/ml/classical/regression/SupportVectorRegressor.md b/docs/api/safeds/ml/classical/regression/SupportVectorRegressor.md new file mode 100644 index 000000000..3677ce7ea --- /dev/null +++ b/docs/api/safeds/ml/classical/regression/SupportVectorRegressor.md @@ -0,0 +1,497 @@ +# `#!sds class` SupportVectorRegressor {#safeds.ml.classical.regression.SupportVectorRegressor data-toc-label='SupportVectorRegressor'} + +Support vector machine for regression. + +**Parent type:** [`Regressor`][safeds.ml.classical.regression.Regressor] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `c` | [`Float`][safeds.lang.Float] | The strength of regularization. Must be greater than 0. | `#!sds 1.0` | +| `kernel` | [`Kernel`][safeds.ml.classical.regression.SupportVectorRegressor.Kernel] | The type of kernel to be used. Defaults to a radial basis function kernel. | `#!sds SupportVectorRegressor.Kernel.RadialBasisFunction` | + +**Examples:** + +```sds hl_lines="4 5" +pipeline example { + val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); + val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); + val regressor = SupportVectorRegressor( + kernel = SupportVectorRegressor.Kernel.Linear + ).fit(training); + val meanSquaredError = regressor.meanSquaredError(test); +} +``` + +??? quote "Stub code in `SupportVectorRegressor.sdsstub`" + + ```sds linenums="23" + class SupportVectorRegressor( + const c: Float = 1.0, + kernel: SupportVectorRegressor.Kernel = SupportVectorRegressor.Kernel.RadialBasisFunction + ) sub Regressor where { + c > 0.0 + } { + /** + * The kernel functions that can be used in the support vector machine. + */ + enum Kernel { + /** + * A linear kernel. + */ + @PythonName("linear") + Linear + + /** + * A polynomial kernel. + * + * @param degree The degree of the polynomial. + */ + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } + + /** + * A sigmoid kernel. + */ + @PythonName("sigmoid") + Sigmoid + + /** + * A radial basis function kernel. + */ + @PythonName("radial_basis_function") + RadialBasisFunction + } + + /** + * Get the regularization strength. + */ + attr c: Float + /** + * Get the type of kernel used. + */ + attr kernel: SupportVectorRegressor.Kernel + + /** + * Create a copy of this regressor and fit it with the given training data. + * + * This regressor is not modified. + * + * @param trainingSet The training data containing the feature and target vectors. + * + * @result fittedRegressor The fitted regressor. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: SupportVectorRegressor + } + ``` + +## `#!sds attr` c {#safeds.ml.classical.regression.SupportVectorRegressor.c data-toc-label='c'} + +Get the regularization strength. + +**Type:** [`Float`][safeds.lang.Float] + +## `#!sds attr` isFitted {#safeds.ml.classical.regression.SupportVectorRegressor.isFitted data-toc-label='isFitted'} + +Whether the model is fitted. + +**Type:** [`Boolean`][safeds.lang.Boolean] + +## `#!sds attr` kernel {#safeds.ml.classical.regression.SupportVectorRegressor.kernel data-toc-label='kernel'} + +Get the type of kernel used. + +**Type:** [`Kernel`][safeds.ml.classical.regression.SupportVectorRegressor.Kernel] + +## `#!sds fun` coefficientOfDetermination {#safeds.ml.classical.regression.SupportVectorRegressor.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) of the regressor on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The coefficient of determination of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="46" + @Pure + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float + ``` + +## `#!sds fun` fit {#safeds.ml.classical.regression.SupportVectorRegressor.fit data-toc-label='fit'} + +Create a copy of this regressor and fit it with the given training data. + +This regressor is not modified. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `trainingSet` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The training data containing the feature and target vectors. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `fittedRegressor` | [`SupportVectorRegressor`][safeds.ml.classical.regression.SupportVectorRegressor] | The fitted regressor. | + +??? quote "Stub code in `SupportVectorRegressor.sdsstub`" + + ```sds linenums="80" + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: SupportVectorRegressor + ``` + +## `#!sds fun` getFeatureNames {#safeds.ml.classical.regression.SupportVectorRegressor.getFeatureNames data-toc-label='getFeatureNames'} + +Return the names of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureNames` | [`List`][safeds.lang.List] | The names of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="52" + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + ``` + +## `#!sds fun` getFeaturesSchema {#safeds.ml.classical.regression.SupportVectorRegressor.getFeaturesSchema data-toc-label='getFeaturesSchema'} + +Return the schema of the feature columns. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `featureSchema` | [`Schema`][safeds.data.tabular.typing.Schema] | The schema of the feature columns. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + ``` + +## `#!sds fun` getTargetName {#safeds.ml.classical.regression.SupportVectorRegressor.getTargetName data-toc-label='getTargetName'} + +Return the name of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetName` | [`String`][safeds.lang.String] | The name of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="74" + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + ``` + +## `#!sds fun` getTargetType {#safeds.ml.classical.regression.SupportVectorRegressor.getTargetType data-toc-label='getTargetType'} + +Return the type of the target column. + +**Note:** The model must be fitted. + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `targetType` | [`DataType`][safeds.data.tabular.typing.DataType] | The type of the target column. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="85" + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType + ``` + +## `#!sds fun` meanAbsoluteError {#safeds.ml.classical.regression.SupportVectorRegressor.meanAbsoluteError data-toc-label='meanAbsoluteError'} + +Compute the mean absolute error (MAE) of the regressor on the given data. + +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The mean absolute error of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="63" + @Pure + @PythonName("mean_absolute_error") + fun meanAbsoluteError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanAbsoluteError: Float + ``` + +## `#!sds fun` meanDirectionalAccuracy {#safeds.ml.classical.regression.SupportVectorRegressor.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) of the regressor on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize_metrics` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The mean directional accuracy of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="84" + @Pure + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float + ``` + +## `#!sds fun` meanSquaredError {#safeds.ml.classical.regression.SupportVectorRegressor.meanSquaredError data-toc-label='meanSquaredError'} + +Compute the mean squared error (MSE) of the regressor on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The mean squared error of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="103" + @Pure + @PythonName("mean_squared_error") + fun meanSquaredError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanSquaredError: Float + ``` + +## `#!sds fun` medianAbsoluteDeviation {#safeds.ml.classical.regression.SupportVectorRegressor.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) of the regressor on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The median absolute deviation of the regressor. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="120" + @Pure + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds fun` predict {#safeds.ml.classical.regression.SupportVectorRegressor.predict data-toc-label='predict'} + +Predict the target values on the given dataset. + +**Note:** The model must be fitted. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `dataset` | `#!sds union` | The dataset containing at least the features. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `prediction` | [`TabularDataset`][safeds.data.labeled.containers.TabularDataset] | The given dataset with an additional column for the predicted target values. | + +??? quote "Stub code in `SupervisedModel.sdsstub`" + + ```sds linenums="40" + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + ``` + +## `#!sds fun` summarizeMetrics {#safeds.ml.classical.regression.SupportVectorRegressor.summarizeMetrics data-toc-label='summarizeMetrics'} + +Summarize the regressor's metrics on the given data. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `validationOrTestSet` | `#!sds union` | The validation or test set. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the regressor's metrics. | + +??? quote "Stub code in `Regressor.sdsstub`" + + ```sds linenums="18" + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> metrics: Table + ``` + +## `#!sds enum` Kernel {#safeds.ml.classical.regression.SupportVectorRegressor.Kernel data-toc-label='Kernel'} + +The kernel functions that can be used in the support vector machine. + +??? quote "Stub code in `SupportVectorRegressor.sdsstub`" + + ```sds linenums="32" + enum Kernel { + /** + * A linear kernel. + */ + @PythonName("linear") + Linear + + /** + * A polynomial kernel. + * + * @param degree The degree of the polynomial. + */ + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } + + /** + * A sigmoid kernel. + */ + @PythonName("sigmoid") + Sigmoid + + /** + * A radial basis function kernel. + */ + @PythonName("radial_basis_function") + RadialBasisFunction + } + ``` + +### Linear {#safeds.ml.classical.regression.SupportVectorRegressor.Kernel.Linear data-toc-label='Linear'} + +A linear kernel. + +### Polynomial {#safeds.ml.classical.regression.SupportVectorRegressor.Kernel.Polynomial data-toc-label='Polynomial'} + +A polynomial kernel. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `degree` | [`Int`][safeds.lang.Int] | The degree of the polynomial. | - | + +### RadialBasisFunction {#safeds.ml.classical.regression.SupportVectorRegressor.Kernel.RadialBasisFunction data-toc-label='RadialBasisFunction'} + +A radial basis function kernel. + +### Sigmoid {#safeds.ml.classical.regression.SupportVectorRegressor.Kernel.Sigmoid data-toc-label='Sigmoid'} + +A sigmoid kernel. diff --git a/docs/api/safeds/ml/metrics/ClassificationMetrics.md b/docs/api/safeds/ml/metrics/ClassificationMetrics.md new file mode 100644 index 000000000..78096d43d --- /dev/null +++ b/docs/api/safeds/ml/metrics/ClassificationMetrics.md @@ -0,0 +1,256 @@ +# `#!sds abstract class` ClassificationMetrics {#safeds.ml.metrics.ClassificationMetrics data-toc-label='ClassificationMetrics'} + +A collection of classification metrics. + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="9" + class ClassificationMetrics { + /** + * Summarize classification metrics on the given data. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result metrics A table containing the classification metrics. + */ + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> metrics: Table + + /** + * Compute the accuracy on the given data. + * + * The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the + * better. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * + * @result accuracy The calculated accuracy. + */ + @Pure + static fun accuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> accuracy: Float + + /** + * Compute the F₁ score on the given data. + * + * The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the + * classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result f1Score The calculated F₁ score. + */ + @Pure + @PythonName("f1_score") + static fun f1Score( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> f1Score: Float + + /** + * Compute the precision on the given data. + * + * The precision is the proportion of positive predictions that were correct. The **higher** the precision, the + * better the classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result precision The calculated precision. + */ + @Pure + static fun precision( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> precision: Float + + /** + * Compute the recall on the given data. + * + * The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the + * better the classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result recall The calculated recall. + */ + @Pure + static fun recall( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> recall: Float + } + ``` + +## `#!sds static fun` accuracy {#safeds.ml.metrics.ClassificationMetrics.accuracy data-toc-label='accuracy'} + +Compute the accuracy on the given data. + +The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the +better. Results range from 0.0 to 1.0. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the classifier. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `accuracy` | [`Float`][safeds.lang.Float] | The calculated accuracy. | + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="37" + @Pure + static fun accuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> accuracy: Float + ``` + +## `#!sds static fun` f1Score {#safeds.ml.metrics.ClassificationMetrics.f1Score data-toc-label='f1Score'} + +Compute the F₁ score on the given data. + +The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the +classifier. Results range from 0.0 to 1.0. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the classifier. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `f1Score` | [`Float`][safeds.lang.Float] | The calculated F₁ score. | + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="55" + @Pure + @PythonName("f1_score") + static fun f1Score( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> f1Score: Float + ``` + +## `#!sds static fun` precision {#safeds.ml.metrics.ClassificationMetrics.precision data-toc-label='precision'} + +Compute the precision on the given data. + +The precision is the proportion of positive predictions that were correct. The **higher** the precision, the +better the classifier. Results range from 0.0 to 1.0. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the classifier. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `precision` | [`Float`][safeds.lang.Float] | The calculated precision. | + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="75" + @Pure + static fun precision( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> precision: Float + ``` + +## `#!sds static fun` recall {#safeds.ml.metrics.ClassificationMetrics.recall data-toc-label='recall'} + +Compute the recall on the given data. + +The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the +better the classifier. Results range from 0.0 to 1.0. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the classifier. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `recall` | [`Float`][safeds.lang.Float] | The calculated recall. | + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="94" + @Pure + static fun recall( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> recall: Float + ``` + +## `#!sds static fun` summarize {#safeds.ml.metrics.ClassificationMetrics.summarize data-toc-label='summarize'} + +Summarize classification metrics on the given data. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the classifier. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | +| `positiveClass` | [`Any`][safeds.lang.Any] | The class to be considered positive. All other classes are considered negative. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the classification metrics. | + +??? quote "Stub code in `ClassificationMetrics.sdsstub`" + + ```sds linenums="19" + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> metrics: Table + ``` diff --git a/docs/api/safeds/ml/metrics/RegressionMetrics.md b/docs/api/safeds/ml/metrics/RegressionMetrics.md new file mode 100644 index 000000000..0aaefd55d --- /dev/null +++ b/docs/api/safeds/ml/metrics/RegressionMetrics.md @@ -0,0 +1,339 @@ +# `#!sds abstract class` RegressionMetrics {#safeds.ml.metrics.RegressionMetrics data-toc-label='RegressionMetrics'} + +A collection of regression metrics. + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="9" + class RegressionMetrics { + /** + * Summarize regression metrics on the given data. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result metrics A table containing the regression metrics. + */ + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> metrics: Table + + /** + * Compute the coefficient of determination (R²) on the given data. + * + * The coefficient of determination compares the regressor's predictions to another model that always predicts the + * mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + * + * The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity + * to 1.0. You can interpret the coefficient of determination as follows: + * + * | R² | Interpretation | + * | ---------- | ------------------------------------------------------------------------------------------ | + * | 1.0 | The model perfectly predicts the target values. Did you overfit? | + * | (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | + * | 0.0 | The model is as good as predicting the mean of the target values. Try something else. | + * | (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + * + * **Note:** Some other libraries call this metric `r2_score`. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result coefficientOfDetermination The calculated coefficient of determination. + */ + @Pure + @PythonName("coefficient_of_determination") + static fun coefficientOfDetermination( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> coefficientOfDetermination: Float + + /** + * Compute the mean absolute error (MAE) on the given data. + * + * The mean absolute error is the average of the absolute differences between the predicted and expected target + * values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanAbsoluteError The calculated mean absolute error. + */ + @Pure + @PythonName("mean_absolute_error") + static fun meanAbsoluteError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanAbsoluteError: Float + + /** + * Compute the mean directional accuracy (MDA) on the given data. + * + * This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) + * matches the expected direction. The mean directional accuracy is the proportion of correctly predicted + * directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to + * 1.0. + * + * This metric is useful for time series data, where the order of the target values has a meaning. It is not useful + * for other types of data. Because of this, it is not included in the `summarize` method. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanDirectionalAccuracy The calculated mean directional accuracy. + */ + @Pure + @PythonName("mean_directional_accuracy") + static fun meanDirectionalAccuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanDirectionalAccuracy: Float + + /** + * Compute the mean squared error (MSE) on the given data. + * + * The mean squared error is the average of the squared differences between the predicted and expected target + * values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * **Note:** To get the root mean squared error (RMSE), take the square root of the result. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanSquaredError The calculated mean squared error. + */ + @Pure + @PythonName("mean_squared_error") + static fun meanSquaredError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanSquaredError: Float + + /** + * Compute the median absolute deviation (MAD) on the given data. + * + * The median absolute deviation is the median of the absolute differences between the predicted and expected + * target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to + * positive infinity. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result medianAbsoluteDeviation The calculated median absolute deviation. + */ + @Pure + @PythonName("median_absolute_deviation") + static fun medianAbsoluteDeviation( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> medianAbsoluteDeviation: Float + } + ``` + +## `#!sds static fun` coefficientOfDetermination {#safeds.ml.metrics.RegressionMetrics.coefficientOfDetermination data-toc-label='coefficientOfDetermination'} + +Compute the coefficient of determination (R²) on the given data. + +The coefficient of determination compares the regressor's predictions to another model that always predicts the +mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + +The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity +to 1.0. You can interpret the coefficient of determination as follows: + +| R² | Interpretation | +| ---------- | ------------------------------------------------------------------------------------------ | +| 1.0 | The model perfectly predicts the target values. Did you overfit? | +| (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | +| 0.0 | The model is as good as predicting the mean of the target values. Try something else. | +| (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + +**Note:** Some other libraries call this metric `r2_score`. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `coefficientOfDetermination` | [`Float`][safeds.lang.Float] | The calculated coefficient of determination. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="47" + @Pure + @PythonName("coefficient_of_determination") + static fun coefficientOfDetermination( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> coefficientOfDetermination: Float + ``` + +## `#!sds static fun` meanAbsoluteError {#safeds.ml.metrics.RegressionMetrics.meanAbsoluteError data-toc-label='meanAbsoluteError'} + +Compute the mean absolute error (MAE) on the given data. + +The mean absolute error is the average of the absolute differences between the predicted and expected target +values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanAbsoluteError` | [`Float`][safeds.lang.Float] | The calculated mean absolute error. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="66" + @Pure + @PythonName("mean_absolute_error") + static fun meanAbsoluteError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanAbsoluteError: Float + ``` + +## `#!sds static fun` meanDirectionalAccuracy {#safeds.ml.metrics.RegressionMetrics.meanDirectionalAccuracy data-toc-label='meanDirectionalAccuracy'} + +Compute the mean directional accuracy (MDA) on the given data. + +This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) +matches the expected direction. The mean directional accuracy is the proportion of correctly predicted +directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to +1.0. + +This metric is useful for time series data, where the order of the target values has a meaning. It is not useful +for other types of data. Because of this, it is not included in the `summarize` method. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanDirectionalAccuracy` | [`Float`][safeds.lang.Float] | The calculated mean directional accuracy. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="89" + @Pure + @PythonName("mean_directional_accuracy") + static fun meanDirectionalAccuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanDirectionalAccuracy: Float + ``` + +## `#!sds static fun` meanSquaredError {#safeds.ml.metrics.RegressionMetrics.meanSquaredError data-toc-label='meanSquaredError'} + +Compute the mean squared error (MSE) on the given data. + +The mean squared error is the average of the squared differences between the predicted and expected target +values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive +infinity. + +**Note:** To get the root mean squared error (RMSE), take the square root of the result. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `meanSquaredError` | [`Float`][safeds.lang.Float] | The calculated mean squared error. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="110" + @Pure + @PythonName("mean_squared_error") + static fun meanSquaredError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanSquaredError: Float + ``` + +## `#!sds static fun` medianAbsoluteDeviation {#safeds.ml.metrics.RegressionMetrics.medianAbsoluteDeviation data-toc-label='medianAbsoluteDeviation'} + +Compute the median absolute deviation (MAD) on the given data. + +The median absolute deviation is the median of the absolute differences between the predicted and expected +target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to +positive infinity. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `medianAbsoluteDeviation` | [`Float`][safeds.lang.Float] | The calculated median absolute deviation. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="129" + @Pure + @PythonName("median_absolute_deviation") + static fun medianAbsoluteDeviation( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> medianAbsoluteDeviation: Float + ``` + +## `#!sds static fun` summarize {#safeds.ml.metrics.RegressionMetrics.summarize data-toc-label='summarize'} + +Summarize regression metrics on the given data. + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `predicted` | `#!sds union, TabularDataset>` | The predicted target values produced by the regressor. | - | +| `expected` | `#!sds union, TabularDataset>` | The expected target values. | - | + +**Results:** + +| Name | Type | Description | +|------|------|-------------| +| `metrics` | [`Table`][safeds.data.tabular.containers.Table] | A table containing the regression metrics. | + +??? quote "Stub code in `RegressionMetrics.sdsstub`" + + ```sds linenums="18" + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> metrics: Table + ``` diff --git a/docs/api/safeds/ml/nn/AvgPooling2DLayer.md b/docs/api/safeds/ml/nn/AvgPooling2DLayer.md deleted file mode 100644 index 7d7b45c82..000000000 --- a/docs/api/safeds/ml/nn/AvgPooling2DLayer.md +++ /dev/null @@ -1,33 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` AvgPooling2DLayer {#safeds.ml.nn.AvgPooling2DLayer data-toc-label='AvgPooling2DLayer'} - -**Parent type:** [`Layer`][safeds.ml.nn.Layer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `kernelSize` | [`Int`][safeds.lang.Int] | - | - | -| `stride` | [`Int`][safeds.lang.Int] | - | - | -| `padding` | [`Int`][safeds.lang.Int] | - | `#!sds 0` | - -??? quote "Stub code in `AvgPooling2DLayer.sdsstub`" - - ```sds linenums="10" - class AvgPooling2DLayer( - @PythonName("kernel_size") kernelSize: Int, - stride: Int, - padding: Int = 0 - ) sub Layer - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.AvgPooling2DLayer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.AvgPooling2DLayer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/Convolutional2DLayer.md b/docs/api/safeds/ml/nn/Convolutional2DLayer.md deleted file mode 100644 index 8b580ae9e..000000000 --- a/docs/api/safeds/ml/nn/Convolutional2DLayer.md +++ /dev/null @@ -1,39 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` Convolutional2DLayer {#safeds.ml.nn.Convolutional2DLayer data-toc-label='Convolutional2DLayer'} - -**Parent type:** [`Layer`][safeds.ml.nn.Layer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `outputChannel` | [`Int`][safeds.lang.Int] | the amount of output channels | - | -| `kernelSize` | [`Int`][safeds.lang.Int] | the size of the kernel | - | -| `stride` | [`Int`][safeds.lang.Int] | the stride of the convolution | `#!sds 1` | -| `padding` | [`Int`][safeds.lang.Int] | the padding of the convolution | `#!sds 0` | - -**Inheritors:** - -- [`ConvolutionalTranspose2DLayer`][safeds.ml.nn.ConvolutionalTranspose2DLayer] - -??? quote "Stub code in `Convolutional2DLayer.sdsstub`" - - ```sds linenums="13" - class Convolutional2DLayer( - @PythonName("output_channel") outputChannel: Int, - @PythonName("kernel_size") kernelSize: Int, - stride: Int = 1, - padding: Int = 0 - ) sub Layer - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.Convolutional2DLayer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.Convolutional2DLayer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/FlattenLayer.md b/docs/api/safeds/ml/nn/FlattenLayer.md deleted file mode 100644 index 5f668837c..000000000 --- a/docs/api/safeds/ml/nn/FlattenLayer.md +++ /dev/null @@ -1,21 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` FlattenLayer {#safeds.ml.nn.FlattenLayer data-toc-label='FlattenLayer'} - -**Parent type:** [`Layer`][safeds.ml.nn.Layer] - -??? quote "Stub code in `FlattenLayer.sdsstub`" - - ```sds linenums="7" - class FlattenLayer() sub Layer - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.FlattenLayer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.FlattenLayer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/ForwardLayer.md b/docs/api/safeds/ml/nn/ForwardLayer.md deleted file mode 100644 index 59cd7ee6e..000000000 --- a/docs/api/safeds/ml/nn/ForwardLayer.md +++ /dev/null @@ -1,39 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ForwardLayer {#safeds.ml.nn.ForwardLayer data-toc-label='ForwardLayer'} - -**Parent type:** [`Layer`][safeds.ml.nn.Layer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `outputSize` | [`Int`][safeds.lang.Int] | The number of neurons in this layer | - | -| `inputSize` | [`Int?`][safeds.lang.Int] | The number of neurons in the previous layer | `#!sds null` | - -**Examples:** - -```sds -pipeline example { - // TODO -} -``` - -??? quote "Stub code in `ForwardLayer.sdsstub`" - - ```sds linenums="13" - class ForwardLayer( - @PythonName("output_size") outputSize: Int, - @PythonName("input_size") inputSize: Int? = null - ) sub Layer - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.ForwardLayer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.ForwardLayer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/Layer.md b/docs/api/safeds/ml/nn/Layer.md deleted file mode 100644 index 68f7e13bb..000000000 --- a/docs/api/safeds/ml/nn/Layer.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -search: - boost: 0.5 ---- - -# :test_tube:{ title="Experimental" } `#!sds abstract class` Layer {#safeds.ml.nn.Layer data-toc-label='Layer'} - -**Inheritors:** - -- [`AvgPooling2DLayer`][safeds.ml.nn.AvgPooling2DLayer] -- [`Convolutional2DLayer`][safeds.ml.nn.Convolutional2DLayer] -- [`FlattenLayer`][safeds.ml.nn.FlattenLayer] -- [`ForwardLayer`][safeds.ml.nn.ForwardLayer] -- [`LSTMLayer`][safeds.ml.nn.LSTMLayer] -- [`MaxPooling2DLayer`][safeds.ml.nn.MaxPooling2DLayer] - -??? quote "Stub code in `Layer.sdsstub`" - - ```sds linenums="4" - class Layer { - /** - * The input_size of this layer. - */ - @PythonName("input_size") attr inputSize: Int - /** - * The output_size of this layer. - */ - @PythonName("output_size") attr outputSize: Int - } - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.Layer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.Layer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/MaxPooling2DLayer.md b/docs/api/safeds/ml/nn/MaxPooling2DLayer.md deleted file mode 100644 index a21bcfb9e..000000000 --- a/docs/api/safeds/ml/nn/MaxPooling2DLayer.md +++ /dev/null @@ -1,33 +0,0 @@ -# :test_tube:{ title="Experimental" } `#!sds class` MaxPooling2DLayer {#safeds.ml.nn.MaxPooling2DLayer data-toc-label='MaxPooling2DLayer'} - -**Parent type:** [`Layer`][safeds.ml.nn.Layer] - -**Parameters:** - -| Name | Type | Description | Default | -|------|------|-------------|---------| -| `kernelSize` | [`Int`][safeds.lang.Int] | - | - | -| `stride` | [`Int`][safeds.lang.Int] | - | - | -| `padding` | [`Int`][safeds.lang.Int] | - | `#!sds 0` | - -??? quote "Stub code in `MaxPooling2DLayer.sdsstub`" - - ```sds linenums="10" - class MaxPooling2DLayer( - @PythonName("kernel_size") kernelSize: Int, - stride: Int, - padding: Int = 0 - ) sub Layer - ``` - -## `#!sds attr` inputSize {#safeds.ml.nn.MaxPooling2DLayer.inputSize data-toc-label='inputSize'} - -The input_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] - -## `#!sds attr` outputSize {#safeds.ml.nn.MaxPooling2DLayer.outputSize data-toc-label='outputSize'} - -The output_size of this layer. - -**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/NeuralNetworkClassifier.md b/docs/api/safeds/ml/nn/NeuralNetworkClassifier.md index 657d2723a..605c127a4 100644 --- a/docs/api/safeds/ml/nn/NeuralNetworkClassifier.md +++ b/docs/api/safeds/ml/nn/NeuralNetworkClassifier.md @@ -6,9 +6,9 @@ A NeuralNetworkClassifier is a neural network that is used for classification ta | Name | Type | Description | Default | |------|------|-------------|---------| -| `inputConversion` | [`InputConversion`][safeds.ml.nn.InputConversion] | to convert the input data for the neural network | - | +| `inputConversion` | `#!sds InputConversion` | to convert the input data for the neural network | - | | `layers` | [`List`][safeds.lang.List] | a list of layers for the neural network to learn | - | -| `outputConversion` | [`OutputConversion`][safeds.ml.nn.OutputConversion] | to convert the output data of the neural network back | - | +| `outputConversion` | `#!sds OutputConversion` | to convert the output data of the neural network back | - | **Type parameters:** diff --git a/docs/api/safeds/ml/nn/NeuralNetworkRegressor.md b/docs/api/safeds/ml/nn/NeuralNetworkRegressor.md index 032496847..60af48ad3 100644 --- a/docs/api/safeds/ml/nn/NeuralNetworkRegressor.md +++ b/docs/api/safeds/ml/nn/NeuralNetworkRegressor.md @@ -6,9 +6,9 @@ A NeuralNetworkRegressor is a neural network that is used for regression tasks. | Name | Type | Description | Default | |------|------|-------------|---------| -| `inputConversion` | [`InputConversion`][safeds.ml.nn.InputConversion] | to convert the input data for the neural network | - | +| `inputConversion` | `#!sds InputConversion` | to convert the input data for the neural network | - | | `layers` | [`List`][safeds.lang.List] | a list of layers for the neural network to learn | - | -| `outputConversion` | [`OutputConversion`][safeds.ml.nn.OutputConversion] | to convert the output data of the neural network back | - | +| `outputConversion` | `#!sds OutputConversion` | to convert the output data of the neural network back | - | **Type parameters:** diff --git a/docs/api/safeds/ml/nn/InputConversion.md b/docs/api/safeds/ml/nn/converters/InputConversion.md similarity index 77% rename from docs/api/safeds/ml/nn/InputConversion.md rename to docs/api/safeds/ml/nn/converters/InputConversion.md index b361b23de..0af33f2b7 100644 --- a/docs/api/safeds/ml/nn/InputConversion.md +++ b/docs/api/safeds/ml/nn/converters/InputConversion.md @@ -3,7 +3,7 @@ search: boost: 0.5 --- -# :test_tube:{ title="Experimental" } `#!sds abstract class` InputConversion {#safeds.ml.nn.InputConversion data-toc-label='InputConversion'} +# :test_tube:{ title="Experimental" } `#!sds abstract class` InputConversion {#safeds.ml.nn.converters.InputConversion data-toc-label='InputConversion'} The input conversion for a neural network, defines the input parameters for the neural network. @@ -16,7 +16,7 @@ The input conversion for a neural network, defines the input parameters for the **Inheritors:** -- [`InputConversionTable`][safeds.ml.nn.InputConversionTable] +- [`InputConversionTable`][safeds.ml.nn.converters.InputConversionTable] ??? quote "Stub code in `InputConversion.sdsstub`" diff --git a/docs/api/safeds/ml/nn/InputConversionImage.md b/docs/api/safeds/ml/nn/converters/InputConversionImage.md similarity index 85% rename from docs/api/safeds/ml/nn/InputConversionImage.md rename to docs/api/safeds/ml/nn/converters/InputConversionImage.md index fbdccff8a..d7a6d09f4 100644 --- a/docs/api/safeds/ml/nn/InputConversionImage.md +++ b/docs/api/safeds/ml/nn/converters/InputConversionImage.md @@ -1,4 +1,4 @@ -# :test_tube:{ title="Experimental" } `#!sds class` InputConversionImage {#safeds.ml.nn.InputConversionImage data-toc-label='InputConversionImage'} +# :test_tube:{ title="Experimental" } `#!sds class` InputConversionImage {#safeds.ml.nn.converters.InputConversionImage data-toc-label='InputConversionImage'} The input conversion for a neural network, defines the input parameters for the neural network. diff --git a/docs/api/safeds/ml/nn/InputConversionTable.md b/docs/api/safeds/ml/nn/converters/InputConversionTable.md similarity index 74% rename from docs/api/safeds/ml/nn/InputConversionTable.md rename to docs/api/safeds/ml/nn/converters/InputConversionTable.md index a36f63b37..cd1984bab 100644 --- a/docs/api/safeds/ml/nn/InputConversionTable.md +++ b/docs/api/safeds/ml/nn/converters/InputConversionTable.md @@ -1,8 +1,8 @@ -# :test_tube:{ title="Experimental" } `#!sds class` InputConversionTable {#safeds.ml.nn.InputConversionTable data-toc-label='InputConversionTable'} +# :test_tube:{ title="Experimental" } `#!sds class` InputConversionTable {#safeds.ml.nn.converters.InputConversionTable data-toc-label='InputConversionTable'} The input conversion for a neural network defines the input parameters for the neural network. -**Parent type:** [`InputConversion`][safeds.ml.nn.InputConversion] +**Parent type:** [`InputConversion`][safeds.ml.nn.converters.InputConversion] ??? quote "Stub code in `InputConversionTable.sdsstub`" diff --git a/docs/api/safeds/ml/nn/InputConversionTimeSeries.md b/docs/api/safeds/ml/nn/converters/InputConversionTimeSeries.md similarity index 86% rename from docs/api/safeds/ml/nn/InputConversionTimeSeries.md rename to docs/api/safeds/ml/nn/converters/InputConversionTimeSeries.md index a74e0103b..32dba7f34 100644 --- a/docs/api/safeds/ml/nn/InputConversionTimeSeries.md +++ b/docs/api/safeds/ml/nn/converters/InputConversionTimeSeries.md @@ -1,4 +1,4 @@ -# :test_tube:{ title="Experimental" } `#!sds class` InputConversionTimeSeries {#safeds.ml.nn.InputConversionTimeSeries data-toc-label='InputConversionTimeSeries'} +# :test_tube:{ title="Experimental" } `#!sds class` InputConversionTimeSeries {#safeds.ml.nn.converters.InputConversionTimeSeries data-toc-label='InputConversionTimeSeries'} The input conversion for a neural network, defines the input parameters for the neural network. diff --git a/docs/api/safeds/ml/nn/OutputConversion.md b/docs/api/safeds/ml/nn/converters/OutputConversion.md similarity index 56% rename from docs/api/safeds/ml/nn/OutputConversion.md rename to docs/api/safeds/ml/nn/converters/OutputConversion.md index ac3f64fc2..c1dd0e278 100644 --- a/docs/api/safeds/ml/nn/OutputConversion.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversion.md @@ -3,7 +3,7 @@ search: boost: 0.5 --- -# :test_tube:{ title="Experimental" } `#!sds abstract class` OutputConversion {#safeds.ml.nn.OutputConversion data-toc-label='OutputConversion'} +# :test_tube:{ title="Experimental" } `#!sds abstract class` OutputConversion {#safeds.ml.nn.converters.OutputConversion data-toc-label='OutputConversion'} The output conversion for a neural network, defines the output parameters for the neural network. @@ -16,10 +16,10 @@ The output conversion for a neural network, defines the output parameters for th **Inheritors:** -- [`OutputConversionImageToColumn`][safeds.ml.nn.OutputConversionImageToColumn] -- [`OutputConversionImageToImage`][safeds.ml.nn.OutputConversionImageToImage] -- [`OutputConversionImageToTable`][safeds.ml.nn.OutputConversionImageToTable] -- [`OutputConversionTable`][safeds.ml.nn.OutputConversionTable] +- [`OutputConversionImageToColumn`][safeds.ml.nn.converters.OutputConversionImageToColumn] +- [`OutputConversionImageToImage`][safeds.ml.nn.converters.OutputConversionImageToImage] +- [`OutputConversionImageToTable`][safeds.ml.nn.converters.OutputConversionImageToTable] +- [`OutputConversionTable`][safeds.ml.nn.converters.OutputConversionTable] ??? quote "Stub code in `OutputConversion.sdsstub`" diff --git a/docs/api/safeds/ml/nn/OutputConversionImageToColumn.md b/docs/api/safeds/ml/nn/converters/OutputConversionImageToColumn.md similarity index 65% rename from docs/api/safeds/ml/nn/OutputConversionImageToColumn.md rename to docs/api/safeds/ml/nn/converters/OutputConversionImageToColumn.md index 0e2032199..1568414d4 100644 --- a/docs/api/safeds/ml/nn/OutputConversionImageToColumn.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversionImageToColumn.md @@ -1,6 +1,6 @@ -# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToColumn {#safeds.ml.nn.OutputConversionImageToColumn data-toc-label='OutputConversionImageToColumn'} +# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToColumn {#safeds.ml.nn.converters.OutputConversionImageToColumn data-toc-label='OutputConversionImageToColumn'} -**Parent type:** [`OutputConversion>`][safeds.ml.nn.OutputConversion] +**Parent type:** [`OutputConversion>`][safeds.ml.nn.converters.OutputConversion] ??? quote "Stub code in `OutputConversionImageToColumn.sdsstub`" diff --git a/docs/api/safeds/ml/nn/OutputConversionImageToImage.md b/docs/api/safeds/ml/nn/converters/OutputConversionImageToImage.md similarity index 67% rename from docs/api/safeds/ml/nn/OutputConversionImageToImage.md rename to docs/api/safeds/ml/nn/converters/OutputConversionImageToImage.md index abd01c91c..42a75de4b 100644 --- a/docs/api/safeds/ml/nn/OutputConversionImageToImage.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversionImageToImage.md @@ -1,6 +1,6 @@ -# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToImage {#safeds.ml.nn.OutputConversionImageToImage data-toc-label='OutputConversionImageToImage'} +# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToImage {#safeds.ml.nn.converters.OutputConversionImageToImage data-toc-label='OutputConversionImageToImage'} -**Parent type:** [`OutputConversion`][safeds.ml.nn.OutputConversion] +**Parent type:** [`OutputConversion`][safeds.ml.nn.converters.OutputConversion] ??? quote "Stub code in `OutputConversionImageToImage.sdsstub`" diff --git a/docs/api/safeds/ml/nn/OutputConversionImageToTable.md b/docs/api/safeds/ml/nn/converters/OutputConversionImageToTable.md similarity index 67% rename from docs/api/safeds/ml/nn/OutputConversionImageToTable.md rename to docs/api/safeds/ml/nn/converters/OutputConversionImageToTable.md index 235c3edb1..116528b1f 100644 --- a/docs/api/safeds/ml/nn/OutputConversionImageToTable.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversionImageToTable.md @@ -1,6 +1,6 @@ -# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToTable {#safeds.ml.nn.OutputConversionImageToTable data-toc-label='OutputConversionImageToTable'} +# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionImageToTable {#safeds.ml.nn.converters.OutputConversionImageToTable data-toc-label='OutputConversionImageToTable'} -**Parent type:** [`OutputConversion`][safeds.ml.nn.OutputConversion] +**Parent type:** [`OutputConversion`][safeds.ml.nn.converters.OutputConversion] ??? quote "Stub code in `OutputConversionImageToTable.sdsstub`" diff --git a/docs/api/safeds/ml/nn/OutputConversionTable.md b/docs/api/safeds/ml/nn/converters/OutputConversionTable.md similarity index 83% rename from docs/api/safeds/ml/nn/OutputConversionTable.md rename to docs/api/safeds/ml/nn/converters/OutputConversionTable.md index d9291a241..2434ef85e 100644 --- a/docs/api/safeds/ml/nn/OutputConversionTable.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversionTable.md @@ -1,8 +1,8 @@ -# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionTable {#safeds.ml.nn.OutputConversionTable data-toc-label='OutputConversionTable'} +# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionTable {#safeds.ml.nn.converters.OutputConversionTable data-toc-label='OutputConversionTable'} The output conversion for a neural network defines the output parameters for the neural network. -**Parent type:** [`OutputConversion`][safeds.ml.nn.OutputConversion] +**Parent type:** [`OutputConversion`][safeds.ml.nn.converters.OutputConversion] **Parameters:** diff --git a/docs/api/safeds/ml/nn/OutputConversionTimeSeries.md b/docs/api/safeds/ml/nn/converters/OutputConversionTimeSeries.md similarity index 84% rename from docs/api/safeds/ml/nn/OutputConversionTimeSeries.md rename to docs/api/safeds/ml/nn/converters/OutputConversionTimeSeries.md index 1b435a297..4ca7a2601 100644 --- a/docs/api/safeds/ml/nn/OutputConversionTimeSeries.md +++ b/docs/api/safeds/ml/nn/converters/OutputConversionTimeSeries.md @@ -1,4 +1,4 @@ -# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionTimeSeries {#safeds.ml.nn.OutputConversionTimeSeries data-toc-label='OutputConversionTimeSeries'} +# :test_tube:{ title="Experimental" } `#!sds class` OutputConversionTimeSeries {#safeds.ml.nn.converters.OutputConversionTimeSeries data-toc-label='OutputConversionTimeSeries'} The output conversion for a neural network, defines the output parameters for the neural network. diff --git a/docs/api/safeds/ml/nn/layers/AveragePooling2DLayer.md b/docs/api/safeds/ml/nn/layers/AveragePooling2DLayer.md new file mode 100644 index 000000000..6e9799c40 --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/AveragePooling2DLayer.md @@ -0,0 +1,42 @@ +# :test_tube:{ title="Experimental" } `#!sds class` AveragePooling2DLayer {#safeds.ml.nn.layers.AveragePooling2DLayer data-toc-label='AveragePooling2DLayer'} + +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `kernelSize` | [`Int`][safeds.lang.Int] | the size of the kernel | - | +| `stride` | [`Int`][safeds.lang.Int] | the stride of the pooling | `#!sds -1` | +| `padding` | [`Int`][safeds.lang.Int] | the padding of the pooling | `#!sds 0` | + +??? quote "Stub code in `AveragePooling2DLayer.sdsstub`" + + ```sds linenums="11" + class AveragePooling2DLayer( + @PythonName("kernel_size") kernelSize: Int, + stride: Int = -1, + padding: Int = 0 + ) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize + } + ``` + +## `#!sds attr` inputSize {#safeds.ml.nn.layers.AveragePooling2DLayer.inputSize data-toc-label='inputSize'} + +Get the input_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] + +## `#!sds attr` outputSize {#safeds.ml.nn.layers.AveragePooling2DLayer.outputSize data-toc-label='outputSize'} + +Get the output_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] diff --git a/docs/api/safeds/ml/nn/layers/Convolutional2DLayer.md b/docs/api/safeds/ml/nn/layers/Convolutional2DLayer.md new file mode 100644 index 000000000..d72d09b3e --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/Convolutional2DLayer.md @@ -0,0 +1,48 @@ +# :test_tube:{ title="Experimental" } `#!sds class` Convolutional2DLayer {#safeds.ml.nn.layers.Convolutional2DLayer data-toc-label='Convolutional2DLayer'} + +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `outputChannel` | [`Int`][safeds.lang.Int] | the amount of output channels | - | +| `kernelSize` | [`Int`][safeds.lang.Int] | the size of the kernel | - | +| `stride` | [`Int`][safeds.lang.Int] | the stride of the convolution | `#!sds 1` | +| `padding` | [`Int`][safeds.lang.Int] | the padding of the convolution | `#!sds 0` | + +**Inheritors:** + +- [`ConvolutionalTranspose2DLayer`][safeds.ml.nn.layers.ConvolutionalTranspose2DLayer] + +??? quote "Stub code in `Convolutional2DLayer.sdsstub`" + + ```sds linenums="13" + class Convolutional2DLayer( + @PythonName("output_channel") outputChannel: Int, + @PythonName("kernel_size") kernelSize: Int, + stride: Int = 1, + padding: Int = 0 + ) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize + } + ``` + +## `#!sds attr` inputSize {#safeds.ml.nn.layers.Convolutional2DLayer.inputSize data-toc-label='inputSize'} + +Get the input_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] + +## `#!sds attr` outputSize {#safeds.ml.nn.layers.Convolutional2DLayer.outputSize data-toc-label='outputSize'} + +Get the output_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] diff --git a/docs/api/safeds/ml/nn/ConvolutionalTranspose2DLayer.md b/docs/api/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.md similarity index 61% rename from docs/api/safeds/ml/nn/ConvolutionalTranspose2DLayer.md rename to docs/api/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.md index afd735bef..20ea71240 100644 --- a/docs/api/safeds/ml/nn/ConvolutionalTranspose2DLayer.md +++ b/docs/api/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.md @@ -1,6 +1,6 @@ -# :test_tube:{ title="Experimental" } `#!sds class` ConvolutionalTranspose2DLayer {#safeds.ml.nn.ConvolutionalTranspose2DLayer data-toc-label='ConvolutionalTranspose2DLayer'} +# :test_tube:{ title="Experimental" } `#!sds class` ConvolutionalTranspose2DLayer {#safeds.ml.nn.layers.ConvolutionalTranspose2DLayer data-toc-label='ConvolutionalTranspose2DLayer'} -**Parent type:** [`Convolutional2DLayer`][safeds.ml.nn.Convolutional2DLayer] +**Parent type:** [`Convolutional2DLayer`][safeds.ml.nn.layers.Convolutional2DLayer] **Parameters:** @@ -24,14 +24,14 @@ ) sub Convolutional2DLayer ``` -## `#!sds attr` inputSize {#safeds.ml.nn.ConvolutionalTranspose2DLayer.inputSize data-toc-label='inputSize'} +## `#!sds attr` inputSize {#safeds.ml.nn.layers.ConvolutionalTranspose2DLayer.inputSize data-toc-label='inputSize'} -The input_size of this layer. +Get the input_size of this layer. -**Type:** [`Int`][safeds.lang.Int] +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] -## `#!sds attr` outputSize {#safeds.ml.nn.ConvolutionalTranspose2DLayer.outputSize data-toc-label='outputSize'} +## `#!sds attr` outputSize {#safeds.ml.nn.layers.ConvolutionalTranspose2DLayer.outputSize data-toc-label='outputSize'} -The output_size of this layer. +Get the output_size of this layer. -**Type:** [`Int`][safeds.lang.Int] +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] diff --git a/docs/api/safeds/ml/nn/layers/FlattenLayer.md b/docs/api/safeds/ml/nn/layers/FlattenLayer.md new file mode 100644 index 000000000..f03c23e0c --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/FlattenLayer.md @@ -0,0 +1,30 @@ +# :test_tube:{ title="Experimental" } `#!sds class` FlattenLayer {#safeds.ml.nn.layers.FlattenLayer data-toc-label='FlattenLayer'} + +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] + +??? quote "Stub code in `FlattenLayer.sdsstub`" + + ```sds linenums="7" + class FlattenLayer() sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: Int + } + ``` + +## `#!sds attr` inputSize {#safeds.ml.nn.layers.FlattenLayer.inputSize data-toc-label='inputSize'} + +Get the input_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] + +## `#!sds attr` outputSize {#safeds.ml.nn.layers.FlattenLayer.outputSize data-toc-label='outputSize'} + +Get the output_size of this layer. + +**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/layers/ForwardLayer.md b/docs/api/safeds/ml/nn/layers/ForwardLayer.md new file mode 100644 index 000000000..550f19b4a --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/ForwardLayer.md @@ -0,0 +1,40 @@ +# :test_tube:{ title="Experimental" } `#!sds class` ForwardLayer {#safeds.ml.nn.layers.ForwardLayer data-toc-label='ForwardLayer'} + +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `outputSize` | [`Int`][safeds.lang.Int] | The number of neurons in this layer | - | +| `inputSize` | [`Int?`][safeds.lang.Int] | The number of neurons in the previous layer | `#!sds null` | + +??? quote "Stub code in `ForwardLayer.sdsstub`" + + ```sds linenums="10" + class ForwardLayer( + @PythonName("output_size") outputSize: Int, + @PythonName("input_size") inputSize: Int? = null + ) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: Int + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: Int + } + ``` + +## `#!sds attr` inputSize {#safeds.ml.nn.layers.ForwardLayer.inputSize data-toc-label='inputSize'} + +Get the input_size of this layer. + +**Type:** [`Int`][safeds.lang.Int] + +## `#!sds attr` outputSize {#safeds.ml.nn.layers.ForwardLayer.outputSize data-toc-label='outputSize'} + +Get the output_size of this layer. + +**Type:** [`Int`][safeds.lang.Int] diff --git a/docs/api/safeds/ml/nn/LSTMLayer.md b/docs/api/safeds/ml/nn/layers/LSTMLayer.md similarity index 76% rename from docs/api/safeds/ml/nn/LSTMLayer.md rename to docs/api/safeds/ml/nn/layers/LSTMLayer.md index ac35f5c59..9a70b191c 100644 --- a/docs/api/safeds/ml/nn/LSTMLayer.md +++ b/docs/api/safeds/ml/nn/layers/LSTMLayer.md @@ -1,6 +1,6 @@ -# :test_tube:{ title="Experimental" } `#!sds class` LSTMLayer {#safeds.ml.nn.LSTMLayer data-toc-label='LSTMLayer'} +# :test_tube:{ title="Experimental" } `#!sds class` LSTMLayer {#safeds.ml.nn.layers.LSTMLayer data-toc-label='LSTMLayer'} -**Parent type:** [`Layer`][safeds.ml.nn.Layer] +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] **Parameters:** @@ -27,13 +27,13 @@ } ``` -## `#!sds attr` inputSize {#safeds.ml.nn.LSTMLayer.inputSize data-toc-label='inputSize'} +## `#!sds attr` inputSize {#safeds.ml.nn.layers.LSTMLayer.inputSize data-toc-label='inputSize'} Get the input_size of this layer. **Type:** [`Int`][safeds.lang.Int] -## `#!sds attr` outputSize {#safeds.ml.nn.LSTMLayer.outputSize data-toc-label='outputSize'} +## `#!sds attr` outputSize {#safeds.ml.nn.layers.LSTMLayer.outputSize data-toc-label='outputSize'} Get the output_size of this layer. diff --git a/docs/api/safeds/ml/nn/layers/Layer.md b/docs/api/safeds/ml/nn/layers/Layer.md new file mode 100644 index 000000000..70872e9f8 --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/Layer.md @@ -0,0 +1,21 @@ +--- +search: + boost: 0.5 +--- + +# :test_tube:{ title="Experimental" } `#!sds abstract class` Layer {#safeds.ml.nn.layers.Layer data-toc-label='Layer'} + +**Inheritors:** + +- [`AveragePooling2DLayer`][safeds.ml.nn.layers.AveragePooling2DLayer] +- [`Convolutional2DLayer`][safeds.ml.nn.layers.Convolutional2DLayer] +- [`FlattenLayer`][safeds.ml.nn.layers.FlattenLayer] +- [`ForwardLayer`][safeds.ml.nn.layers.ForwardLayer] +- [`LSTMLayer`][safeds.ml.nn.layers.LSTMLayer] +- [`MaxPooling2DLayer`][safeds.ml.nn.layers.MaxPooling2DLayer] + +??? quote "Stub code in `Layer.sdsstub`" + + ```sds linenums="6" + class Layer + ``` diff --git a/docs/api/safeds/ml/nn/layers/MaxPooling2DLayer.md b/docs/api/safeds/ml/nn/layers/MaxPooling2DLayer.md new file mode 100644 index 000000000..ff459690d --- /dev/null +++ b/docs/api/safeds/ml/nn/layers/MaxPooling2DLayer.md @@ -0,0 +1,42 @@ +# :test_tube:{ title="Experimental" } `#!sds class` MaxPooling2DLayer {#safeds.ml.nn.layers.MaxPooling2DLayer data-toc-label='MaxPooling2DLayer'} + +**Parent type:** [`Layer`][safeds.ml.nn.layers.Layer] + +**Parameters:** + +| Name | Type | Description | Default | +|------|------|-------------|---------| +| `kernelSize` | [`Int`][safeds.lang.Int] | the size of the kernel | - | +| `stride` | [`Int`][safeds.lang.Int] | the stride of the pooling | `#!sds -1` | +| `padding` | [`Int`][safeds.lang.Int] | the padding of the pooling | `#!sds 0` | + +??? quote "Stub code in `MaxPooling2DLayer.sdsstub`" + + ```sds linenums="11" + class MaxPooling2DLayer( + @PythonName("kernel_size") kernelSize: Int, + stride: Int = -1, + padding: Int = 0 + ) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize + } + ``` + +## `#!sds attr` inputSize {#safeds.ml.nn.layers.MaxPooling2DLayer.inputSize data-toc-label='inputSize'} + +Get the input_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] + +## `#!sds attr` outputSize {#safeds.ml.nn.layers.MaxPooling2DLayer.outputSize data-toc-label='outputSize'} + +Get the output_size of this layer. + +**Type:** [`ImageSize`][safeds.data.image.typing.ImageSize] diff --git a/packages/safe-ds-lang/src/language/runtime/safe-ds-python-server.ts b/packages/safe-ds-lang/src/language/runtime/safe-ds-python-server.ts index c26bf0e83..7567b0a90 100644 --- a/packages/safe-ds-lang/src/language/runtime/safe-ds-python-server.ts +++ b/packages/safe-ds-lang/src/language/runtime/safe-ds-python-server.ts @@ -16,8 +16,8 @@ import { UpdateRunnerNotification, } from '../communication/rpc.js'; -const LOWEST_SUPPORTED_RUNNER_VERSION = '0.15.0'; -const LOWEST_UNSUPPORTED_RUNNER_VERSION = '0.16.0'; +const LOWEST_SUPPORTED_RUNNER_VERSION = '0.16.0'; +const LOWEST_UNSUPPORTED_RUNNER_VERSION = '0.17.0'; const npmVersionRange = `>=${LOWEST_SUPPORTED_RUNNER_VERSION} <${LOWEST_UNSUPPORTED_RUNNER_VERSION}`; export const pipVersionRange = `>=${LOWEST_SUPPORTED_RUNNER_VERSION},<${LOWEST_UNSUPPORTED_RUNNER_VERSION}`; diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/image/containers/ImageList.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/image/containers/ImageList.sdsstub index a28b53495..e86c89550 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/image/containers/ImageList.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/image/containers/ImageList.sdsstub @@ -18,7 +18,7 @@ class ImageList { /** * Return the number of images in this image list. */ - @PythonName("number_of_images") attr numberOfImages: Int + @PythonName("number_of_images") attr imageCount: Int /** * Return a list of all widths in this image list. */ @@ -38,7 +38,7 @@ class ImageList { /** * Return the number of different sizes of images in this image list. */ - @PythonName("number_of_sizes") attr numberOfSizes: Int + @PythonName("number_of_sizes") attr sizeCount: Int /** * Create an ImageList from a list of images. @@ -133,7 +133,7 @@ class ImageList { /** * Return a list of all images in this image list. * - * @param indices a list of all indices to include in the output. If None, all indices will be included + * @param indices a list of all indices to include in the output. If null, all indices will be included * * @result images the list of all images */ diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/Dataset.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/Dataset.sdsstub new file mode 100644 index 000000000..e88e1c8cf --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/Dataset.sdsstub @@ -0,0 +1,6 @@ +package safeds.data.labeled.containers + +/** + * A dataset is used as input to machine learning models. + */ +class Dataset diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ExperimentalTabularDataset.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ExperimentalTabularDataset.sdsstub deleted file mode 100644 index da990c3ca..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ExperimentalTabularDataset.sdsstub +++ /dev/null @@ -1,62 +0,0 @@ -package safeds.data.labeled.containers - -from safeds.data.tabular.containers import ExperimentalTable - -/** - * A dataset containing tabular data. It can be used to train machine learning models. - * - * Columns in a tabular dataset are divided into three categories: - * - * * The target column is the column that a model should predict. - * * Feature columns are columns that a model should use to make predictions. - * * Extra columns are columns that are neither feature nor target. They can be used to provide additional context, - * like an ID column. - * - * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns - * are specified, all columns except the target column are used as features. - * - * @param data The data. - * @param targetName Name of the target column. - * @param extraNames Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but - * the target column are used as features. - * - * @example - * pipeline example { - * // from safeds.data.labeled.containers import TabularDataset - * // dataset = TabularDataset( - * // {"id": [1, 2, 3], "feature": [4, 5, 6], "target": [1, 2, 3]}, - * // target_name="target", - * // extra_names=["id"] - * // ) - * } - */ -@Experimental -class ExperimentalTabularDataset( - data: ExperimentalTable, - @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List? = null -) { - /** - * The feature columns of the tabular dataset. - */ - attr features: ExperimentalTable - /** - * The target column of the tabular dataset. - */ - attr target: ExperimentalColumn - /** - * Additional columns of the tabular dataset that are neither features nor target. - * - * These can be used to store additional information about instances, such as IDs. - */ - attr extras: ExperimentalTable - - /** - * Return a table containing all columns of the tabular dataset. - * - * @result table A table containing all columns of the tabular dataset. - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ImageDataset.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ImageDataset.sdsstub index 5cc143472..66ba1a649 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ImageDataset.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/ImageDataset.sdsstub @@ -2,6 +2,7 @@ package safeds.data.labeled.containers from safeds.data.image.containers import ImageList from safeds.data.image.typing import ImageSize +from safeds.data.labeled.containers import Dataset from safeds.data.tabular.containers import Table /** @@ -18,7 +19,7 @@ class ImageDataset( @PythonName("output_data") outputData: T, @PythonName("batch_size") batchSize: Int = 1, shuffle: Boolean = false -) { +) sub Dataset { /** * Get the input `ImageSize` of this dataset. */ diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TabularDataset.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TabularDataset.sdsstub index d9613613a..1528ae870 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TabularDataset.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TabularDataset.sdsstub @@ -1,34 +1,43 @@ package safeds.data.labeled.containers +from safeds.data.labeled.containers import Dataset +from safeds.data.tabular.containers import Table + /** - * A tabular dataset maps feature columns to a target column. + * A dataset containing tabular data. It can be used to train machine learning models. * - * Create a tabular dataset from a mapping of column names to their values. + * Columns in a tabular dataset are divided into three categories: * - * @param data - * The data. + * - The target column is the column that a model should predict. + * - Feature columns are columns that a model should use to make predictions. + * - Extra columns are columns that are neither feature nor target. They can be used to provide additional context, + * like an ID column. * - * @param targetName - * Name of the target column. + * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns + * are specified, all columns except the target column are used as features. * - * @param extraNames - * Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the - * target column are used as features. + * @param data The data. + * @param targetName Name of the target column. + * @param extraNames Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but + * the target column are used as features. * * @example * pipeline example { - * val dataset = TabularDataset( - * {"id": [1, 2, 3], "feature": [4, 5, 6], "target": [1, 2, 3]}, - * targetName="target", - * extraNames=["id"] + * val table = Table( + * { + * "id": [1, 2, 3], + * "feature": [4, 5, 6], + * "target": [1, 2, 3], + * }, * ); + * val dataset = table.toTabularDataset(targetName="target", extraNames=["id"]); * } */ class TabularDataset( data: union>, Table>, @PythonName("target_name") targetName: String, @PythonName("extra_names") extraNames: List = [] -) { +) sub Dataset { /** * The feature columns of the tabular dataset. */ @@ -45,11 +54,9 @@ class TabularDataset( attr extras: Table /** - * Return a new `Table` containing the feature columns and the target column. - * - * The original `TabularDataset` is not modified. + * Return a table containing all columns of the tabular dataset. * - * @result table A table containing the feature columns and the target column. + * @result table A table containing all columns of the tabular dataset. */ @Pure @PythonName("to_table") diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TimeSeriesDataset.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TimeSeriesDataset.sdsstub index d614186ab..ebe2ca1b8 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TimeSeriesDataset.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/labeled/containers/TimeSeriesDataset.sdsstub @@ -10,7 +10,7 @@ from safeds.data.tabular.containers import Table * @param data The data. * @param targetName Name of the target column. * @param timeName Name of the time column. - * @param extraNames Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but + * @param extraNames Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but * the target column are used as features. * * @example diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Cell.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Cell.sdsstub new file mode 100644 index 000000000..c0ae8cb0a --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Cell.sdsstub @@ -0,0 +1,286 @@ +package safeds.data.tabular.containers + +/** + * A single value in a table. + * + * This class cannot be instantiated directly. It is only used for arguments of callbacks. + */ +class Cell { + /** + * Negate a boolean. This WILL LATER BE equivalent to the ^not operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^not()); + * // Column("example", [false, true]) + * } + */ + @Pure + @PythonName("not_") + fun ^not() -> result: Cell + + /** + * Perform a boolean AND operation. This WILL LATER BE equivalent to the ^and operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^and(false)); + * // Column("example", [false, false]) + * } + */ + @Pure + @PythonName("and_") + fun ^and( + other: union> + ) -> result: Cell + + /** + * Perform a boolean OR operation. This WILL LATER BE equivalent to the ^or operator. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.^or(true)); + * // Column("example", [true, true]) + * } + */ + @Pure + @PythonName("or_") + fun ^or( + other: union> + ) -> result: Cell + + /** + * Perform a boolean XOR operation. + * + * @example + * pipeline example { + * val column = Column("example", [true, false]); + * val result = column.transform((cell) -> cell.xor(true)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun xor( + other: union> + ) -> result: Cell + + /** + * Get the absolute value. + * + * @example + * pipeline example { + * val column = Column("example", [1, -2]); + * val result = column.transform((cell) -> cell.abs()); + * // Column("example", [1, 2]) + * } + */ + @Pure + fun abs() -> result: Cell + + /** + * Round up to the nearest integer. + * + * @example + * pipeline example { + * val column = Column("example", [1.1, 2.9]); + * val result = column.transform((cell) -> cell.ceil()); + * // Column("example", [2, 3]) + * } + */ + @Pure + fun ceil() -> result: Cell + + /** + * Round down to the nearest integer. + * + * @example + * pipeline example { + * val column = Column("example", [1.1, 2.9]); + * val result = column.transform((cell) -> cell.floor()); + * // Column("example", [1, 2]) + * } + */ + @Pure + fun floor() -> result: Cell + + /** + * Negate the value. + * + * @example + * pipeline example { + * val column = Column("example", [1, -2]); + * val result = column.transform((cell) -> cell.neg()); + * // Column("example", [-1, 2]) + * } + */ + @Pure + fun neg() -> result: Cell + + /** + * Add a value. This WILL LATER BE equivalent to the `+` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.add(3)); + * // Column("example", [4, 5]) + * } + */ + @Pure + fun add( + other: Any + ) -> result: Cell + + /** + * Perform a modulo operation. + * + * @example + * pipeline example { + * val column = Column("example", [5, 6]); + * val result = column.transform((cell) -> cell.mod(3)); + * // Column("example", [2, 0]) + * } + */ + @Pure + fun mod( + other: Any + ) -> result: Cell + + /** + * Multiply by a value. This WILL LATER BE equivalent to the `*` operator. + * + * @example + * pipeline example { + * val column = Column("example", [2, 3]); + * val result = column.transform((cell) -> cell.mul(4)); + * // Column("example", [8, 12]) + * } + */ + @Pure + fun mul( + other: Any + ) -> result: Cell + + /** + * Raise to a power. + * + * @example + * pipeline example { + * val column = Column("example", [2, 3]); + * val result = column.transform((cell) -> cell.pow(3.0)); + * // Column("example", [8, 27]) + * } + */ + @Pure + fun pow( + other: union + ) -> result: Cell + + /** + * Subtract a value. This WILL LATER BE equivalent to the `-` operator. + * + * @example + * pipeline example { + * val column = Column("example", [5, 6]); + * val result = column.transform((cell) -> cell.^sub(3)); + * // Column("example", [2, 3]) + * } + */ + @Pure + fun ^sub( + other: Any + ) -> result: Cell + + /** + * Divide by a value. This WILL LATER BE equivalent to the `/` operator. + * + * @example + * pipeline example { + * val column = Column("example", [6, 8]); + * val result = column.transform((cell) -> cell.div(2)); + * // Column("example", [3, 4]) + * } + */ + @Pure + fun div( + other: Any + ) -> result: Cell + + /** + * Check if equal to a value. This WILL LATER BE equivalent to the `==` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.eq(2)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun eq( + other: Any + ) -> result: Cell + + /** + * Check if greater than or equal to a value. This WILL LATER BE equivalent to the `>=` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.ge(2)); + * // Column("example", [false, true]) + * } + */ + @Pure + fun ge( + other: Any + ) -> result: Cell + + /** + * Check if greater than a value. This WILL LATER BE equivalent to the `>` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.gt(2)); + * // Column("example", [false, false]) + * } + */ + @Pure + fun gt( + other: Any + ) -> result: Cell + + /** + * Check if less than or equal to a value. This WILL LATER BE equivalent to the `<=` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.le(2)); + * // Column("example", [true, true]) + * } + */ + @Pure + fun le( + other: Any + ) -> result: Cell + + /** + * Check if less than a value. This WILL LATER BE equivalent to the `<` operator. + * + * @example + * pipeline example { + * val column = Column("example", [1, 2]); + * val result = column.transform((cell) -> cell.lt(2)); + * // Column("example", [true, false]) + * } + */ + @Pure + fun lt( + other: Any + ) -> result: Cell +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Column.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Column.sdsstub index 6c8caad0f..a8c1083c4 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Column.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Column.sdsstub @@ -1,14 +1,14 @@ package safeds.data.tabular.containers -from safeds.data.image.containers import Image from safeds.data.tabular.containers import Table -from safeds.data.tabular.typing import ColumnType +from safeds.data.tabular.plotting import ColumnPlotter +from safeds.data.tabular.typing import DataType /** - * A column is a named collection of values. + * A named, one-dimensional collection of homogeneous values. * * @param name The name of the column. - * @param data The data. + * @param data The data of the column. If null, an empty column is created. * * @example * pipeline example { @@ -17,183 +17,54 @@ from safeds.data.tabular.typing import ColumnType */ class Column( name: String, - data: List = [] + data: List? = null ) { /** - * Return the name of the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val name = column.name; // "test" - * } + * Whether the column is numeric. */ - attr name: String + @PythonName("is_numeric") attr isNumeric: Boolean /** - * Return the number of elements in the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val numberOfRows = column.numberOfRows; // 3 - * } + * Whether the column is temporal. */ - @PythonName("number_of_rows") attr numberOfRows: Int + @PythonName("is_temporal") attr isTemporal: Boolean /** - * Return the type of the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val type = column.type; // Integer - * } - * - * @example - * pipeline example { - * val column = Column("test", ["a", "b", "c"]); - * val type = column.type; // String - * } + * The name of the column. */ - attr type: ColumnType - - /** - * Return a list of all unique values in the column. - * - * @result result1 List of unique values in the column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, 2, 4, 3]); - * val uniqueValues = column.getUniqueValues(); // [1, 2, 3, 4] - * } - */ - @Deprecated( - alternative="Try ExperimentalColumn.getDistinctValues instead.", - reason="The word 'unique' could imply that only values that occur exactly once are returned.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("get_unique_values") - fun getUniqueValues() -> result1: List - + attr name: String /** - * Return column value at specified index, starting at 0. - * - * @param index Index of requested element. - * - * @result result1 Value at index in column. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val value = column.getValue(1); // 2 - * } + * The number of rows in the column. */ - @Pure - @PythonName("get_value") - fun getValue( - index: Int - ) -> result1: T - + @PythonName("number_of_rows") attr rowCount: Int /** - * Check if all values have a given property. - * - * @param predicate Callable that is used to find matches. - * - * @result allMatch True if all match. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val allMatch = column.all((value) -> value < 4); // true - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val allMatch = column.all((value) -> value < 2); // false - * } + * The plotter for the column. */ - @Pure - fun all( - predicate: (value: T) -> matches: Boolean - ) -> allMatch: Boolean - + attr plot: ColumnPlotter /** - * Check if any value has a given property. - * - * @param predicate Callable that is used to find matches. - * - * @result anyMatch True if any match. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val anyMatch = column.any((value) -> value < 2); // true - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val anyMatch = column.any((value) -> value < 1); // false - * } + * The type of the column. */ - @Pure - fun any( - predicate: (value: T) -> matches: Boolean - ) -> anyMatch: Boolean + attr type: DataType /** - * Check if no values has a given property. + * Return the column value at specified index. * - * @param predicate Callable that is used to find matches. + * Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at + * -1). * - * @result noneMatch True if none match. + * @param index Index of requested value. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val noneMatch = column.none((value) -> value < 1); // true - * } + * @result value Value at index. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val noneMatch = column.none((value) -> value > 1); // false + * val result = column.getValue(1); // 2 * } */ @Pure - fun none( - predicate: (value: T) -> matches: Boolean - ) -> noneMatch: Boolean - - /** - * Return whether the column has missing values. - * - * @result hasMissingValues True if missing values exist. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val hasMissingValues = column.hasMissingValues(); // true - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val hasMissingValues = column.hasMissingValues(); // false - * } - */ - @Deprecated( - alternative="Column.missingValueCount() > 0.", - reason="Barely saves any characters.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("has_missing_values") - fun hasMissingValues() -> hasMissingValues: Boolean + @PythonName("get_value") + fun getValue( + index: Int + ) -> value: T /** * Return a new column with a new name. @@ -207,46 +78,45 @@ class Column( * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val renamedColumn = column.rename("new_name"); + * val result = column.rename("new_name"); + * // Column("new_name", [1, 2, 3]) * } */ @Pure fun rename( @PythonName("new_name") newName: String - ) -> renamedColumn: Column + ) -> renamedColumn: Column /** - * Apply a transform method to every data point. + * Return a new column with values transformed by the transformer. * * The original column is not modified. * - * @param transformer Function that will be applied to all data points. + * @param transformer The transformer to apply to each value. * - * @result transformedColumn The transformed column. + * @result transformedColumn A new column with transformed values. * * @example * pipeline example { - * val price = Column("price", [4.99, 5.99, 2.49]); - * val discountedPrice = price.transform((value) -> value * 0.75); + * val column = Column("test", [1, 2, 3]); + * val result = column.transform((cell) -> cell.mul(2)); + * // Column("test", [2, 4, 6]) * } */ @Pure fun transform( - transformer: (value: T) -> transformedValue: R + transformer: (cell: Cell) -> transformedCell: Cell ) -> transformedColumn: Column /** - * Return a table with a number of statistical key values. - * - * The original Column is not modified. + * Return a table with important statistics about the column. * * @result statistics The table with statistics. * * @example * pipeline example { - * // from safeds.data.tabular.containers import Column - * // column = Column("a", [1, 3]) - * // column.summarize_statistics() + * val column = Column("a", [1, 3]); + * val result = column.summarizeStatistics(); * } */ @Pure @@ -254,229 +124,213 @@ class Column( fun summarizeStatistics() -> statistics: Table /** - * Calculate Pearson correlation between this and another column. Both columns have to be numerical. + * Calculate the Pearson correlation between this column and another column. + * + * The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly + * related: * - * @result correlation Correlation between the two columns. + * - A correlation of -1 indicates a perfect negative linear relationship. + * - A correlation of 0 indicates no linear relationship. + * - A correlation of 1 indicates a perfect positive linear relationship. + * + * @param other The other column to calculate the correlation with. + * + * @result correlation The Pearson correlation between the two columns. * * @example * pipeline example { - * val column1 = Column("test1", [1, 2, 3]); - * val column2 = Column("test2", [2, 4, 6]); - * val correlation = column1.correlationWith(column2); // 1.0 + * val column1 = Column("test", [1, 2, 3]); + * val column2 = Column("test", [2, 4, 6]); + * val result = column1.correlationWith(column2); * } * * @example * pipeline example { - * val column1 = Column("test1", [1, 2, 3]); - * val column2 = Column("test2", [3, 2, 1]); - * val correlation = column1.correlationWith(column2); // -1.0 + * val column1 = Column("test", [1, 2, 3]); + * val column2 = Column("test", [3, 2, 1]); + * val result = column1.correlationWith(column2); * } */ @Pure @PythonName("correlation_with") fun correlationWith( - @PythonName("other_column") otherColumn: Column + other: Column ) -> correlation: Float + /** + * Return the number of distinct values in the column. + * + * @param ignoreMissingValues Whether to ignore missing values when counting distinct values. + * + * @result distinctValueCount The number of distinct values in the column. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3, 2]); + * val result = column.distinctValueCount(); // 3 + * } + */ + @Pure + @PythonName("distinct_value_count") + fun distinctValueCount( + @PythonName("ignore_missing_values") ignoreMissingValues: Boolean = true + ) -> distinctValueCount: Int + /** * Calculate the idness of this column. * - * We define the idness as follows: + * We define the idness as the number of distinct values (including missing values) divided by the number of rows. + * If the column is empty, the idness is 1.0. * - * $$ - * \frac{\text{number of different values}}{\text{number of rows}} - * $$ + * A high idness indicates that the column most values in the column are unique. In this case, you must be careful + * when using the column for analysis, as a model may learn a mapping from this column to the target. * * @result idness The idness of the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val idness = column.idness(); // 1.0 + * val result = column.idness(); // 1.0 * } * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val idness = column.idness(); // 0.75 + * val column = Column("test", [1, 2, 3, 2]); + * val result = column.idness(); // 0.75 * } */ @Pure fun idness() -> idness: Float /** - * Return the maximum value of the column. The column has to be numerical. + * Return the maximum value in the column. * - * @result maximum The maximum value. + * @result max The maximum value in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val maximum = column.maximum(); // 3 + * val result = column.max(); // 3 * } */ - @Deprecated( - alternative="Try ExperimentalColumn.max instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - fun maximum() -> maximum: Float + fun max() -> max: T? /** - * Return the mean value of the column. The column has to be numerical. + * Return the mean of the values in the column. * - * @result mean The mean value. + * The mean is the sum of the values divided by the number of values. + * + * @result mean The mean of the values in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val mean = column.mean(); // 2.0 + * val result = column.mean(); // 2.0 * } */ @Pure - fun mean() -> mean: Float + fun mean() -> mean: T /** - * Return the median value of the column. The column has to be numerical. + * Return the median of the values in the column. * - * @result median The median value. + * The median is the value in the middle of the sorted list of values. If the number of values is even, the median + * is the mean of the two middle values. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val median = column.median(); // 2.0 - * } + * @result median The median of the values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val median = column.median(); // 2.5 + * val column = Column("test", [1, 2, 3]); + * val result = column.median(); // 2.0 * } */ @Pure - fun median() -> median: Float + fun median() -> median: T /** - * Return the minimum value of the column. The column has to be numerical. + * Return the minimum value in the column. * - * @result minimum The minimum value. + * @result min The minimum value in the column. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val minimum = column.minimum(); // 1 + * val result = column.min(); // 1 * } */ - @Deprecated( - alternative="Try ExperimentalColumn.min instead.", - reason="More concise.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - fun minimum() -> minimum: Float + fun min() -> min: T? /** * Return the number of missing values in the column. * - * @result count The number of missing values. + * @result missingValueCount The number of missing values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val missingValueCount = column.missingValueCount(); // 0 - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val missingValueCount = column.missingValueCount(); // 1 + * val column = Column("test", [1, null, 3]); + * val result = column.missingValueCount(); // 1 * } */ @Pure @PythonName("missing_value_count") - fun missingValueCount() -> count: Int + fun missingValueCount() -> missingValueCount: Int /** - * Return the ratio of missing values to the total number of elements in the column. + * Return the missing value ratio. * - * @result missinValueRatio The ratio of missing values to the total number of elements in the column. + * We define the missing value ratio as the number of missing values in the column divided by the number of rows. + * If the column is empty, the missing value ratio is 1.0. * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, 4]); - * val missingValueRatio = column.missingValueRatio(); // 0.0 - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3, null]); - * val missingValueRatio = column.missingValueRatio(); // 0.25 - * } - */ - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missinValueRatio: Float - - /** - * Return the mode of the column. + * A high missing value ratio indicates that the column is dominated by missing values. In this case, the column + * may not be useful for analysis. * - * @result mode Returns a list with the most common values. + * @result missingValueRatio The ratio of missing values in the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val mode = column.mode(); // [2] - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 2, 3, 3]); - * val mode = column.mode(); // [2, 3] + * val column = Column("test", [1, null, 3, null]); + * val result = column.missingValueRatio(); // 0.5 * } */ @Pure - fun mode() -> mode: List + @PythonName("missing_value_ratio") + fun missingValueRatio() -> missingValueRatio: Float /** - * Calculate the stability of this column. + * Return the stability of the column. * - * We define the stability as follows: + * We define the stability as the number of occurrences of the most common non-missing value divided by the total + * number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. * - * $$ - * \frac{\text{number of occurrences of most common non-null value}}{\text{number of non-null values}} - * $$ - * - * The stability is not defined for a column with only null values. + * A high stability indicates that the column is dominated by a single value. In this case, the column may not be + * useful for analysis. * * @result stability The stability of the column. * * @example * pipeline example { - * val column = Column("test", [1, 2, 2, 3]); - * val stability = column.stability(); // 0.5 - * } - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 2, 3, null]); - * val stability = column.stability(); // 0.5 + * val column = Column("test", [1, 1, 2, 3, null]); + * val result = column.stability(); // 0.5 * } */ @Pure fun stability() -> stability: Float /** - * Return the standard deviation of the column. The column has to be numerical. + * Return the standard deviation of the values in the column. + * + * The standard deviation is the square root of the variance. * - * @result standardDeviation The standard deviation of all values. + * @result standardDeviation The standard deviation of the values in the column. If no standard deviation can be calculated due to the + * type of the column, null is returned. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val standardDeviation = column.standardDeviation(); // 1.0 + * val result = column.standardDeviation(); // 1.0 * } */ @Pure @@ -484,159 +338,50 @@ class Column( fun standardDeviation() -> standardDeviation: Float /** - * Return the sum of the column. The column has to be numerical. + * Return the variance of the values in the column. * - * @result sum The sum of all values. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val sum = column.sum(); // 6 - * } - */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - fun sum() -> sum: Float - - /** - * Return the variance of the column. The column has to be numerical. + * The variance is the average of the squared differences from the mean. * - * @result variance The variance of all values. + * @result variance The variance of the values in the column. If no variance can be calculated due to the type of the column, + * null is returned. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val variance = column.variance(); // 1.0 + * val result = column.variance(); // 1.0 * } */ @Pure fun variance() -> variance: Float /** - * Plot this column in a boxplot. This function can only plot real numerical data. - * - * @result boxplot The plot as an image. - * - * @example - * pipeline example { - * val column = Column("test", [1, 2, 3]); - * val plot = column.plotBoxplot(); - * } - */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.boxPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_boxplot") - fun plotBoxplot() -> boxplot: Image - - /** - * Plot a column in a histogram. - * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. + * Return the values of the column in a list. * - * @result histogram The plot as an image. + * @result values The values of the column in a list. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val plot = column.plotHistogram(); + * val result = column.toList(); // [1, 2, 3] * } */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.histogram instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_histogram") - fun plotHistogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image - - /** - * Create a plot comparing the numerical values of columns using IDs as the x-axis. - * - * @param columnList A list of time columns to be plotted. - * - * @result plot A plot with all the Columns plotted by the ID on the x-axis. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Column - * // col1 =Column("target", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) - * // col2 =Column("target", [42, 51, 63, 71, 83, 91, 10, 11, 12, 13]) - * // image = col1.plot_compare_columns([col2]) - * } - */ - @Deprecated( - alternative="We still decide where to move this.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_compare_columns") - fun plotCompareColumns( - @PythonName("column_list") columnList: List> - ) -> plot: Image - - /** - * Plot a lagplot for the given column. - * - * @param lag The amount of lag used to plot - * - * @result plot The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Column("values", [1,2,3,4,3,2]) - * // image = table.plot_lagplot(2) - * } - */ - @Deprecated( - alternative="Try ExperimentalColumn.plot.lagPlot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_lagplot") - fun plotLagplot( - lag: Int - ) -> plot: Image + @PythonName("to_list") + fun toList() -> values: List /** * Create a table that contains only this column. * * @result table The table with this column. - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: Table - - /** - * Return an HTML representation of the column. - * - * @result html The generated HTML. * * @example * pipeline example { * val column = Column("test", [1, 2, 3]); - * val html = column.toHtml(); + * val result = column.toTable(); + * // Table({"test": [1, 2, 3]}) * } */ @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("to_table") + fun toTable() -> table: Table } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalCell.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalCell.sdsstub deleted file mode 100644 index 10655355d..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalCell.sdsstub +++ /dev/null @@ -1,287 +0,0 @@ -package safeds.data.tabular.containers - -/** - * A single value in a table. - * - * This class cannot be instantiated directly. It is only used for arguments of callbacks. - */ -@Experimental -class ExperimentalCell { - /** - * Negate a boolean. This is equivalent to the `~` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.not_()) - * } - */ - @Pure - @PythonName("not_") - fun ^not() -> result: ExperimentalCell - - /** - * Perform a boolean AND operation. This is equivalent to the `&` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.and_(False)) - * } - */ - @Pure - @PythonName("and_") - fun ^and( - other: union> - ) -> result: ExperimentalCell - - /** - * Perform a boolean OR operation. This is equivalent to the `|` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.or_(True)) - * } - */ - @Pure - @PythonName("or_") - fun ^or( - other: union> - ) -> result: ExperimentalCell - - /** - * Perform a boolean XOR operation. This is equivalent to the `^` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [True, False]) - * // column.transform(lambda cell: cell.xor(True)) - * } - */ - @Pure - fun xor( - other: union> - ) -> result: ExperimentalCell - - /** - * Get the absolute value. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, -2]) - * // column.transform(lambda cell: cell.abs()) - * } - */ - @Pure - fun abs() -> result: ExperimentalCell - - /** - * Round up to the nearest integer. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1.1, 2.9]) - * // column.transform(lambda cell: cell.ceil()) - * } - */ - @Pure - fun ceil() -> result: ExperimentalCell - - /** - * Round down to the nearest integer. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1.1, 2.9]) - * // column.transform(lambda cell: cell.floor()) - * } - */ - @Pure - fun floor() -> result: ExperimentalCell - - /** - * Negate the value. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, -2]) - * // column.transform(lambda cell: cell.neg()) - * } - */ - @Pure - fun neg() -> result: ExperimentalCell - - /** - * Add a value. This is equivalent to the `+` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.add(3)) - * } - */ - @Pure - fun add( - other: Any - ) -> result: ExperimentalCell - - /** - * Perform a modulo operation. This is equivalent to the `%` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [5, 6]) - * // column.transform(lambda cell: cell.mod(3)) - * } - */ - @Pure - fun mod( - other: Any - ) -> result: ExperimentalCell - - /** - * Multiply by a value. This is equivalent to the `*` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [2, 3]) - * // column.transform(lambda cell: cell.mul(4)) - * } - */ - @Pure - fun mul( - other: Any - ) -> result: ExperimentalCell - - /** - * Raise to a power. This is equivalent to the `**` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [2, 3]) - * // column.transform(lambda cell: cell.pow(3)) - * } - */ - @Pure - fun pow( - other: union - ) -> result: ExperimentalCell - - /** - * Subtract a value. This is equivalent to the `-` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [5, 6]) - * // column.transform(lambda cell: cell.sub(3)) - * } - */ - @Pure - fun ^sub( - other: Any - ) -> result: ExperimentalCell - - /** - * Divide by a value. This is equivalent to the `/` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [6, 8]) - * // column.transform(lambda cell: cell.div(2)) - * } - */ - @Pure - fun div( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if equal to a value. This is equivalent to the `==` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.eq(2)) - * } - */ - @Pure - fun eq( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if greater than or equal to a value. This is equivalent to the `>=` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.ge(2)) - * } - */ - @Pure - fun ge( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if greater than a value. This is equivalent to the `>` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.gt(2)) - * } - */ - @Pure - fun gt( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if less than or equal to a value. This is equivalent to the `<=` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.le(2)) - * } - */ - @Pure - fun le( - other: Any - ) -> result: ExperimentalCell - - /** - * Check if less than a value. This is equivalent to the `<` operator. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("example", [1, 2]) - * // column.transform(lambda cell: cell.lt(2)) - * } - */ - @Pure - fun lt( - other: Any - ) -> result: ExperimentalCell -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalColumn.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalColumn.sdsstub deleted file mode 100644 index 73a19da46..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalColumn.sdsstub +++ /dev/null @@ -1,507 +0,0 @@ -package safeds.data.tabular.containers - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.plotting import ExperimentalColumnPlotter -from safeds.data.tabular.typing import ExperimentalDataType - -/** - * A named, one-dimensional collection of homogeneous values. - * - * @param name The name of the column. - * @param data The data of the column. If None, an empty column is created. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // ExperimentalColumn("test", [1, 2, 3]) - * } - */ -@Experimental -class ExperimentalColumn( - name: String, - data: List? = null -) { - /** - * Whether the column is numeric. - */ - @PythonName("is_numeric") attr isNumeric: Boolean - /** - * Whether the column is temporal. - */ - @PythonName("is_temporal") attr isTemporal: Boolean - /** - * The name of the column. - */ - attr name: String - /** - * The number of rows in the column. - */ - @PythonName("number_of_rows") attr numberOfRows: Int - /** - * The plotter for the column. - */ - attr plot: ExperimentalColumnPlotter - /** - * The type of the column. - */ - attr type: ExperimentalDataType - - /** - * Return the distinct values in the column. - * - * @result distinctValues The distinct values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3, 2]) - * // column.get_distinct_values() - * } - */ - @Pure - @PythonName("get_distinct_values") - fun getDistinctValues() -> distinctValues: List - - /** - * Return the column value at specified index. Indexing starts at 0. - * - * @param index Index of requested value. - * - * @result value Value at index. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.get_value(1) - * } - */ - @Pure - @PythonName("get_value") - fun getValue( - index: Int - ) -> value: T - - /** - * Return whether all values in the column satisfy the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result allSatisfyPredicate Whether all values in the column satisfy the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.all(lambda cell: cell > 0) - * } - */ - @Pure - fun all( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> allSatisfyPredicate: Boolean - - /** - * Return whether any value in the column satisfies the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result anySatisfyPredicate Whether any value in the column satisfies the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.any(lambda cell: cell > 2) - * } - */ - @Pure - fun any( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> anySatisfyPredicate: Boolean - - /** - * Return how many values in the column satisfy the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result count The number of values in the column that satisfy the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.count(lambda cell: cell > 1) - * } - */ - @Pure - fun count( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> count: Int - - /** - * Return whether no value in the column satisfies the predicate. - * - * @param predicate The predicate to apply to each value. - * - * @result noneSatisfyPredicate Whether no value in the column satisfies the predicate. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.none(lambda cell: cell < 0) - * } - */ - @Pure - fun none( - predicate: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> noneSatisfyPredicate: Boolean - - /** - * Return a new column with a new name. - * - * The original column is not modified. - * - * @param newName The new name of the column. - * - * @result renamedColumn A new column with the new name. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.rename("new_name") - * } - */ - @Pure - fun rename( - @PythonName("new_name") newName: String - ) -> renamedColumn: ExperimentalColumn - - /** - * Return a new column with values transformed by the transformer. - * - * The original column is not modified. - * - * @param transformer The transformer to apply to each value. - * - * @result transformedColumn A new column with transformed values. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.transform(lambda cell: 2 * cell) - * } - */ - @Pure - fun transform( - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> transformedColumn: ExperimentalColumn - - /** - * Return a table with important statistics about the column. - * - * @result statistics The table with statistics. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("a", [1, 3]) - * // column.summarize_statistics() - * } - */ - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - - /** - * Calculate the Pearson correlation between this column and another column. - * - * The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly related: - * * A correlation of -1 indicates a perfect negative linear relationship. - * * A correlation of 0 indicates no linear relationship. - * * A correlation of 1 indicates a perfect positive linear relationship. - * - * @param other The other column to calculate the correlation with. - * - * @result correlation The Pearson correlation between the two columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column1 = ExperimentalColumn("test", [1, 2, 3]) - * // column2 = ExperimentalColumn("test", [2, 4, 6]) - * // column1.correlation_with(column2) - * } - */ - @Pure - @PythonName("correlation_with") - fun correlationWith( - other: ExperimentalColumn - ) -> correlation: Float - - /** - * Return the number of distinct values in the column. - * - * @result distinctValueCount The number of distinct values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3, 2]) - * // column.distinct_value_count() - * } - */ - @Pure - @PythonName("distinct_value_count") - fun distinctValueCount() -> distinctValueCount: Int - - /** - * Calculate the idness of this column. - * - * We define the idness as the number of distinct values divided by the number of rows. If the column is empty, - * the idness is 1.0. - * - * A high idness indicates that the column most values in the column are unique. In this case, you must be careful - * when using the column for analysis, as a model may learn a mapping from this column to the target. - * - * @result idness The idness of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column1 = ExperimentalColumn("test", [1, 2, 3]) - * // column1.idness() - * } - */ - @Pure - fun idness() -> idness: Float - - /** - * Return the maximum value in the column. - * - * @result max The maximum value in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.max() - * } - */ - @Pure - fun max() -> max: T - - /** - * Return the mean of the values in the column. - * - * The mean is the sum of the values divided by the number of values. - * - * @result mean The mean of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.mean() - * } - */ - @Pure - fun mean() -> mean: T - - /** - * Return the median of the values in the column. - * - * The median is the value in the middle of the sorted list of values. If the number of values is even, the median - * is the mean of the two middle values. - * - * @result median The median of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.median() - * } - */ - @Pure - fun median() -> median: T - - /** - * Return the minimum value in the column. - * - * @result min The minimum value in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.min() - * } - */ - @Pure - fun min() -> min: T - - /** - * Return the number of missing values in the column. - * - * @result missingValueCount The number of missing values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, None, 3]) - * // column.missing_value_count() - * } - */ - @Pure - @PythonName("missing_value_count") - fun missingValueCount() -> missingValueCount: Int - - /** - * Return the missing value ratio. - * - * We define the missing value ratio as the number of missing values in the column divided by the number of rows. - * If the column is empty, the missing value ratio is 1.0. - * - * A high missing value ratio indicates that the column is dominated by missing values. In this case, the column - * may not be useful for analysis. - * - * @result missingValueRatio The ratio of missing values in the column. - */ - @Pure - @PythonName("missing_value_ratio") - fun missingValueRatio() -> missingValueRatio: Float - - /** - * Return the mode of the values in the column. - * - * The mode is the value that appears most frequently in the column. If multiple values occur equally often, all - * of them are returned. The values are sorted in ascending order. - * - * @result mode The mode of the values in the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [3, 1, 2, 1, 3]) - * // column.mode() - * } - */ - @Pure - fun mode() -> mode: ExperimentalColumn - - /** - * Return the stability of the column. - * - * We define the stability as the number of occurrences of the most common non-missing value divided by the total - * number of non-missing values. If the column is empty or all values are missing, the stability is 1.0. - * - * A high stability indicates that the column is dominated by a single value. In this case, the column may not be - * useful for analysis. - * - * @result stability The stability of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 1, 2, 3, None]) - * // column.stability() - * } - */ - @Pure - fun stability() -> stability: Float - - /** - * Return the standard deviation of the values in the column. - * - * The standard deviation is the square root of the variance. - * - * @result standardDeviation The standard deviation of the values in the column. If no standard deviation can be calculated due to the - * type of the column, None is returned. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.standard_deviation() - * } - */ - @Pure - @PythonName("standard_deviation") - fun standardDeviation() -> standardDeviation: Float? - - /** - * Return the variance of the values in the column. - * - * The variance is the average of the squared differences from the mean. - * - * @result variance The variance of the values in the column. If no variance can be calculated due to the type of the column, - * None is returned. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.variance() - * } - */ - @Pure - fun variance() -> variance: Float? - - /** - * Return the values of the column in a list. - * - * @result values The values of the column in a list. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.to_list() - * } - */ - @Pure - @PythonName("to_list") - fun toList() -> values: List - - /** - * Create a table that contains only this column. - * - * @result table The table with this column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // column.to_table() - * } - */ - @Pure - @PythonName("to_table") - fun toTable() -> table: ExperimentalTable - - /** - * Convert the column to the old column format. This method is temporary and will be removed in a later version. - * - * @result oldColumn The column in the old format. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("a", [1, 2, 3]) - * // old_column = column.temporary_to_old_column() - * } - */ - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_column") - fun temporaryToOldColumn() -> oldColumn: Column -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalRow.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalRow.sdsstub deleted file mode 100644 index f93084895..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalRow.sdsstub +++ /dev/null @@ -1,64 +0,0 @@ -package safeds.data.tabular.containers - -from safeds.data.tabular.typing import ExperimentalDataType -from safeds.data.tabular.typing import ExperimentalSchema - -/** - * A one-dimensional collection of named, heterogeneous values. - * - * This class cannot be instantiated directly. It is only used for arguments of callbacks. - */ -@Experimental -class ExperimentalRow { - /** - * The names of the columns in the row. - */ - @PythonName("column_names") attr columnNames: List - /** - * The number of columns in the row. - */ - @PythonName("number_of_columns") attr numberOfColumns: Int - /** - * The schema of the row. - */ - attr ^schema: ExperimentalSchema - - /** - * Get the value of the specified column. - * - * @param name The name of the column. - * - * @result value The value of the column. - */ - @Pure - @PythonName("get_value") - fun getValue( - name: String - ) -> value: ExperimentalCell - - /** - * Get the type of the specified column. - * - * @param name The name of the column. - * - * @result type The type of the column. - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Check if the row has a column with the specified name. - * - * @param name The name of the column. - * - * @result hasColumn Whether the row has a column with the specified name. - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalTable.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalTable.sdsstub deleted file mode 100644 index 989df667f..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/ExperimentalTable.sdsstub +++ /dev/null @@ -1,950 +0,0 @@ -package safeds.data.tabular.containers - -from safeds.data.labeled.containers import ExperimentalTabularDataset -from safeds.data.tabular.containers import ExperimentalRow -from safeds.data.tabular.containers import Table -from safeds.data.tabular.plotting import ExperimentalTablePlotter -from safeds.data.tabular.transformation import ExperimentalInvertibleTableTransformer -from safeds.data.tabular.transformation import ExperimentalTableTransformer -from safeds.data.tabular.typing import ExperimentalDataType -from safeds.data.tabular.typing import ExperimentalSchema - -/** - * A two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. - * - * To create a `Table` call the constructor or use one of the following static methods: - * - * | Method | Description | - * | ------------------------------------------------------------------------------------| -------------------------------------- | - * | [fromCsvFile][safeds.data.tabular.containers.ExperimentalTable.fromCsvFile] | Create a table from a CSV file. | - * | [fromJsonFile][safeds.data.tabular.containers.ExperimentalTable.fromJsonFile] | Create a table from a JSON file. | - * | [fromParquetFile][safeds.data.tabular.containers.ExperimentalTable.fromParquetFile] | Create a table from a Parquet file. | - * | [fromColumns][safeds.data.tabular.containers.ExperimentalTable.fromColumns] | Create a table from a list of columns. | - * | [fromMap][safeds.data.tabular.containers.ExperimentalTable.fromMap] | Create a table from a dictionary. | - * - * @param data The data of the table. If None, an empty table is created. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * } - */ -@Experimental -class ExperimentalTable( - data: Map>? = null -) { - /** - * The names of the columns in the table. - */ - @PythonName("column_names") attr columnNames: List - /** - * The number of columns in the table. - */ - @PythonName("number_of_columns") attr numberOfColumns: Int - /** - * The number of rows in the table. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - */ - @PythonName("number_of_rows") attr numberOfRows: Int - /** - * The plotter for the table. - */ - attr plot: ExperimentalTablePlotter - /** - * The schema of the table. - */ - attr ^schema: ExperimentalSchema - - /** - * Create a table from a list of columns. - * - * @param columns The columns. - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // a = ExperimentalColumn("a", [1, 2, 3]) - * // b = ExperimentalColumn("b", [4, 5, 6]) - * // ExperimentalTable.from_columns([a, b]) - * } - */ - @Pure - @PythonName("from_columns") - static fun fromColumns( - columns: union, List>> - ) -> table: ExperimentalTable - - /** - * Create a table from a CSV file. - * - * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_csv_file("./src/resources/from_csv_file.csv") - * } - */ - @Pure - @PythonName("from_csv_file") - static fun fromCsvFile( - path: String - ) -> table: ExperimentalTable - - /** - * Create a table from a map of column names to column values. - * - * @param data The data. - * - * @result table The generated table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // data = {'a': [1, 2, 3], 'b': [4, 5, 6]} - * // ExperimentalTable.from_dict(data) - * } - */ - @Pure - @PythonName("from_dict") - static fun fromMap( - data: Map> - ) -> table: ExperimentalTable - - /** - * Create a table from a JSON file. - * - * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_json_file("./src/resources/from_json_file_2.json") - * } - */ - @Pure - @PythonName("from_json_file") - static fun fromJsonFile( - path: String - ) -> table: ExperimentalTable - - /** - * Create a table from a Parquet file. - * - * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". - * - * @result table The created table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // ExperimentalTable.from_parquet_file("./src/resources/from_parquet_file.parquet") - * } - */ - @Pure - @PythonName("from_parquet_file") - static fun fromParquetFile( - path: String - ) -> table: ExperimentalTable - - /** - * Return a new table with additional columns. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param columns The columns to add. - * - * @result newTable The table with the additional columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // new_column = ExperimentalColumn("b", [4, 5, 6]) - * // table.add_columns(new_column) - * } - */ - @Pure - @PythonName("add_columns") - fun addColumns( - columns: union, List>> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with an additional computed column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the new column. - * @param computer The function that computes the values of the new column. - * - * @result newTable The table with the computed column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.add_computed_column("c", lambda row: row.get_value("a") + row.get_value("b")) - * } - */ - @Pure - @PythonName("add_computed_column") - fun addComputedColumn( - name: String, - computer: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Get a column from the table. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - * - * @param name The name of the column. - * - * @result column The column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.get_column("a") - * } - */ - @Pure - @PythonName("get_column") - fun getColumn( - name: String - ) -> column: ExperimentalColumn - - /** - * Get the data type of a column. - * - * @param name The name of the column. - * - * @result type The data type of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.get_column_type("a") - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Check if the table has a column with a specific name. - * - * @param name The name of the column. - * - * @result hasColumn Whether the table has a column with the specified name. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.has_column("a") - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> hasColumn: Boolean - - /** - * Return a new table without the specified columns. - * - * **Note:** The original table is not modified. - * - * @param names The names of the columns to remove. - * - * @result newTable The table with the columns removed. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_columns("a") - * } - */ - @Pure - @PythonName("remove_columns") - fun removeColumns( - names: union, String> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with only the specified columns. - * - * @param names The names of the columns to keep. - * - * @result newTable The table with only the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_columns_except("a") - * } - */ - @Pure - @PythonName("remove_columns_except") - fun removeColumnsExcept( - names: union, String> - ) -> newTable: ExperimentalTable - - /** - * Return a new table without columns that contain missing values. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @result newTable The table without columns containing missing values. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, None]}) - * // table.remove_columns_with_missing_values() - * } - */ - @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> newTable: ExperimentalTable - - /** - * Return a new table without non-numeric columns. - * - * **Note:** The original table is not modified. - * - * @result newTable The table without non-numeric columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": ["4", "5", "6"]}) - * // table.remove_non_numeric_columns() - * } - */ - @Pure - @PythonName("remove_non_numeric_columns") - fun removeNonNumericColumns() -> newTable: ExperimentalTable - - /** - * Return a new table with a column renamed. - * - * **Note:** The original table is not modified. - * - * @param oldName The name of the column to rename. - * @param newName The new name of the column. - * - * @result newTable The table with the column renamed. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.rename_column("a", "c") - * } - */ - @Pure - @PythonName("rename_column") - fun renameColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_name") newName: String - ) -> newTable: ExperimentalTable - - /** - * Return a new table with a column replaced by zero or more columns. - * - * **Note:** The original table is not modified. - * - * @param oldName The name of the column to replace. - * @param newColumns The new column or columns. - * - * @result newTable The table with the column replaced. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn, ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.replace_column("a", []) - * } - */ - @Pure - @PythonName("replace_column") - fun replaceColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_columns") newColumns: union, List>> - ) -> newTable: ExperimentalTable - - /** - * Return a new table with a column transformed. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column to transform. - * @param transformer The function that transforms the column. - * - * @result newTable The table with the transformed column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.transform_column("a", lambda cell: cell + 1) - * } - */ - @Pure - @PythonName("transform_column") - fun transformColumn( - name: String, - transformer: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without duplicate rows. - * - * **Note:** The original table is not modified. - * - * @result newTable The table without duplicate rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 2], "b": [4, 5, 5]}) - * // table.remove_duplicate_rows() - * } - */ - @Pure - @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> newTable: ExperimentalTable - - /** - * Return a new table without rows that satisfy a condition. - * - * **Note:** The original table is not modified. - * - * @param query The function that determines which rows to remove. - * - * @result newTable The table without the specified rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_rows(lambda row: row.get_value("a") == 2) - * } - */ - @Pure - @PythonName("remove_rows") - fun removeRows( - query: (param1: ExperimentalRow) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows that satisfy a condition on a specific column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column. - * @param query The function that determines which rows to remove. - * - * @result newTable The table without the specified rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.remove_rows_by_column("a", lambda cell: cell == 2) - * } - */ - @Pure - @PythonName("remove_rows_by_column") - fun removeRowsByColumn( - name: String, - query: (param1: ExperimentalCell) -> result1: ExperimentalCell - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows containing missing values in the specified columns. - * - * **Note:** The original table is not modified. - * - * @param columnNames Names of the columns to consider. If None, all columns are considered. - * - * @result newTable The table without rows containing missing values in the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, None, 3], "b": [4, 5, None]}) - * // table.remove_rows_with_missing_values() - * } - */ - @Pure - @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues( - @PythonName("column_names") columnNames: List? = null - ) -> newTable: ExperimentalTable - - /** - * Return a new table without rows containing outliers in the specified columns. - * - * Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the - * data point from the mean of the column divided by the standard deviation of the column. If the z-score is - * greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the - * calculation of the z-score. - * - * The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in - * `column_names`. - * - * **Notes:** - * - * * The original table is not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param columnNames Names of the columns to consider. If None, all numeric columns are considered. - * @param zScoreThreshold The z-score threshold for detecting outliers. - * - * @result newTable The table without rows containing outliers in the specified columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5, 6, 1000, None], - * // "b": [1, 2, 3, 4, 5, 6, 7, 8], - * // } - * // ) - * // table.remove_rows_with_outliers(z_score_threshold=2) - * } - */ - @Pure - @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers( - @PythonName("column_names") columnNames: List? = null, - @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows shuffled. - * - * **Note:** The original table is not modified. - * - * @result newTable The table with the rows shuffled. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.shuffle_rows() - * } - */ - @Pure - @PythonName("shuffle_rows") - fun shuffleRows() -> newTable: ExperimentalTable - - /** - * Return a new table with a slice of rows. - * - * **Note:** The original table is not modified. - * - * @param start The start index of the slice. - * @param length The length of the slice. If None, the slice contains all rows starting from `start`. - * - * @result newTable The table with the slice of rows. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.slice_rows(start=1) - * } - */ - @Pure - @PythonName("slice_rows") - fun sliceRows( - start: Int = 0, - length: Int? = null - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows sorted. - * - * **Note:** The original table is not modified. - * - * @param keySelector The function that selects the key to sort by. - * @param descending Whether to sort in descending order. - * - * @result newTable The table with the rows sorted. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - * // table.sort_rows(lambda row: row.get_value("a") - row.get_value("b")) - * } - */ - @Pure - @PythonName("sort_rows") - fun sortRows( - @PythonName("key_selector") keySelector: (param1: ExperimentalRow) -> result1: ExperimentalCell, - descending: Boolean = false - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows sorted by a specific column. - * - * **Note:** The original table is not modified. - * - * @param name The name of the column to sort by. - * @param descending Whether to sort in descending order. - * - * @result newTable The table with the rows sorted by the specified column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [2, 1, 3], "b": [1, 1, 2]}) - * // table.sort_rows_by_column("a") - * } - */ - @Pure - @PythonName("sort_rows_by_column") - fun sortRowsByColumn( - name: String, - descending: Boolean = false - ) -> newTable: ExperimentalTable - - /** - * Create two tables by splitting the rows of the current table. - * - * The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table - * contains the remaining rows. - * - * **Note:** The original table is not modified. - * - * @param percentageInFirst The percentage of rows to include in the first table. Must be between 0 and 1. - * @param shuffle Whether to shuffle the rows before splitting. - * - * @result firstTable The first table. - * @result secondTable The second table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}) - * // first_table, second_table = table.split_rows(0.6) - * // first_table - * // second_table - * } - */ - @Pure - @PythonName("split_rows") - fun splitRows( - @PythonName("percentage_in_first") percentageInFirst: Float, - shuffle: Boolean = true - ) -> (firstTable: ExperimentalTable, secondTable: ExperimentalTable) - - /** - * Return a new table with the columns of another table added. - * - * **Notes:** - * - * * The original tables are not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param other The table to add as columns. - * - * @result newTable The table with the columns added. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table1 = ExperimentalTable({"a": [1, 2, 3]}) - * // table2 = ExperimentalTable({"b": [4, 5, 6]}) - * // table1.add_table_as_columns(table2) - * } - */ - @Pure - @PythonName("add_table_as_columns") - fun addTableAsColumns( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - - /** - * Return a new table with the rows of another table added. - * - * **Notes:** - * - * * The original tables are not modified. - * * This operation must fully load the data into memory, which can be expensive. - * - * @param other The table to add as rows. - * - * @result newTable The table with the rows added. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table1 = ExperimentalTable({"a": [1, 2, 3]}) - * // table2 = ExperimentalTable({"a": [4, 5, 6]}) - * // table1.add_table_as_rows(table2) - * } - */ - @Pure - @PythonName("add_table_as_rows") - fun addTableAsRows( - other: ExperimentalTable - ) -> newTable: ExperimentalTable - - /** - * Return a new table inverse-transformed by a **fitted, invertible** transformer. - * - * **Notes:** - * - * * The original table is not modified. - * * Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - * - * @param fittedTransformer The fitted, invertible transformer to apply. - * - * @result newTable The inverse-transformed table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // from safeds.data.tabular.transformation import ExperimentalRangeScaler - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // transformer, transformed_table = ExperimentalRangeScaler(min_=0, max_=1).fit_and_transform(table, ["a"]) - * // transformed_table.inverse_transform_table(transformer) - * } - */ - @Pure - @PythonName("inverse_transform_table") - fun inverseTransformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalInvertibleTableTransformer - ) -> newTable: ExperimentalTable - - /** - * Return a new table transformed by a **fitted** transformer. - * - * **Notes:** - * - * * The original table is not modified. - * * Depending on the transformer, this operation might fully load the data into memory, which can be expensive. - * - * @param fittedTransformer The fitted transformer to apply. - * - * @result newTable The transformed table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // from safeds.data.tabular.transformation import ExperimentalRangeScaler - * // table = ExperimentalTable({"a": [1, 2, 3]}) - * // transformer = ExperimentalRangeScaler(min_=0, max_=1).fit(table, ["a"]) - * // table.transform_table(transformer) - * } - */ - @Pure - @PythonName("transform_table") - fun transformTable( - @PythonName("fitted_transformer") fittedTransformer: ExperimentalTableTransformer - ) -> newTable: ExperimentalTable - - /** - * Return a table with important statistics about this table. - * - * @result statistics The table with statistics. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 3]}) - * // table.summarize_statistics() - * } - */ - @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: ExperimentalTable - - /** - * Return the data of the table as a list of columns. - * - * @result columns List of columns. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // columns = table.to_columns() - * } - */ - @Pure - @PythonName("to_columns") - fun toColumns() -> columns: List> - - /** - * Write the table to a CSV file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_csv_file("./src/resources/to_csv_file.csv") - * } - */ - @Pure - @PythonName("to_csv_file") - fun toCsvFile( - path: String - ) - - /** - * Return a map of column names to column values. - * - * @result map Dictionary representation of the table. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_dict() - * } - */ - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - - /** - * Write the table to a JSON file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * **Note:** This operation must fully load the data into memory, which can be expensive. - * - * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". - * @param orientation The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If - * "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but - * slower and less memory-efficient. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_json_file("./src/resources/to_json_file_2.json") - * } - */ - @Pure - @PythonName("to_json_file") - fun toJsonFile( - path: String, - orientation: literal<"column", "row"> = "column" - ) - - /** - * Write the table to a Parquet file. - * - * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it - * will be overwritten. - * - * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // table.to_parquet_file("./src/resources/to_parquet_file.parquet") - * } - */ - @Pure - @PythonName("to_parquet_file") - fun toParquetFile( - path: String - ) - - /** - * Return a new `TabularDataset` with columns marked as a target, feature, or extra. - * - * * The target column is the column that a model should predict. - * * Feature columns are columns that a model should use to make predictions. - * * Extra columns are columns that are neither feature nor target. They can be used to provide additional context, - * like an ID column. - * - * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns - * are specified, all columns except the target column are used as features. - * - * @param targetName Name of the target column. - * @param extraNames Names of the columns that are neither feature nor target. If None, no extra columns are used, i.e. all but - * the target column are used as features. - * - * @result dataset A new tabular dataset with the given target and feature names. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "item": ["apple", "milk", "beer"], - * // "price": [1.10, 1.19, 1.79], - * // "amount_bought": [74, 72, 51], - * // } - * // ) - * // dataset = table.to_tabular_dataset(target_name="amount_bought", extra_names=["item"]) - * } - */ - @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( - @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List? = null - ) -> dataset: ExperimentalTabularDataset - - /** - * Convert the table to the old table format. This method is temporary and will be removed in a later version. - * - * @result oldTable The table in the old format. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"a": [1, 2, 3], "b": [4, 5, 6]}) - * // old_table = table.temporary_to_old_table() - * } - */ - @Deprecated( - alternative="None.", - reason="Only a temporary solution until this implementation is stable.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("temporary_to_old_table") - fun temporaryToOldTable() -> oldTable: Table -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Row.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Row.sdsstub index 0798d2520..c4050fda7 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Row.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Row.sdsstub @@ -1,195 +1,63 @@ package safeds.data.tabular.containers -from safeds.data.tabular.typing import ColumnType, Schema +from safeds.data.tabular.typing import DataType +from safeds.data.tabular.typing import Schema /** - * A row is a collection of named values. + * A one-dimensional collection of named, heterogeneous values. * - * @param data The data. If None, an empty row is created. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * } + * This class cannot be instantiated directly. It is only used for arguments of callbacks. */ -@Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" -) -class Row( - data: Map? = null // TODO: update default value to empty map -) { +class Row { /** - * Return a list of all column names in the row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val columnNames = row.columnNames; // ["a", "b"] - * } + * The names of the columns in the row. */ @PythonName("column_names") attr columnNames: List /** - * Return the number of columns in this row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val numberOfColumns = row.numberOfColumns; // 2 - * } + * The number of columns in the row. */ - @PythonName("number_of_columns") attr numberOfColumns: Int + @PythonName("number_of_columns") attr columnCount: Int /** - * Return the schema of the row. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val ^schema = row.^schema; - * } + * The schema of the row. */ attr ^schema: Schema /** - * Create a row from a dictionary that maps column names to column values. - * - * @param data The data. - * - * @result row The created row. - * - * @example - * pipeline example { - * val row = Row.fromDict({"a": 1, "b": 2}); - * } - */ - @Pure - @PythonName("from_dict") - static fun fromDict( - data: Map - ) -> row: Row - - /** - * Return the value of a specified column. + * Get the value of the specified column. * - * @param columnName The column name. + * @param name The name of the column. * - * @result value The column value. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val value = row.getValue("a"); // 1 - * } + * @result value The value of the column. */ @Pure @PythonName("get_value") fun getValue( - @PythonName("column_name") columnName: String - ) -> value: Any - - /** - * Check whether the row contains a given column. - * - * @param columnName The column name. - * - * @result hasColumn True, if the row contains the column, False otherwise. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val hasColumn = row.hasColumn("a"); // True - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> hasColumn: Boolean + name: String + ) -> value: Cell /** - * Return the type of the specified column. + * Get the type of the specified column. * - * @param columnName The column name. + * @param name The name of the column. * * @result type The type of the column. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val type = row.getColumnType("a"); // Integer - * } */ @Pure @PythonName("get_column_type") fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType - - /** - * Sort the columns of a `Row` with the given comparator and return a new `Row`. - * - * The original row is not modified. The comparator is a function with four parameters: - * - * * `name_1` is the name of the first column. - * * `value_1` is the value of the first column. - * * `name_2` is the name of the second column. - * * `value_2` is the value of the second column. - * - * It should return an integer, indicating the desired order of the columns: - * - * * If `col1` should be ordered before `col2`, the function should return a negative number. - * * If `col1` should be ordered after `col2`, the function should return a positive number. - * * If the original order of `col1` and `col2` should be kept, the function should return 0. - * - * If no comparator is given, the columns will be sorted alphabetically by their name. - * - * @param comparator The function used to compare two tuples of (ColumnName, Value). - * - * @result sortedRow A new row with sorted columns. - * - * @example - * pipeline example { - * val row = Row({"b": 2, "a": 1}); - * val sortedRow = row.sortColumns((name1, value1, name2, value2) -> - * value1 as (Int) - value2 as (Int) - * ); - * } - */ - @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (name1: String, value1: Any, name2: String, value2: Any) -> comparison: Int - ) -> sortedRow: Row + name: String + ) -> type: DataType /** - * Return a map of column names to column values. + * Check if the row has a column with the specified name. * - * @result map Map representation of the row. + * @param name The name of the column. * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val map = row.toMap(); // {"a": 1, "b": 2} - * } + * @result hasColumn Whether the row has a column with the specified name. */ @Pure - @PythonName("to_dict") - fun toMap() -> map: Map - - /** - * Return an HTML representation of the row. - * - * @result html The generated HTML. - * - * @example - * pipeline example { - * val row = Row({"a": 1, "b": 2}); - * val html = row.toHtml(); - * } - */ - @Pure - @PythonName("to_html") - fun toHtml() -> html: String + @PythonName("has_column") + fun hasColumn( + name: String + ) -> hasColumn: Boolean } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Table.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Table.sdsstub index fa90270fc..cd76cd797 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Table.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/containers/Table.sdsstub @@ -1,141 +1,102 @@ package safeds.data.tabular.containers from safeds.data.labeled.containers import TabularDataset -from safeds.data.image.containers import Image -from safeds.data.tabular.containers import Column, Row -from safeds.data.tabular.transformation import InvertibleTableTransformer, TableTransformer -from safeds.data.tabular.typing import ColumnType, Schema +from safeds.data.labeled.containers import TimeSeriesDataset +from safeds.data.tabular.containers import Row +from safeds.data.tabular.plotting import TablePlotter +from safeds.data.tabular.transformation import InvertibleTableTransformer +from safeds.data.tabular.transformation import TableTransformer +from safeds.data.tabular.typing import DataType +from safeds.data.tabular.typing import Schema /** - * A table is a two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. + * A two-dimensional collection of data. It can either be seen as a list of rows or as a list of columns. * * To create a `Table` call the constructor or use one of the following static methods: * - * | Method | Description | - * | -------------------------- | -------------------------------------- | - * | {@link Table.fromCsvFile} | Create a table from a CSV file. | - * | {@link Table.fromJsonFile} | Create a table from a JSON file. | - * | {@link Table.fromMap} | Create a table from a map. | - * | {@link Table.fromColumns} | Create a table from a list of columns. | - * | {@link Table.fromRows} | Create a table from a list of rows. | + * | Method | Description | + * | ----------------------------------------------------------------------- | -------------------------------------- | + * | [fromCsvFile][safeds.data.tabular.containers.Table.fromCsvFile] | Create a table from a CSV file. | + * | [fromJsonFile][safeds.data.tabular.containers.Table.fromJsonFile] | Create a table from a JSON file. | + * | [fromParquetFile][safeds.data.tabular.containers.Table.fromParquetFile] | Create a table from a Parquet file. | + * | [fromColumns][safeds.data.tabular.containers.Table.fromColumns] | Create a table from a list of columns. | + * | [fromMap][safeds.data.tabular.containers.Table.fromMap] | Create a table from a map. | * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. - * - * @param data The data. If None, an empty table is created. + * @param data The data of the table. If null, an empty table is created. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); * } */ class Table( - data: Map>? = null // TODO: update default value to empty map + data: Map>? = null ) { /** - * Return a list of all column names in this table. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val columnNames = table.columnNames; // ["a", "b"] - * } + * The names of the columns in the table. */ @PythonName("column_names") attr columnNames: List /** - * Return the number of columns. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val numberOfColumns = table.numberOfColumns; // 2 - * } + * The number of columns in the table. */ - @PythonName("number_of_columns") attr numberOfColumns: Int + @PythonName("number_of_columns") attr columnCount: Int /** - * Return the number of rows. + * The number of rows in the table. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val numberOfRows = table.numberOfRows; // 2 - * } + * **Note:** This operation must fully load the data into memory, which can be expensive. */ - @PythonName("number_of_rows") attr numberOfRows: Int + @PythonName("number_of_rows") attr rowCount: Int /** - * Return the schema of the table. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val ^schema = table.^schema; - * } + * The plotter for the table. */ - attr ^schema: Schema - + attr plot: TablePlotter /** - * Read data from a CSV file into a table. - * - * @param path The path to the CSV file. - * - * @result table The table created from the CSV file. - * - * @example - * pipeline example { - * val table = Table.fromCsvFile("path/to/file.csv"); - * } + * The schema of the table. */ - @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_csv_file") - static fun fromCsvFile( - path: String - ) -> table: Table + attr ^schema: Schema /** - * Read data from an Excel file into a table. - * - * Valid file extensions are `.xls`, `.xlsx`, `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. + * Create a table from a list of columns. * - * @param path The path to the Excel file. + * @param columns The columns. * - * @result table The table created from the Excel file. + * @result table The created table. * * @example * pipeline example { - * val table = Table.fromExcelFile("path/to/file.xlsx"); + * val a = Column("a", [1, 2, 3]); + * val b = Column("b", [4, 5, 6]); + * val result = Table.fromColumns([a, b]); * } */ - @Deprecated( - alternative="Table.fromCsvFile", - reason="Requires a heavy depencency just for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_excel_file") - static fun fromExcelFile( - path: String + @Pure + @PythonName("from_columns") + static fun fromColumns( + columns: union> ) -> table: Table /** - * Read data from a JSON file into a table. + * Create a table from a CSV file. * - * @param path The path to the JSON file. + * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". + * @param separator The separator between the values in the CSV file. * - * @result table The table created from the JSON file. + * @result table The created table. * * @example * pipeline example { - * val table = Table.fromJsonFile("path/to/file.json"); + * val result = Table.fromCsvFile("input.csv"); * } */ @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) - @PythonName("from_json_file") - static fun fromJsonFile( - path: String + @PythonName("from_csv_file") + static fun fromCsvFile( + path: String, + separator: String = "," ) -> table: Table /** - * Create a table from a map of column names to column values. + * Create a table from a map that maps column names to column values. * * @param data The data. * @@ -143,964 +104,724 @@ class Table( * * @example * pipeline example { - * val table = Table.fromMap({"a": [1, 2], "b": [3, 4]}); + * val data = {"a'": [1, 2, 3], "b": [4, 5, 6]}; + * val result = Table.fromMap(data); * } */ @Pure @PythonName("from_dict") static fun fromMap( - data: Map> + data: Map> ) -> table: Table /** - * Return a table created from a list of columns. + * Create a table from a JSON file. * - * @param columns The columns to be combined. They need to have the same size. + * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". * - * @result table The generated table. + * @result table The created table. * * @example * pipeline example { - * val column1 = Column("a", [1, 2]); - * val column2 = Column("b", [3, 4]); - * val table = Table.fromColumns([column1, column2]); + * val result = Table.fromJsonFile("input.json"); * } */ - @Pure - @PythonName("from_columns") - static fun fromColumns( - columns: List + @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) + @PythonName("from_json_file") + static fun fromJsonFile( + path: String ) -> table: Table /** - * Return a table created from a list of rows. + * Create a table from a Parquet file. * - * @param rows The rows to be combined. They need to have a matching schema. + * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". * - * @result table The generated table. + * @result table The created table. * * @example * pipeline example { - * val row1 = Row({"a": 1, "b": 3}); - * val row2 = Row({"a": 2, "b": 4}); - * val table = Table.fromRows([row1, row2]); + * val result = Table.fromParquetFile("input.parquet"); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("from_rows") - static fun fromRows( - rows: List + @Impure([ImpurityReason.FileReadFromParameterizedPath("path")]) + @PythonName("from_parquet_file") + static fun fromParquetFile( + path: String ) -> table: Table /** - * Return a column with the data of the specified column. - * - * @param columnName The name of the column. + * Return a new table with additional columns. * - * @result column The column. + * **Notes:** * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = table.getColumn("a"); // Column("a", [1, 2]) - * } - */ - @Pure - @PythonName("get_column") - fun getColumn( - @PythonName("column_name") columnName: String - ) -> column: Column - - /** - * Return whether the table contains a given column. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @param columnName The name of the column. + * @param columns The columns to add. * - * @result hasColumn True if the column exists. + * @result newTable The table with the additional columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val hasColumn = table.hasColumn("a"); // true + * val table = Table({"a": [1, 2, 3]}); + * val newColumn = Column("b", [4, 5, 6]); + * val result = table.addColumns(newColumn); * } */ @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> hasColumn: Boolean + @PythonName("add_columns") + fun addColumns( + columns: union> + ) -> newTable: Table /** - * Return the type of the given column. + * Return a new table with an additional computed column. * - * @param columnName The name of the column to be queried. + * **Note:** The original table is not modified. * - * @result type The type of the column. + * @param name The name of the new column. + * @param computer The function that computes the values of the new column. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val type = table.getColumnType("a"); // Integer - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - @PythonName("column_name") columnName: String - ) -> type: ColumnType - - /** - * Return the row at a specified index. - * - * @param index The index. - * - * @result row The row of the table at the index. + * @result newTable The table with the computed column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val row = table.getRow(0); // Row({"a": 1, "b": 3}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.addComputedColumn("c", (row) -> row.getValue("a").add(row.getValue("b"))); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("get_row") - fun getRow( - index: Int - ) -> row: Row + @PythonName("add_computed_column") + fun addComputedColumn( + name: String, + computer: (row: Row) -> computedCell: Cell + ) -> newTable: Table /** - * Return a table with a number of statistical key values. + * Get a column from the table. * - * The original table is not modified. + * **Note:** This operation must fully load the data into memory, which can be expensive. * - * @result statistics The table with statistics. + * @param name The name of the column. + * + * @result column The column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val statistics = table.summarizeStatistics(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.getColumn("a"); + * // Column("a", [1, 2, 3]) * } */ @Pure - @PythonName("summarize_statistics") - fun summarizeStatistics() -> statistics: Table + @PythonName("get_column") + fun getColumn( + name: String + ) -> column: Column /** - * Return a new table with the provided column attached at the end. + * Get the data type of a column. * - * The original table is not modified. + * @param name The name of the column. * - * @result newTable The table with the column attached. + * @result type The data type of the column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = Column("c", [5, 6]); - * val newTable = table.addColumn(column); - * // Table({ - * // "a": [1, 2], - * // "b": [3, 4], - * // "c": [5, 6], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.getColumnType("a"); * } */ - @Deprecated( - alternative="Table.addColumns", - reason="No need for two methods.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("add_column") - fun addColumn( - column: Column - ) -> newTable: Table + @PythonName("get_column_type") + fun getColumnType( + name: String + ) -> type: DataType /** - * Return a new `Table` with multiple added columns. + * Check if the table has a column with a specific name. * - * The original table is not modified. + * @param name The name of the column. * - * @param columns The columns to be added. - * - * @result newTable A new table combining the original table and the given columns. + * @result hasColumn Whether the table has a column with the specified name. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column1 = Column("c", [5, 6]); - * val column2 = Column("d", [7, 8]); - * val newTable = table.addColumns([column1, column2]); - * // Table({ - * // "a": [1, 2], - * // "b": [3, 4], - * // "c": [5, 6], - * // "d": [7, 8], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.hasColumn("a"); // true * } */ @Pure - @PythonName("add_columns") - fun addColumns( - columns: union, Table> - ) -> newTable: Table + @PythonName("has_column") + fun hasColumn( + name: String + ) -> hasColumn: Boolean /** - * Return a new `Table` with an added Row attached. + * Return a new table without the specified columns. * - * If the table happens to be empty beforehand, respective columns will be added automatically. + * **Notes:** * - * The order of columns of the new row will be adjusted to the order of columns in the table. - * The new table will contain the merged schema. + * - The original table is not modified. + * - This method does not raise if a column does not exist. You can use it to ensure that the resulting table does + * not contain certain columns. * - * The original table is not modified. - * - * @param row The row to be added. + * @param names The names of the columns to remove. * - * @result newTable A new table with the added row at the end. + * @result newTable The table with the columns removed. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [4, 5]}); - * val row = Row({"a": 3, "b": 6}); - * val newTable = table.addRow(row); - * // Table({ - * // "a": [1, 2, 3], - * // "b": [4, 5, 6], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumns("a"); + * // Table({"b": [4, 5, 6]}) * } - */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("add_row") - fun addRow( - row: Row - ) -> newTable: Table - - /** - * Return a new `Table` with multiple added Rows attached. - * - * The order of columns of the new rows will be adjusted to the order of columns in the table. - * The new table will contain the merged schema. - * - * The original table is not modified. - * - * @param rows The rows to be added. - * - * @result newTable A new table which combines the original table and the given rows. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [5, 6]}); - * val row1 = Row({"a": 3, "b": 7}); - * val row2 = Row({"a": 4, "b": 8}); - * val newTable = table.addRows([row1, row2]); - * // Table({ - * // "a": [1, 2, 3, 4], - * // "b": [5, 6, 7, 8], - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumns("c"); + * // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("add_rows") - fun addRows( - rows: union, Table> + @PythonName("remove_columns") + fun removeColumns( + names: union, String> ) -> newTable: Table /** - * Return a new table with rows filtered by Callable (e.g. lambda function). + * Return a new table with only the specified columns. * - * The original table is not modified. - * - * @param query A Callable that is applied to all rows. + * @param names The names of the columns to keep. * - * @result filteredTable A table containing only the rows filtered by the query. + * @result newTable The table with only the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val filteredTable = table.filterRows((row) -> - * row.getValue("a") as (Int) > 1 - * ); - * // Table({"a": [2], "b": [4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeColumnsExcept("a"); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeRows", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("filter_rows") - fun filterRows( - query: (row: Row) -> matches: Boolean - ) -> filteredTable: Table + @PythonName("remove_columns_except") + fun removeColumnsExcept( + names: union, String> + ) -> newTable: Table /** - * Return a map with copies of the output tables as values and the keys from the key_selector. + * Return a new table without columns that contain missing values. * - * The original table is not modified. + * **Notes:** * - * @param keySelector A Callable that is applied to all rows and returns the key of the group. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @result tablesByKey A map containing the new tables as values and the selected keys as keys. + * @result newTable The table without columns containing missing values. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val tablesByKey = table.groupRows((row) -> - * row.getValue("a") as (Int) <= 2 - * ); - * // { - * // true: Table({"a": [1, 2], "b": [4, 5]}), - * // false: Table({"a": [3], "b": [6]}), - * // } + * val table = Table({"a": [1, 2, 3], "b": [4, 5, null]}); + * val result = table.removeColumnsWithMissingValues(); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="None.", - reason="We'll provide a new solution with a more useful and efficient result.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("group_rows") - fun groupRows( - @PythonName("key_selector") keySelector: (row: Row) -> key: T - ) -> tablesByKey: Map + @PythonName("remove_columns_with_missing_values") + fun removeColumnsWithMissingValues() -> newTable: Table /** - * Return a new table with only the given column(s). - * - * The original table is not modified. + * Return a new table without non-numeric columns. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * **Note:** The original table is not modified. * - * @param columnNames A list containing only the columns to be kept. - * - * @result projectedTable A table containing only the given column(s). + * @result newTable The table without non-numeric columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val projectedTable = table.keepOnlyColumns(["a"]); - * // Table({"a": [1, 2]}) + * val table = Table({"a": [1, 2, 3], "b": ["4", "5", "6"]}); + * val result = table.removeNonNumericColumns(); + * // Table({"a": [1, 2, 3]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeColumnsExcept", - reason="Users looked for a method with 'remove' in the name, so they missed this.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("keep_only_columns") - fun keepOnlyColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table + @PythonName("remove_non_numeric_columns") + fun removeNonNumericColumns() -> newTable: Table /** - * Return a new table without the given column(s). + * Return a new table with a column renamed. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * @param oldName The name of the column to rename. + * @param newName The new name of the column. * - * @param columnNames A list containing all columns to be dropped. - * - * @result projectedTable A table without the given columns. + * @result newTable The table with the column renamed. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val projectedTable = table.removeColumns(["a"]); - * // Table({"b": [3, 4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.renameColumn("a", "c"); + * // Table({"c": [1, 2, 3], "b": [4, 5, 6]}) * } */ @Pure - @PythonName("remove_columns") - fun removeColumns( - @PythonName("column_names") columnNames: List - ) -> projectedTable: Table + @PythonName("rename_column") + fun renameColumn( + @PythonName("old_name") oldName: String, + @PythonName("new_name") newName: String + ) -> newTable: Table /** - * Return a new table without the columns that contain missing values. + * Return a new table with a column replaced by zero or more columns. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * @param oldName The name of the column to replace. + * @param newColumns The new columns. * - * @result projectedTable A table without the columns that contain missing values. + * @result newTable The table with the column replaced. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val projectedTable = table.removeColumnsWithMissingValues(); - * // Table({"b": [3, 4]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.replaceColumn("a", []); + * // Table({"b": [4, 5, 6]}) * } */ @Pure - @PythonName("remove_columns_with_missing_values") - fun removeColumnsWithMissingValues() -> projectedTable: Table + @PythonName("replace_column") + fun replaceColumn( + @PythonName("old_name") oldName: String, + @PythonName("new_columns") newColumns: union, Table> + ) -> newTable: Table /** - * Return a new table without the columns that contain non-numerical values. + * Return a new table with a column transformed. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + * @param name The name of the column to transform. + * @param transformer The function that transforms the column. * - * @result projectedTable A table without the columns that contain non-numerical values. + * @result newTable The table with the transformed column. * * @example * pipeline example { - * val table = Table({"a": ["z", "y"], "b": [1, 2]}); - * val projectedTable = table.removeColumnsWithNonNumericalValues(); - * // Table({"b": [1, 2]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.transformColumn("a", (cell) -> cell.add(1)); + * // Table({"a": [2, 3, 4], "b": [4, 5, 6]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.removeNonNumericColumns", - reason="More concise name.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("remove_columns_with_non_numerical_values") - fun removeColumnsWithNonNumericalValues() -> projectedTable: Table + @PythonName("transform_column") + fun transformColumn( + name: String, + transformer: (cell: Cell) -> transformedCell: Cell + ) -> newTable: Table /** - * Return a new table with every duplicate row removed. + * Return a new table without duplicate rows. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result filteredTable The table with the duplicate rows removed. + * @result newTable The table without duplicate rows. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 1], "b": [3, 4, 3]}); - * val filteredTable = table.removeDuplicateRows(); - * // Table({"a": [1, 2], "b": [3, 4]}) + * val table = Table({"a": [1, 2, 2], "b": [4, 5, 5]}); + * val result = table.removeDuplicateRows(); + * // Table({"a": [1, 2], "b": [4, 5]}) * } */ @Pure @PythonName("remove_duplicate_rows") - fun removeDuplicateRows() -> filteredTable: Table + fun removeDuplicateRows() -> newTable: Table /** - * Return a new table without the rows that contain missing values. + * Return a new table without rows that satisfy a condition. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result filteredTable A table without the rows that contain missing values. + * @param query The function that determines which rows to remove. + * + * @result newTable The table without the specified rows. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val filteredTable = table.removeRowsWithMissingValues(); - * // Table({"a": [1], "b": [3]}) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeRows((row) -> row.getValue("a").eq(2)); + * // Table({"a": [1, 3], "b": [4, 6]}) * } */ @Pure - @PythonName("remove_rows_with_missing_values") - fun removeRowsWithMissingValues() -> filteredTable: Table + @PythonName("remove_rows") + fun removeRows( + query: (row: Row) -> shouldRemoveRow: Cell + ) -> newTable: Table /** - * Return a new table without those rows that contain at least one outlier. + * Return a new table without rows that satisfy a condition on a specific column. * - * We define an outlier as a value that has a distance of more than 3 standard deviations from the column mean. - * Missing values are not considered outliers. They are also ignored during the calculation of the standard - * deviation. + * **Note:** The original table is not modified. * - * The original table is not modified. + * @param name The name of the column. + * @param query The function that determines which rows to remove. * - * @result filteredTable A new table without rows containing outliers. + * @result newTable The table without the specified rows. * * @example * pipeline example { - * val table = Table({ - * "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - * "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3, 1000] - * }); - * val filteredTable = table.removeRowsWithOutliers(); - * // Table({ - * // "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - * // "b": [0, 0.1, -0.1, 0.2, 0, 0.1, 0, -0.3, 0, 0.3] - * // }) + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.removeRowsByColumn("a", (cell) -> cell.eq(2)); + * // Table({"a": [1, 3], "b": [4, 6]}) * } */ @Pure - @PythonName("remove_rows_with_outliers") - fun removeRowsWithOutliers() -> filteredTable: Table + @PythonName("remove_rows_by_column") + fun removeRowsByColumn( + name: String, + query: (cell: Cell) -> shouldRemoveRow: Cell + ) -> newTable: Table /** - * Return a new `Table` with a single column renamed. + * Return a new table without rows containing missing values in the specified columns. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param oldName The old name of the target column. - * @param newName The new name of the target column. + * @param columnNames Names of the columns to consider. If null, all columns are considered. * - * @result newTable The Table with the renamed column. + * @result newTable The table without rows containing missing values in the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val newTable = table.renameColumn("a", "c"); - * // Table({"c": [1, 2], "b": [3, 4]}) + * val table = Table({"a": [1, null, 3], "b": [4, 5, null]}); + * val result = table.removeRowsWithMissingValues(); + * // Table({"a": [1], "b": [4]}) * } */ @Pure - @PythonName("rename_column") - fun renameColumn( - @PythonName("old_name") oldName: String, - @PythonName("new_name") newName: String + @PythonName("remove_rows_with_missing_values") + fun removeRowsWithMissingValues( + @PythonName("column_names") columnNames: List? = null ) -> newTable: Table /** - * Return a new table with the specified old column replaced by a list of new columns. + * Return a new table without rows containing outliers in the specified columns. * - * The order of columns is kept. + * Whether a data point is an outlier in a column is determined by its z-score. The z-score the distance of the + * data point from the mean of the column divided by the standard deviation of the column. If the z-score is + * greater than the given threshold, the data point is considered an outlier. Missing values are ignored during the + * calculation of the z-score. * - * The original table is not modified. + * The z-score is only defined for numeric columns. Non-numeric columns are ignored, even if they are specified in + * `column_names`. * - * @param oldColumnName The name of the column to be replaced. - * @param newColumns The list of new columns replacing the old column. + * **Notes:** * - * @result newTable A table with the old column replaced by the new columns. + * - The original table is not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column = Column("c", [5, 6]); - * val newTable = table.replaceColumn("a", [column]); - * // Table({"c": [5, 6], "b": [3, 4]}) - * } + * @param columnNames Names of the columns to consider. If null, all numeric columns are considered. + * @param zScoreThreshold The z-score threshold for detecting outliers. + * + * @result newTable The table without rows containing outliers in the specified columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val column1 = Column("c", [5, 6]); - * val column2 = Column("d", [7, 8]); - * val newTable = table.replaceColumn("a", [column1, column2]); - * // Table({"c": [5, 6], "d": [7, 8], "b": [3, 4]}) + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5, 6, 1000, null], + * "b": [1, 2, 3, 4, 5, 6, 7, 8], + * } + * ); + * val result = table.removeRowsWithOutliers(zScoreThreshold=2.0); + * // Table({"a": [1, 2, 3, 4, 5, 6, null], "b": [1, 2, 3, 4, 5, 6]}) * } */ @Pure - @PythonName("replace_column") - fun replaceColumn( - @PythonName("old_column_name") oldColumnName: String, - @PythonName("new_columns") newColumns: List + @PythonName("remove_rows_with_outliers") + fun removeRowsWithOutliers( + @PythonName("column_names") columnNames: List? = null, + @PythonName("z_score_threshold") zScoreThreshold: Float = 3.0 ) -> newTable: Table /** - * Return a new `Table` with randomly shuffled rows of this `Table`. + * Return a new table with the rows shuffled. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @result shuffledTable The shuffled Table. + * @result newTable The table with the rows shuffled. * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val shuffledTable = table.shuffleRows(); + * val result = table.shuffleRows(); + * // Table({"a": [3, 2, 1], "b": [6, 5, 4]}) * } */ @Pure @PythonName("shuffle_rows") - fun shuffleRows() -> shuffledTable: Table + fun shuffleRows() -> newTable: Table /** - * Slice a part of the table into a new table. + * Return a new table with a slice of rows. * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param start The first index of the range to be copied into a new table, None by default. - * @param end The last index of the range to be copied into a new table, None by default. - * @param step The step size used to iterate through the table, 1 by default. + * @param start The start index of the slice. + * @param length The length of the slice. If null, the slice contains all rows starting from `start`. Must greater than or + * equal to 0. * - * @result slicedTable The resulting table. + * @result newTable The table with the slice of rows. * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(start = 1); + * val result = table.sliceRows(start=1); * // Table({"a": [2, 3], "b": [5, 6]}) * } * * @example * pipeline example { * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(end = 2); - * // Table({"a": [1, 2], "b": [4, 5]}) - * } - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); - * val slicedTable = table.sliceRows(step = 2); - * // Table({"a": [1, 3], "b": [4, 6]}) + * val result = table.sliceRows(start=1, length=1); + * // Table({"a": [2], "b": [5]}) * } */ @Pure @PythonName("slice_rows") fun sliceRows( - start: Int? = null, - end: Int? = null, - step: Int = 1 - ) -> slicedTable: Table + start: Int = 0, + length: Int? = null + ) -> newTable: Table /** - * Sort the columns of a `Table` with the given comparator and return a new `Table`. - * - * The comparator is a function that takes two columns `col1` and `col2` and - * returns an integer: - * - * * If `col1` should be ordered before `col2`, the function should return a negative number. - * * If `col1` should be ordered after `col2`, the function should return a positive number. - * * If the original order of `col1` and `col2` should be kept, the function should return 0. + * Return a new table with the rows sorted. * - * If no comparator is given, the columns will be sorted alphabetically by their name. - * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param comparator The function used to compare two columns. + * @param keySelector The function that selects the key to sort by. + * @param descending Whether to sort in descending order. * - * @result sortedTable A new table with sorted columns. + * @result newTable The table with the rows sorted. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortColumns((col1, col2) -> 1); - * // Table({"a": [1, 2], "b": [3, 4]}) - * } - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortColumns((col1, col2) -> -1); - * // Table({"b": [3, 4], "a": [1, 2]}) + * val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + * val result = table.sortRows((row) -> row.getValue("a").^sub(row.getValue("b"))); + * // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) * } */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("sort_columns") - fun sortColumns( - comparator: (column1: Column, column2: Column) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows") + fun sortRows( + @PythonName("key_selector") keySelector: (row: Row) -> key: Cell, + descending: Boolean = false + ) -> newTable: Table /** - * Sort the rows of a `Table` with the given comparator and return a new `Table`. - * - * The comparator is a function that takes two rows `row1` and `row2` and - * returns an integer: + * Return a new table with the rows sorted by a specific column. * - * * If `row1` should be ordered before `row2`, the function should return a negative number. - * * If `row1` should be ordered after `row2`, the function should return a positive number. - * * If the original order of `row1` and `row2` should be kept, the function should return 0. - * - * The original table is not modified. + * **Note:** The original table is not modified. * - * @param comparator The function used to compare two rows. + * @param name The name of the column to sort by. + * @param descending Whether to sort in descending order. * - * @result sortedTable A new table with sorted rows. + * @result newTable The table with the rows sorted by the specified column. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortRows((row1, row2) -> 1); - * // Table({"a": [1, 2], "b": [3, 4]}) - * } - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val sortedTable = table.sortRows((row1, row2) -> -1); - * // Table({"a": [2, 1], "b": [4, 3]}) + * val table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}); + * val result = table.sortRowsByColumn("a"); + * // Table({"a": [1, 2, 3], "b": [1, 1, 2]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.sortRows", - reason="Selecting a key is more ergonomic than a comparator.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("sort_rows") - fun sortRows( - comparator: (row1: Row, row2: Row) -> comparison: Int - ) -> sortedTable: Table + @PythonName("sort_rows_by_column") + fun sortRowsByColumn( + name: String, + descending: Boolean = false + ) -> newTable: Table /** - * Split the table into two new tables. Consider using {@link Table.shuffleRows} before splitting to ensure a random - * distribution of rows in both tables. + * Create two tables by splitting the rows of the current table. * - * The original table is not modified. + * The first table contains a percentage of the rows specified by `percentage_in_first`, and the second table + * contains the remaining rows. * - * @param ratioInFirst - * How many rows should be in the first table, expressed as a ratio of the total number of rows. Must be between 0 - * and 1. + * **Notes:** * - * @result first The first table with the specified size. - * @result second The second table with the remaining rows. + * - The original table is not modified. + * - By default, the rows are shuffled before splitting. You can disable this by setting `shuffle` to false. + * + * @param percentageInFirst The percentage of rows to include in the first table. Must be between 0 and 1. + * @param shuffle Whether to shuffle the rows before splitting. + * + * @result firstTable The first table. + * @result secondTable The second table. * * @example * pipeline example { - * val table = Table({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}); - * val first, val second = table.splitRows(0.5); - * // first: Table({"a": [1, 2], "b": [5, 6]}) - * // second: Table({"a": [3, 4], "b": [7, 8]}) + * val table = Table({"a": [1, 2, 3, 4, 5], "b": [6, 7, 8, 9, 10]}); + * val firstTable, val secondTable = table.splitRows(0.6); * } */ @Pure @PythonName("split_rows") fun splitRows( - @PythonName("percentage_in_first") ratioInFirst: Float - ) -> (first: Table, second: Table) + @PythonName("percentage_in_first") percentageInFirst: Float, + shuffle: Boolean = true + ) -> (firstTable: Table, secondTable: Table) /** - * Return a new `Table` with the provided column transformed by calling the provided transformer. + * Return a new table with the columns of another table added. * - * The original table is not modified. + * **Notes:** * - * @result transformedTable The table with the transformed column. + * - The original tables are not modified. + * - This operation must fully load the data into memory, which can be expensive. + * + * @param other The table to add as columns. + * + * @result newTable The table with the columns added. * * @example * pipeline example { - * val prices = Table({ - * "product": ["apple", "banana", "cherry"], - * "price": [ 100, 2, 4], - * }); - * val discountedPrices = prices.transformColumn("price", (row) -> - * row.getValue("price") as (Int) * 0.5 - * ); - * // Table({ - * // "product": ["apple", "banana", "cherry"], - * // "price": [ 50, 1, 2], - * // }) + * val table1 = Table({"a": [1, 2, 3]}); + * val table2 = Table({"b": [4, 5, 6]}); + * val result = table1.addTableAsColumns(table2); + * // Table({"a": [1, 2, 3], "b": [4, 5, 6]}) * } */ @Pure - @PythonName("transform_column") - fun transformColumn( - name: String, - transformer: (row: Row) -> newColumnValue: Any? - ) -> transformedTable: Table + @PythonName("add_table_as_columns") + fun addTableAsColumns( + other: Table + ) -> newTable: Table /** - * Return a new `Table` with a learned transformation applied to this table. + * Return a new table with the rows of another table added. * - * The original table is not modified. + * **Notes:** * - * @param transformer The transformer which transforms the given table. + * - The original tables are not modified. + * - This operation must fully load the data into memory, which can be expensive. * - * @result transformedTable The transformed table. + * @param other The table to add as rows. + * + * @result newTable The table with the rows added. * * @example * pipeline example { - * val table = Table({"a": [1, null], "b": [3, 4]}); - * val imputer = Imputer(Imputer.Strategy.Mean).fit(table, ["a"]); - * val transformedTable = table.transformTable(imputer); - * // Table({"a": [1, 1], "b": [3, 4]}) + * val table1 = Table({"a": [1, 2, 3]}); + * val table2 = Table({"a": [4, 5, 6]}); + * val result = table1.addTableAsRows(table2); + * // Table({"a": [1, 2, 3, 4, 5, 6]}) * } */ @Pure - @PythonName("transform_table") - fun transformTable( - transformer: TableTransformer - ) -> transformedTable: Table + @PythonName("add_table_as_rows") + fun addTableAsRows( + other: Table + ) -> newTable: Table /** - * Return a new `Table` with the inverted transformation applied by the given transformer. + * Return a new table inverse-transformed by a **fitted, invertible** transformer. * - * The original table is not modified. + * **Notes:** * - * @param transformer A transformer that was fitted with columns, which are all present in the table. + * - The original table is not modified. + * - Depending on the transformer, this operation might fully load the data into memory, which can be expensive. * - * @result originalTable The original table. + * @param fittedTransformer The fitted, invertible transformer to apply. + * + * @result newTable The inverse-transformed table. * * @example * pipeline example { - * val table = Table({"a": ["z", "y"], "b": [3, 4]}); - * val encoder = LabelEncoder().fit(table, ["a"]); - * val transformedTable = table.transformTable(encoder); - * val originalTable = transformedTable.inverseTransformTable(encoder); - * // Table({"a": ["z", "y"], "b": [3, 4]}) + * val table = Table({"a": [1, 2, 3]}); + * val transformer, val transformedTable = RangeScaler(min=0.0, max=1.0).fitAndTransform(table, ["a"]); + * val result = transformedTable.inverseTransformTable(transformer); + * // Table({"a": [1, 2, 3]}) * } */ @Pure @PythonName("inverse_transform_table") fun inverseTransformTable( - transformer: InvertibleTableTransformer - ) -> originalTable: Table - - /** - * Plot a correlation heatmap for all numerical columns of this `Table`. - * - * @result correlationHeatmap The plot as an image. - * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val correlationHeatmap = table.plotCorrelationHeatmap(); - * } - */ - @Deprecated( - alternative="Try ExperimentalTable.plot.correlationHeatmap instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_correlation_heatmap") - fun plotCorrelationHeatmap() -> correlationHeatmap: Image + @PythonName("fitted_transformer") fittedTransformer: InvertibleTableTransformer + ) -> newTable: Table /** - * Plot two columns against each other in a lineplot. - * - * If there are multiple x-values for a y-value, the resulting plot will consist of a line representing the mean - * and the lower-transparency area around the line representing the 95% confidence interval. - * - * @param xColumnName The column name of the column to be plotted on the x-Axis. - * @param yColumnName The column name of the column to be plotted on the y-Axis. + * Return a new table transformed by a **fitted** transformer. * - * @result lineplot The plot as an image. + * **Notes:** * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val lineplot = table.plotLineplot("a", "b"); - * } - */ - @Deprecated( - alternative="Try ExperimentalTable.plot.lineplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) - @Pure - @PythonName("plot_lineplot") - fun plotLineplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> lineplot: Image - - /** - * Plot two columns against each other in a scatterplot. + * - The original table is not modified. + * - Depending on the transformer, this operation might fully load the data into memory, which can be expensive. * - * @param xColumnName The column name of the column to be plotted on the x-Axis. - * @param yColumnName The column name of the column to be plotted on the y-Axis. + * @param fittedTransformer The fitted transformer to apply. * - * @result scatterplot The plot as an image. + * @result newTable The transformed table. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val scatterplot = table.plotScatterplot("a", "b"); + * val table = Table({"a": [1, 2, 3]}); + * val transformer = RangeScaler(min=0.0, max=1.0).fit(table, ["a"]); + * val result = table.transformTable(transformer); + * // Table({"a": [0, 0.5, 1]}) * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.scatterplot instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_scatterplot") - fun plotScatterplot( - @PythonName("x_column_name") xColumnName: String, - @PythonName("y_column_name") yColumnName: String - ) -> scatterplot: Image + @PythonName("transform_table") + fun transformTable( + @PythonName("fitted_transformer") fittedTransformer: TableTransformer + ) -> newTable: Table /** - * Plot a boxplot for every numerical column. + * Return a table with important statistics about this table. * - * @result boxplots The plot as an image. + * @result statistics The table with statistics. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val boxplots = table.plotBoxplots(); + * val table = Table({"a": [1, 3]}); + * val result = table.summarizeStatistics(); * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.boxplots instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_boxplots") - fun plotBoxplots() -> boxplots: Image + @PythonName("summarize_statistics") + fun summarizeStatistics() -> statistics: Table /** - * Plot a histogram for every column. + * Return the data of the table as a list of columns. * - * @param numberOfBins The number of bins to use in the histogram. - * - * @result histograms The plot as an image. + * @result columns List of columns. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val histograms = table.plotHistograms(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val columns = table.toColumns(); * } */ - @Deprecated( - alternative="Try ExperimentalTable.plot.histograms instead.", - reason="Groups all plotting methods in one place.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("plot_histograms") - fun plotHistograms( - @PythonName("number_of_bins") const numberOfBins: Int = 10 - ) -> histograms: Image where { - numberOfBins > 0 - } + @PythonName("to_columns") + fun toColumns() -> columns: List /** - * Write the data from the table into a CSV file. + * Write the table to a CSV file. * - * If the file and/or the directories do not exist they will be created. If the file already exists it will be - * overwritten. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @param path The path to the output file. + * @param path The path to the CSV file. If the file extension is omitted, it is assumed to be ".csv". * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toCsvFile("path/to/file.csv"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toCsvFile("output.csv"); * } */ @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) @@ -1110,158 +831,132 @@ class Table( ) /** - * Write the data from the table into an Excel file. + * Return a map that maps column names to column values. * - * Valid file extensions are `.xls`, '.xlsx', `.xlsm`, `.xlsb`, `.odf`, `.ods` and `.odt`. - * If the file and/or the directories do not exist, they will be created. If the file already exists, it will be - * overwritten. - * - * @param path The path to the output file. + * @result map Map representation of the table. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toExcelFile("path/to/file.xlsx"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * val result = table.toMap(); + * // {"a": [1, 2, 3], "b": [4, 5, 6]} * } */ - @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) - @PythonName("to_excel_file") - fun toExcelFile( - path: String - ) + @Pure + @PythonName("to_dict") + fun toMap() -> map: Map> /** - * Write the data from the table into a JSON file. + * Write the table to a JSON file. * - * If the file and/or the directories do not exist, they will be created. If the file already exists it will be - * overwritten. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @param path The path to the output file. + * **Note:** This operation must fully load the data into memory, which can be expensive. + * + * @param path The path to the JSON file. If the file extension is omitted, it is assumed to be ".json". + * @param orientation The orientation of the JSON file. If "column", the JSON file will be structured as a list of columns. If + * "row", the JSON file will be structured as a list of rows. Row orientation is more human-readable, but + * slower and less memory-efficient. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * table.toJsonFile("path/to/file.json"); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toJsonFile("output.json"); * } */ @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) @PythonName("to_json_file") fun toJsonFile( - path: String + path: String, + orientation: literal<"column", "row"> = "column" ) /** - * Return a map of column names to column values. - * - * @result map Map representation of the table. + * Write the table to a Parquet file. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val map = table.toMap(); - * // {"a": [1, 2], "b": [3, 4]} - * } - */ - @Pure - @PythonName("to_dict") - fun toMap() -> map: Map> - - /** - * Return an HTML representation of the table. + * If the file and/or the parent directories do not exist, they will be created. If the file exists already, it + * will be overwritten. * - * @result html The generated HTML. + * @param path The path to the Parquet file. If the file extension is omitted, it is assumed to be ".parquet". * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val html = table.toHtml(); + * val table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}); + * table.toParquetFile("output.parquet"); * } */ - @Deprecated( - alternative="None.", - reason="No use case.", - sinceVersion="0.15.0", - removalVersion="0.16.0" + @Impure([ImpurityReason.FileWriteToParameterizedPath("path")]) + @PythonName("to_parquet_file") + fun toParquetFile( + path: String ) - @Pure - @PythonName("to_html") - fun toHtml() -> html: String /** - * Return a list of the columns. + * Return a new `TabularDataset` with columns marked as a target, feature, or extra. * - * @result columns List of columns. + * - The target column is the column that a model should predict. + * - Feature columns are columns that a model should use to make predictions. + * - Extra columns are columns that are neither feature nor target. They can be used to provide additional context, + * like an ID column. * - * @example - * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val columns = table.toColumns(); - * // [Column("a", [1, 2]), Column("b", [3, 4])] - * } - */ - @Pure - @PythonName("to_columns") - fun toColumns() -> columns: List - - /** - * Return a list of the rows. + * Feature columns are implicitly defined as all columns except the target and extra columns. If no extra columns + * are specified, all columns except the target column are used as features. + * + * @param targetName Name of the target column. + * @param extraNames Names of the columns that are neither feature nor target. If null, no extra columns are used, i.e. all but + * the target column are used as features. * - * @result rows List of rows. + * @result dataset A new tabular dataset with the given target and feature names. * * @example * pipeline example { - * val table = Table({"a": [1, 2], "b": [3, 4]}); - * val rows = table.toRows(); - * // [Row({"a": 1, "b": 3}), Row({"a": 2, "b": 4})] + * val table = Table( + * { + * "item": ["apple", "milk", "beer"], + * "price": [1.10, 1.19, 1.79], + * "amount_bought": [74, 72, 51], + * } + * ); + * val dataset = table.toTabularDataset(targetName="amount_bought", extraNames=["item"]); * } */ - @Deprecated( - alternative="None.", - reason="This interface cannot be implemented efficiently.", - sinceVersion="0.15.0", - removalVersion="0.16.0" - ) @Pure - @PythonName("to_rows") - fun toRows() -> rows: List + @PythonName("to_tabular_dataset") + fun toTabularDataset( + @PythonName("target_name") targetName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TabularDataset /** - * Return a new `TabularDataset` with columns marked as a target column or feature columns. + * Return a new `TimeSeriesDataset` with columns marked as a target column, time or feature columns. * * The original table is not modified. * - * @param targetName - * Name of the target column. - * - * @param extraNames - * Names of the columns that are neither features nor target. If None, no extra columns are used, i.e. all but the - * target column are used as features. - * - * @result dataset A new tabular dataset with the given target and extras. + * @param targetName Name of the target column. + * @param timeName Name of the time column. + * @param extraNames Names of the columns that are neither features nor target. If null, no extra columns are used, i.e. all but + * the target column are used as features. * - * @example - * pipeline example { - * val table = Table({ - * "age": [23, 16], - * "survived": [ 0, 1], - * }); - * val dataset = table.toTabularDataset("survived"); - * } + * @result dataset A new time series dataset with the given target and feature names. * * @example * pipeline example { - * val table = Table({ - * "id": [ 1, 2], - * "age": [23, 16], - * "survived": [ 0, 1], - * }); - * val dataset = table.toTabularDataset("target", extraNames = ["id"]); + * val table = Table( + * { + * "day": [0, 1, 2], + * "price": [1.10, 1.19, 1.79], + * "amount_bought": [74, 72, 51], + * } + * ); + * val dataset = table.toTimeSeriesDataset(targetName="amount_bought", timeName= "day"); * } */ @Pure - @PythonName("to_tabular_dataset") - fun toTabularDataset( + @PythonName("to_time_series_dataset") + fun toTimeSeriesDataset( @PythonName("target_name") targetName: String, - @PythonName("extra_names") extraNames: List = [] - ) -> dataset: TabularDataset + @PythonName("time_name") timeName: String, + @PythonName("extra_names") extraNames: List? = null + ) -> dataset: TimeSeriesDataset } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ColumnPlotter.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ColumnPlotter.sdsstub new file mode 100644 index 000000000..3730aaa79 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ColumnPlotter.sdsstub @@ -0,0 +1,72 @@ +package safeds.data.tabular.plotting + +from safeds.data.image.containers import Image + +/** + * A class that contains plotting methods for a column. + * + * @param column The column to plot. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3]); + * val plotter = column.plot; + * } + */ +class ColumnPlotter( + column: Column +) { + /** + * Create a box plot for the values in the column. This is only possible for numeric columns. + * + * @result plot The box plot as an image. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3]); + * val boxplot = column.plot.boxPlot(); + * } + */ + @Pure + @PythonName("box_plot") + fun boxPlot() -> plot: Image + + /** + * Create a histogram for the values in the column. + * + * @param maxBinCount The maximum number of bins to use in the histogram. Default is 10. + * + * @result plot The plot as an image. + * + * @example + * pipeline example { + * val column = Column("test", [1, 2, 3]); + * val histogram = column.plot.histogram(); + * } + */ + @Pure + fun histogram( + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } + + /** + * Create a lag plot for the values in the column. + * + * @param lag The amount of lag. + * + * @result plot The plot as an image. + * + * @example + * pipeline example { + * val column = Column("values", [1, 2, 3, 4]); + * val image = column.plot.lagPlot(2); + * } + */ + @Pure + @PythonName("lag_plot") + fun lagPlot( + lag: Int + ) -> plot: Image +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalColumnPlotter.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalColumnPlotter.sdsstub deleted file mode 100644 index a0eaa7e44..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalColumnPlotter.sdsstub +++ /dev/null @@ -1,75 +0,0 @@ -package safeds.data.tabular.plotting - -from safeds.data.image.containers import Image - -/** - * A class that contains plotting methods for a column. - * - * @param column The column to plot. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // plotter = column.plot - * } - */ -@Experimental -class ExperimentalColumnPlotter( - column: ExperimentalColumn -) { - /** - * Create a box plot for the values in the column. This is only possible for numeric columns. - * - * @result boxPlot The box plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // boxplot = column.plot.box_plot() - * } - */ - @Pure - @PythonName("box_plot") - fun boxPlot() -> boxPlot: Image - - /** - * Create a histogram for the values in the column. - * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. - * - * @result histogram The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("test", [1, 2, 3]) - * // histogram = column.plot.histogram() - * } - */ - @Pure - fun histogram( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> histogram: Image - - /** - * Create a lag plot for the values in the column. - * - * @param lag The amount of lag. - * - * @result lagPlot The plot as an image. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalColumn - * // column = ExperimentalColumn("values", [1, 2, 3, 4]) - * // image = column.plot.lag_plot(2) - * } - */ - @Pure - @PythonName("lag_plot") - fun lagPlot( - lag: Int - ) -> lagPlot: Image -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalTablePlotter.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/TablePlotter.sdsstub similarity index 53% rename from packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalTablePlotter.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/TablePlotter.sdsstub index d443f441c..1b205aafd 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/ExperimentalTablePlotter.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/plotting/TablePlotter.sdsstub @@ -1,7 +1,7 @@ package safeds.data.tabular.plotting from safeds.data.image.containers import Image -from safeds.data.tabular.containers import ExperimentalTable +from safeds.data.tabular.containers import Table /** * A class that contains plotting methods for a table. @@ -10,13 +10,12 @@ from safeds.data.tabular.containers import ExperimentalTable * * @example * pipeline example { - * val table = ExperimentalTable({"test": [1, 2, 3]}); + * val table = Table({"test": [1, 2, 3]}); * val plotter = table.plot; * } */ -@Experimental -class ExperimentalTablePlotter( - table: ExperimentalTable +class TablePlotter( + table: Table ) { /** * Plot a boxplot for every numerical column. @@ -25,9 +24,8 @@ class ExperimentalTablePlotter( * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table({"a":[1, 2], "b": [3, 42]}) - * // image = table.plot_boxplots() + * val table = Table({"a":[1, 2], "b": [3, 42]}); + * val image = table.plot.boxPlots(); * } */ @Pure @@ -41,9 +39,8 @@ class ExperimentalTablePlotter( * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table.from_dict({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}) - * // image = table.plot_correlation_heatmap() + * val table = Table({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}); + * val image = table.plot.correlationHeatmap(); * } */ @Pure @@ -53,21 +50,22 @@ class ExperimentalTablePlotter( /** * Plot a histogram for every column. * - * @param numberOfBins The number of bins to use in the histogram. Default is 10. + * @param maxBinCount The maximum number of bins to use in the histogram. Default is 10. * * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import Table - * // table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}) - * // image = table.plot_histograms() + * val table = Table({"a": [2, 3, 5, 1], "b": [54, 74, 90, 2014]}); + * val image = table.plot.histograms(); * } */ @Pure fun histograms( - @PythonName("number_of_bins") numberOfBins: Int = 10 - ) -> plot: Image + @PythonName("maximum_number_of_bins") const maxBinCount: Int = 10 + ) -> plot: Image where { + maxBinCount > 0 + } /** * Create a line plot for two columns in the table. @@ -75,18 +73,17 @@ class ExperimentalTablePlotter( * @param xName The name of the column to be plotted on the x-axis. * @param yName The name of the column to be plotted on the y-axis. * - * @result linePlot The plot as an image. + * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5], - * // "b": [2, 3, 4, 5, 6], - * // } - * // ) - * // image = table.plot.line_plot("a", "b") + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5], + * "b": [2, 3, 4, 5, 6], + * } + * ); + * val image = table.plot.linePlot("a", "b"); * } */ @Pure @@ -94,7 +91,7 @@ class ExperimentalTablePlotter( fun linePlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> linePlot: Image + ) -> plot: Image /** * Create a scatter plot for two columns in the table. @@ -102,18 +99,17 @@ class ExperimentalTablePlotter( * @param xName The name of the column to be plotted on the x-axis. * @param yName The name of the column to be plotted on the y-axis. * - * @result scatterPlot The plot as an image. + * @result plot The plot as an image. * * @example * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable( - * // { - * // "a": [1, 2, 3, 4, 5], - * // "b": [2, 3, 4, 5, 6], - * // } - * // ) - * // image = table.plot.scatter_plot("a", "b") + * val table = Table( + * { + * "a": [1, 2, 3, 4, 5], + * "b": [2, 3, 4, 5, 6], + * } + * ); + * val image = table.plot.scatterPlot("a", "b"); * } */ @Pure @@ -121,5 +117,5 @@ class ExperimentalTablePlotter( fun scatterPlot( @PythonName("x_name") xName: String, @PythonName("y_name") yName: String - ) -> scatterPlot: Image + ) -> plot: Image } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Discretizer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Discretizer.sdsstub index 278f76824..407cd9e36 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Discretizer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Discretizer.sdsstub @@ -6,7 +6,7 @@ from safeds.data.tabular.transformation import TableTransformer /** * The Discretizer bins continuous data into intervals. * - * @param numberOfBins The number of bins to be created. + * @param binCount The number of bins to be created. * * @example * pipeline example { @@ -17,23 +17,46 @@ from safeds.data.tabular.transformation import TableTransformer * } */ class Discretizer( - @PythonName("number_of_bins") const numberOfBins: Int = 5 + @PythonName("number_of_bins") const binCount: Int = 5 ) sub TableTransformer where { - numberOfBins >= 2 + binCount >= 2 } { + /** + * The number of bins to be created. + */ + @PythonName("number_of_bins") attr binCount: Int + /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Discretizer + ) -> fittedTransformer: Discretizer + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: Discretizer, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalDiscretizer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalDiscretizer.sdsstub deleted file mode 100644 index 15324e11a..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalDiscretizer.sdsstub +++ /dev/null @@ -1,30 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalTableTransformer - -/** - * The Discretizer bins continuous data into intervals. - * - * @param numberOfBins The number of bins to be created. - */ -@Experimental -class ExperimentalDiscretizer( - @PythonName("number_of_bins") numberOfBins: Int = 5 -) sub ExperimentalTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalDiscretizer -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.sdsstub deleted file mode 100644 index 0d369c77a..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalInvertibleTableTransformer.sdsstub +++ /dev/null @@ -1,25 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalTableTransformer - -/** - * A `TableTransformer` that can also undo the learned transformation after it has been applied. - */ -@Experimental -class ExperimentalInvertibleTableTransformer() sub ExperimentalTableTransformer { - /** - * Undo the learned transformation. - * - * The table is not modified. - * - * @param transformedTable The table to be transformed back to the original version. - * - * @result originalTable The original table. - */ - @Pure - @PythonName("inverse_transform") - fun inverseTransform( - @PythonName("transformed_table") transformedTable: ExperimentalTable - ) -> originalTable: ExperimentalTable -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalLabelEncoder.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalLabelEncoder.sdsstub deleted file mode 100644 index b493c036b..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalLabelEncoder.sdsstub +++ /dev/null @@ -1,26 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalInvertibleTableTransformer - -/** - * The LabelEncoder encodes one or more given columns into labels. - */ -@Experimental -class ExperimentalLabelEncoder() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalLabelEncoder -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.sdsstub deleted file mode 100644 index 9d827605d..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalOneHotEncoder.sdsstub +++ /dev/null @@ -1,58 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalInvertibleTableTransformer - -/** - * A way to deal with categorical features that is particularly useful for unordered (i.e. nominal) data. - * - * It replaces a column with a set of columns, each representing a unique value in the original column. The value of - * each new column is 1 if the original column had that value, and 0 otherwise. Take the following table as an - * example: - * - * | col1 | - * |------| - * | "a" | - * | "b" | - * | "c" | - * | "a" | - * - * The one-hot encoding of this table is: - * - * | col1__a | col1__b | col1__c | - * |---------|---------|---------| - * | 1 | 0 | 0 | - * | 0 | 1 | 0 | - * | 0 | 0 | 1 | - * | 1 | 0 | 0 | - * - * The name "one-hot" comes from the fact that each row has exactly one 1 in it, and the rest of the values are 0s. - * One-hot encoding is closely related to dummy variable / indicator variables, which are used in statistics. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Table - * // from safeds.data.tabular.transformation import OneHotEncoder - * // table = Table({"col1": ["a", "b", "c", "a"]}) - * // transformer = OneHotEncoder() - * // transformer.fit_and_transform(table, ["col1"])[1] - * } - */ -@Experimental -class ExperimentalOneHotEncoder() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalOneHotEncoder -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalRangeScaler.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalRangeScaler.sdsstub deleted file mode 100644 index f14c41308..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalRangeScaler.sdsstub +++ /dev/null @@ -1,32 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalInvertibleTableTransformer - -/** - * The RangeScaler transforms column values by scaling each value to a given range. - * - * @param min The minimum of the new range after the transformation - * @param max The maximum of the new range after the transformation - */ -@Experimental -class ExperimentalRangeScaler( - @PythonName("min_") min: Float = 0.0, - @PythonName("max_") max: Float = 1.0 -) sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalRangeScaler -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalSimpleImputer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalSimpleImputer.sdsstub deleted file mode 100644 index 9fce49cc2..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalSimpleImputer.sdsstub +++ /dev/null @@ -1,83 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalTableTransformer - -/** - * Replace missing values using the given strategy. - * - * @param strategy How to replace missing values. - * @param valueToReplace The value that should be replaced. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import Column, Table - * // from safeds.data.tabular.transformation import Imputer - * // - * // table = Table.from_columns( - * // [ - * // Column("a", [1, 3, None]), - * // Column("b", [None, 2, 3]), - * // ], - * // ) - * // transformer = Imputer(Imputer.Strategy.Constant(0)) - * // transformed_table = transformer.fit_and_transform(table) - * } - */ -@Experimental -class ExperimentalSimpleImputer( - strategy: ExperimentalSimpleImputer.Strategy, - @PythonName("value_to_replace") valueToReplace: union = null -) sub ExperimentalTableTransformer { - /** - * Various strategies to replace missing values. - */ - enum Strategy { - /** - * Replace missing values with the given constant value. - * - * @param value The value to replace missing values. - */ - Constant(value: Any) - - /** - * Replace missing values with the mean of each column. - */ - Mean - - /** - * Replace missing values with the median of each column. - */ - Median - - /** - * Replace missing values with the mode of each column. - */ - Mode - } - - /** - * The strategy used to replace missing values. - */ - attr strategy: ExperimentalSimpleImputer.Strategy - /** - * The value that should be replaced. - */ - @PythonName("value_to_replace") attr valueToReplace: Any - - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalSimpleImputer -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalStandardScaler.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalStandardScaler.sdsstub deleted file mode 100644 index 27ecfd085..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalStandardScaler.sdsstub +++ /dev/null @@ -1,26 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.transformation import ExperimentalInvertibleTableTransformer - -/** - * The StandardScaler transforms column values to a range by removing the mean and scaling to unit variance. - */ -@Experimental -class ExperimentalStandardScaler() sub ExperimentalInvertibleTableTransformer { - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalStandardScaler -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalTableTransformer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalTableTransformer.sdsstub deleted file mode 100644 index 99e8a1ab3..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/ExperimentalTableTransformer.sdsstub +++ /dev/null @@ -1,89 +0,0 @@ -package safeds.data.tabular.transformation - -from safeds.data.tabular.containers import ExperimentalTable - -/** - * Learn a transformation for a set of columns in a `Table` and transform another `Table` with the same columns. - */ -@Experimental -class ExperimentalTableTransformer { - /** - * Whether the transformer is fitted. - */ - @PythonName("is_fitted") attr isFitted: Boolean - - /** - * Learn a transformation for a set of columns in a table. - * - * This transformer is not modified. - * - * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - */ - @Pure - fun fit( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? - ) -> fittedTransformer: ExperimentalTableTransformer - - /** - * Apply the learned transformation to a table. - * - * The table is not modified. - * - * @param table The table to which the learned transformation is applied. - * - * @result transformedTable The transformed table. - */ - @Pure - fun transform( - table: ExperimentalTable - ) -> transformedTable: ExperimentalTable - - /** - * Get the names of all new columns that have been added by the transformer. - * - * @result addedColumns A list of names of the added columns, ordered as they will appear in the table. - */ - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> addedColumns: List - - /** - * Get the names of all columns that have been changed by the transformer. - * - * @result changedColumns A list of names of changed columns, ordered as they appear in the table. - */ - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> changedColumns: List - - /** - * Get the names of all columns that have been removed by the transformer. - * - * @result removedColumns A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. - */ - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> removedColumns: List - - /** - * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. - * - * Neither the transformer nor the table are modified. - * - * @param table The table used to fit the transformer. The transformer is then applied to this table. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. - * - * @result fittedTransformer The fitted transformer. - * @result transformedTable The transformed table. - */ - @Pure - @PythonName("fit_and_transform") - fun fitAndTransform( - table: ExperimentalTable, - @PythonName("column_names") columnNames: List? = null - ) -> (result1: ExperimentalTableTransformer, result2: ExperimentalTable) -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/InvertibleTableTransformer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/InvertibleTableTransformer.sdsstub index af751789f..98855d797 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/InvertibleTableTransformer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/InvertibleTableTransformer.sdsstub @@ -1,37 +1,60 @@ package safeds.data.tabular.transformation from safeds.data.tabular.containers import Table +from safeds.data.tabular.transformation import TableTransformer /** * A `TableTransformer` that can also undo the learned transformation after it has been applied. */ -class InvertibleTableTransformer sub TableTransformer { +class InvertibleTableTransformer() sub TableTransformer { /** * Learn a transformation for a set of columns in a table. * + * **Note:** This transformer is not modified. + * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: InvertibleTableTransformer + ) -> fittedTransformer: InvertibleTableTransformer + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: InvertibleTableTransformer, transformedTable: Table) /** - * Undo the learned transformation. + * Undo the learned transformation as well as possible. + * + * Column order and types may differ from the original table. Likewise, some values might not be restored. * - * The table is not modified. + * **Note:** The given table is not modified. * * @param transformedTable The table to be transformed back to the original version. * - * @result result1 The original table. + * @result originalTable The original table. */ @Pure @PythonName("inverse_transform") fun inverseTransform( @PythonName("transformed_table") transformedTable: Table - ) -> result1: Table + ) -> originalTable: Table } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/LabelEncoder.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/LabelEncoder.sdsstub index 51b06be3c..b7be4b73c 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/LabelEncoder.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/LabelEncoder.sdsstub @@ -6,6 +6,9 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer /** * The LabelEncoder encodes one or more given columns into labels. * + * @param partialOrder The partial order of the labels. The labels are encoded in the order of the given list. Additional values are + * encoded as the next integer after the last value in the list in the order they appear in the data. + * * @example * pipeline example { * val table = Table({"a": ["z", "y"], "b": [3, 4]}); @@ -16,20 +19,40 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer * // Table({"a": ["z", "y"], "b": [3, 4]}) * } */ -class LabelEncoder() sub InvertibleTableTransformer { +class LabelEncoder( + @PythonName("partial_order") partialOrder: List = [] +) sub InvertibleTableTransformer { /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all non-numeric columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: LabelEncoder + ) -> fittedTransformer: LabelEncoder + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: LabelEncoder, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/OneHotEncoder.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/OneHotEncoder.sdsstub index d08e50171..b391b3d6d 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/OneHotEncoder.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/OneHotEncoder.sdsstub @@ -29,6 +29,8 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer * The name "one-hot" comes from the fact that each row has exactly one 1 in it, and the rest of the values are 0s. * One-hot encoding is closely related to dummy variable / indicator variables, which are used in statistics. * + * @param separator The separator used to separate the original column name from the value in the new column names. + * * @example * pipeline example { * val table = Table({"a": ["z", "y"], "b": [3, 4]}); @@ -39,20 +41,40 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer * // Table({"a": ["z", "y"], "b": [3, 4]}) * } */ -class OneHotEncoder() sub InvertibleTableTransformer { +class OneHotEncoder( + separator: String = "__" +) sub InvertibleTableTransformer { /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: OneHotEncoder + ) -> fittedTransformer: OneHotEncoder + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: OneHotEncoder, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/RangeScaler.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/RangeScaler.sdsstub index 487f3a12d..1605535a6 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/RangeScaler.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/RangeScaler.sdsstub @@ -6,8 +6,8 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer /** * The RangeScaler transforms column values by scaling each value to a given range. * - * @param minimum The minimum of the new range after the transformation - * @param maximum The maximum of the new range after the transformation + * @param min The minimum of the new range after the transformation + * @param max The maximum of the new range after the transformation * * @example * pipeline example { @@ -20,22 +20,49 @@ from safeds.data.tabular.transformation import InvertibleTableTransformer * } */ class RangeScaler( - const minimum: Float = 0.0, - const maximum: Float = 1.0 + const min: Float = 0.0, + const max: Float = 1.0 ) sub InvertibleTableTransformer { + /** + * The minimum of the new range after the transformation. + */ + attr min: Float + /** + * The maximum of the new range after the transformation. + */ + attr max: Float + /** * Learn a transformation for a set of columns in a table. * * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all numeric columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: RangeScaler + ) -> fittedTransformer: RangeScaler + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: RangeScaler, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Imputer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/SimpleImputer.sdsstub similarity index 57% rename from packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Imputer.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/SimpleImputer.sdsstub index 3cd4e6f94..717162347 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/Imputer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/SimpleImputer.sdsstub @@ -6,12 +6,12 @@ from safeds.data.tabular.transformation import TableTransformer /** * Replace missing values with the given strategy. * - * @param strategy The strategy used to impute missing values. Use the classes nested inside `Imputer.Strategy` to specify it. + * @param strategy The strategy used to impute missing values. * * @example * pipeline example { * val table = Table({"a": [1, null], "b": [3, 4]}); - * val imputer = Imputer(Imputer.Strategy.Mean).fit(table, ["a"]); + * val imputer = SimpleImputer(SimpleImputer.Strategy.Mean).fit(table, ["a"]); * val transformedTable = imputer.transform(table); * // Table({"a": [1, 1], "b": [3, 4]}) * } @@ -19,13 +19,13 @@ from safeds.data.tabular.transformation import TableTransformer * @example * pipeline example { * val table = Table({"a": [1, null], "b": [3, 4]}); - * val imputer = Imputer(Imputer.Strategy.Constant(0)).fit(table, ["a"]); + * val imputer = SimpleImputer(SimpleImputer.Strategy.Constant(0)).fit(table, ["a"]); * val transformedTable = imputer.transform(table); * // Table({"a": [1, 0], "b": [3, 4]}) * } */ -class Imputer( - strategy: Imputer.Strategy, +class SimpleImputer( + strategy: SimpleImputer.Strategy, @PythonName("value_to_replace") valueToReplace: union = null ) sub TableTransformer { /** @@ -37,28 +37,32 @@ class Imputer( * * @param value The value to replace missing values. */ + @PythonName("constant") Constant(value: Any) /** * Replace missing values with the mean of each column. */ + @PythonName("mean") Mean /** * Replace missing values with the median of each column. */ + @PythonName("median") Median /** * Replace missing values with the mode of each column. */ + @PythonName("mode") Mode } /** * The strategy used to replace missing values. */ - attr strategy: Imputer.Strategy + attr strategy: SimpleImputer.Strategy /** * The value that should be replaced. */ @@ -70,13 +74,31 @@ class Imputer( * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: Imputer + ) -> fittedTransformer: SimpleImputer + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: SimpleImputer, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/StandardScaler.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/StandardScaler.sdsstub index dcf96d762..4d0c09127 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/StandardScaler.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/StandardScaler.sdsstub @@ -23,13 +23,31 @@ class StandardScaler() sub InvertibleTableTransformer { * This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: StandardScaler + ) -> fittedTransformer: StandardScaler + + /** + * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. + * + * **Note:** Neither this transformer nor the given table are modified. + * + * @param table The table used to fit the transformer. The transformer is then applied to this table. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. + * + * @result fittedTransformer The fitted transformer. + * @result transformedTable The transformed table. + */ + @Pure + @PythonName("fit_and_transform") + fun fitAndTransform( + table: Table, + @PythonName("column_names") columnNames: List? = null + ) -> (fittedTransformer: StandardScaler, transformedTable: Table) } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/TableTransformer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/TableTransformer.sdsstub index 4fb573b26..016b9e42c 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/TableTransformer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/transformation/TableTransformer.sdsstub @@ -14,67 +14,40 @@ class TableTransformer { /** * Learn a transformation for a set of columns in a table. * - * This transformer is not modified. + * **Note:** This transformer is not modified. * * @param table The table used to fit the transformer. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * - * @result result1 The fitted transformer. + * @result fittedTransformer The fitted transformer. */ @Pure fun fit( table: Table, @PythonName("column_names") columnNames: List? - ) -> result1: TableTransformer + ) -> fittedTransformer: TableTransformer /** * Apply the learned transformation to a table. * - * The table is not modified. + * **Note:** The given table is not modified. * * @param table The table to which the learned transformation is applied. * - * @result result1 The transformed table. + * @result transformedTable The transformed table. */ @Pure fun transform( table: Table - ) -> result1: Table - - /** - * Get the names of all new columns that have been added by the transformer. - * - * @result result1 A list of names of the added columns, ordered as they will appear in the table. - */ - @Pure - @PythonName("get_names_of_added_columns") - fun getNamesOfAddedColumns() -> result1: List - - /** - * Get the names of all columns that have been changed by the transformer. - * - * @result result1 A list of names of changed columns, ordered as they appear in the table. - */ - @Pure - @PythonName("get_names_of_changed_columns") - fun getNamesOfChangedColumns() -> result1: List - - /** - * Get the names of all columns that have been removed by the transformer. - * - * @result result1 A list of names of the removed columns, ordered as they appear in the table the transformer was fitted on. - */ - @Pure - @PythonName("get_names_of_removed_columns") - fun getNamesOfRemovedColumns() -> result1: List + ) -> transformedTable: Table /** * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. * - * Neither the transformer nor the table are modified. + * **Note:** Neither this transformer nor the given table are modified. * * @param table The table used to fit the transformer. The transformer is then applied to this table. - * @param columnNames The list of columns from the table used to fit the transformer. If `None`, all columns are used. + * @param columnNames The list of columns from the table used to fit the transformer. If `null`, all columns are used. * * @result fittedTransformer The fitted transformer. * @result transformedTable The transformed table. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ColumnType.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ColumnType.sdsstub deleted file mode 100644 index 2b018f109..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ColumnType.sdsstub +++ /dev/null @@ -1,42 +0,0 @@ -package safeds.data.tabular.typing - -/** - * Abstract base class for column types. - * - * @param isNullable Whether the columntype is nullable. - * - * @example - * pipeline example { - * // TODO - * } - */ -@Experimental -class ColumnType { - /** - * Return whether the given column type is nullable. - * - * @result result1 True if the column is nullable. - * - * @example - * pipeline example { - * // TODO - * } - */ - @Pure - @PythonName("is_nullable") - fun isNullable() -> result1: Boolean - - /** - * Return whether the given column type is numeric. - * - * @result result1 True if the column is numeric. - * - * @example - * pipeline example { - * // TODO - * } - */ - @Pure - @PythonName("is_numeric") - fun isNumeric() -> result1: Boolean -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalDataType.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/DataType.sdsstub similarity index 88% rename from packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalDataType.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/DataType.sdsstub index 968d81f7c..83c7bb628 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalDataType.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/DataType.sdsstub @@ -3,8 +3,7 @@ package safeds.data.tabular.typing /** * The type of a column or cell in a table. */ -@Experimental -class ExperimentalDataType { +class DataType { /** * Whether the column type is numeric. */ diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalSchema.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalSchema.sdsstub deleted file mode 100644 index 90347421c..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/ExperimentalSchema.sdsstub +++ /dev/null @@ -1,70 +0,0 @@ -package safeds.data.tabular.typing - -from safeds.data.tabular.typing import ExperimentalDataType - -/** - * The schema of a row or table. - */ -@Experimental -class ExperimentalSchema { - /** - * Return a list of all column names contained in this schema. - */ - @PythonName("column_names") attr columnNames: List - - /** - * Return the type of the given column. - * - * @param name The name of the column. - * - * @result type The type of the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // type_ = table.schema.get_column_type("A") - * } - */ - @Pure - @PythonName("get_column_type") - fun getColumnType( - name: String - ) -> type: ExperimentalDataType - - /** - * Return whether the schema contains a given column. - * - * @param name The name of the column. - * - * @result contains True if the schema contains the column. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // table.schema.has_column("A") - * } - */ - @Pure - @PythonName("has_column") - fun hasColumn( - name: String - ) -> contains: Boolean - - /** - * Return a dictionary that maps column names to column types. - * - * @result data Dictionary representation of the schema. - * - * @example - * pipeline example { - * // from safeds.data.tabular.containers import ExperimentalTable - * // table = ExperimentalTable({"A": [1, 2, 3], "B": ["a", "b", "c"]}) - * // dict_ = table.schema.to_dict() - * } - */ - @Pure - @PythonName("to_dict") - fun toDict() -> data: Map -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/Schema.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/Schema.sdsstub index 5fbba3bf9..9c780deee 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/Schema.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/data/tabular/typing/Schema.sdsstub @@ -1,76 +1,66 @@ package safeds.data.tabular.typing -from safeds.data.tabular.typing import ColumnType +from safeds.data.tabular.typing import DataType /** - * Store column names and corresponding data types for a `Table` or `Row`. - * - * @param schema Map from column names to data types. - * - * @example - * pipeline example { - * // TODO - * } + * The schema of a row or table. */ -@Experimental class Schema { /** - * Return a list of all column names saved in this schema. - * - * @example - * pipeline example { - * // TODO - * } + * Return a list of all column names contained in this schema. */ @PythonName("column_names") attr columnNames: List /** - * Return whether the schema contains a given column. + * Return the type of the given column. * - * @param columnName The name of the column. + * @param name The name of the column. * - * @result result1 True if the schema contains the column. + * @result type The type of the column. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val type = table.^schema.getColumnType("A"); * } */ @Pure - @PythonName("has_column") - fun hasColumn( - @PythonName("column_name") columnName: String - ) -> result1: Boolean + @PythonName("get_column_type") + fun getColumnType( + name: String + ) -> type: DataType /** - * Return the type of the given column. + * Return whether the schema contains a given column. * - * @param columnName The name of the column. + * @param name The name of the column. * - * @result result1 The type of the column. + * @result contains True if the schema contains the column. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val contains = table.^schema.hasColumn("A"); // true * } */ @Pure - @PythonName("get_column_type") - fun getColumnType( - @PythonName("column_name") columnName: String - ) -> result1: ColumnType + @PythonName("has_column") + fun hasColumn( + name: String + ) -> contains: Boolean /** * Return a dictionary that maps column names to column types. * - * @result result1 Dictionary representation of the schema. + * @result data Dictionary representation of the schema. * * @example * pipeline example { - * // TODO + * val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]}); + * val map = table.^schema.toMap(); * } */ @Pure @PythonName("to_dict") - fun toDict() -> result1: Map + fun toMap() -> data: Map } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/SupervisedModel.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/SupervisedModel.sdsstub new file mode 100644 index 000000000..43611bd18 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/SupervisedModel.sdsstub @@ -0,0 +1,88 @@ +package safeds.ml.classical + +from safeds.data.labeled.containers import TabularDataset +from safeds.data.tabular.containers import Table +from safeds.data.tabular.typing import DataType +from safeds.data.tabular.typing import Schema + +/** + * A model for supervised learning tasks. + */ +class SupervisedModel { + /** + * Whether the model is fitted. + */ + @PythonName("is_fitted") attr isFitted: Boolean + + /** + * Create a copy of this model and fit it with the given training data. + * + * **Note:** This model is not modified. + * + * @param trainingSet The training data containing the features and target. + * + * @result fittedModel The fitted model. + */ + @Pure + fun fit( + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedModel: SupervisedModel + + /** + * Predict the target values on the given dataset. + * + * **Note:** The model must be fitted. + * + * @param dataset The dataset containing at least the features. + * + * @result prediction The given dataset with an additional column for the predicted target values. + */ + @Pure + fun predict( + dataset: union + ) -> prediction: TabularDataset + + /** + * Return the names of the feature columns. + * + * **Note:** The model must be fitted. + * + * @result featureNames The names of the feature columns. + */ + @Pure + @PythonName("get_feature_names") + fun getFeatureNames() -> featureNames: List + + /** + * Return the schema of the feature columns. + * + * **Note:** The model must be fitted. + * + * @result featureSchema The schema of the feature columns. + */ + @Pure + @PythonName("get_features_schema") + fun getFeaturesSchema() -> featureSchema: Schema + + /** + * Return the name of the target column. + * + * **Note:** The model must be fitted. + * + * @result targetName The name of the target column. + */ + @Pure + @PythonName("get_target_name") + fun getTargetName() -> targetName: String + + /** + * Return the type of the target column. + * + * **Note:** The model must be fitted. + * + * @result targetType The type of the target column. + */ + @Pure + @PythonName("get_target_type") + fun getTargetType() -> targetType: DataType +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/AdaBoostClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/AdaBoostClassifier.sdsstub index 70122e7ee..563e8c37d 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/AdaBoostClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/AdaBoostClassifier.sdsstub @@ -8,7 +8,7 @@ from safeds.ml.classical.classification import Classifier * Ada Boost classification. * * @param learner The learner from which the boosted ensemble is built. - * @param maximumNumberOfLearners The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure + * @param maxLearnerCount The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure * is stopped early. Has to be greater than 0. * @param learningRate Weight applied to each classifier at each boosting iteration. A higher learning rate increases the contribution * of each classifier. Has to be greater than 0. @@ -17,16 +17,16 @@ from safeds.ml.classical.classification import Classifier * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val classifier = AdaBoostClassifier(maximumNumberOfLearners = 100).fit(training); + * val classifier = AdaBoostClassifier(maxLearnerCount = 100).fit(training); * val accuracy = classifier.accuracy(test); * } */ class AdaBoostClassifier( learner: Classifier = DecisionTreeClassifier(), - @PythonName("maximum_number_of_learners") const maximumNumberOfLearners: Int = 50, + @PythonName("maximum_number_of_learners") const maxLearnerCount: Int = 50, @PythonName("learning_rate") const learningRate: Float = 1.0 ) sub Classifier where { - maximumNumberOfLearners >= 1, + maxLearnerCount >= 1, learningRate > 0.0 } { /** @@ -36,7 +36,7 @@ class AdaBoostClassifier( /** * Get the maximum number of learners in the ensemble. */ - @PythonName("maximum_number_of_learners") attr maximumNumberOfLearners: Int + @PythonName("maximum_number_of_learners") attr maxLearnerCount: Int /** * Get the learning rate. */ @@ -53,6 +53,6 @@ class AdaBoostClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: AdaBoostClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/Classifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/Classifier.sdsstub index 45333c52e..372c01a30 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/Classifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/Classifier.sdsstub @@ -2,45 +2,17 @@ package safeds.ml.classical.classification from safeds.data.labeled.containers import TabularDataset from safeds.data.tabular.containers import Table +from safeds.ml.classical import SupervisedModel /** - * Abstract base class for all classifiers. + * A model for classification tasks. */ -class Classifier { - /** - * Whether the classifier is fitted. - */ - @PythonName("is_fitted") attr isFitted: Boolean - - /** - * Create a copy of this classifier and fit it with the given training data. - * - * This classifier is not modified. - * - * @param trainingSet The training data containing the feature and target vectors. - * - * @result fittedClassifier The fitted classifier. - */ - @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: Classifier - - /** - * Predict a target vector using a dataset containing feature vectors. The model has to be trained first. - * - * @param dataset The dataset containing the feature vectors. - * - * @result prediction A dataset containing the given feature vectors and the predicted target vector. - */ - @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset - +class Classifier sub SupervisedModel { /** * Summarize the classifier's metrics on the given data. * + * **Note:** The model must be fitted. + * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * @@ -49,65 +21,82 @@ class Classifier { @Pure @PythonName("summarize_metrics") fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any ) -> metrics: Table /** * Compute the accuracy of the classifier on the given data. * + * The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the + * better. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. + * * @param validationOrTestSet The validation or test set. * - * @result accuracy The calculated accuracy score, i.e. the percentage of equal data. + * @result accuracy The classifier's accuracy. */ @Pure fun accuracy( - @PythonName("validation_or_test_set") validationOrTestSet: union + @PythonName("validation_or_test_set") validationOrTestSet: union ) -> accuracy: Float /** - * Compute the classifier's precision on the given data. + * Compute the classifier's F₁ score on the given data. + * + * The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the + * classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result precision The calculated precision score, i.e. the ratio of correctly predicted positives to all predicted positives. - * Return 1 if no positive predictions are made. + * @result f1Score The classifier's F₁ score. */ @Pure - fun precision( - @PythonName("validation_or_test_set") validationOrTestSet: union, + @PythonName("f1_score") + fun f1Score( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> precision: Float + ) -> f1Score: Float /** - * Compute the classifier's recall on the given data. + * Compute the classifier's precision on the given data. + * + * The precision is the proportion of positive predictions that were correct. The **higher** the precision, the + * better the classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result recall The calculated recall score, i.e. the ratio of correctly predicted positives to all expected positives. - * Return 1 if there are no positive expectations. + * @result precision The classifier's precision. */ @Pure - fun recall( - @PythonName("validation_or_test_set") validationOrTestSet: union, + fun precision( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> recall: Float + ) -> precision: Float /** - * Compute the classifier's $F_1$-score on the given data. + * Compute the classifier's recall on the given data. + * + * The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the + * better the classifier. Results range from 0.0 to 1.0. + * + * **Note:** The model must be fitted. * * @param validationOrTestSet The validation or test set. * @param positiveClass The class to be considered positive. All other classes are considered negative. * - * @result f1Score The calculated $F_1$-score, i.e. the harmonic mean between precision and recall. - * Return 1 if there are no positive expectations and predictions. + * @result recall The classifier's recall. */ @Pure - @PythonName("f1_score") - fun f1Score( - @PythonName("validation_or_test_set") validationOrTestSet: union, + fun recall( + @PythonName("validation_or_test_set") validationOrTestSet: union, @PythonName("positive_class") positiveClass: Any - ) -> f1Score: Float + ) -> recall: Float } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/DecisionTreeClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/DecisionTreeClassifier.sdsstub index c18943a8a..8a28ae788 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/DecisionTreeClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/DecisionTreeClassifier.sdsstub @@ -1,16 +1,13 @@ package safeds.ml.classical.classification -from safeds.data.labeled.containers import ExperimentalTabularDataset from safeds.data.labeled.containers import TabularDataset -from safeds.data.tabular.containers import ExperimentalTable -from safeds.data.tabular.containers import Table from safeds.ml.classical.classification import Classifier /** * Decision tree classification. * - * @param maximumDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. - * @param minimumNumberOfSamplesInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. + * @param maxDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. + * @param minSampleCountInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. * * @example * pipeline example { @@ -21,19 +18,19 @@ from safeds.ml.classical.classification import Classifier * } */ class DecisionTreeClassifier( - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1 + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1 ) sub Classifier where { - minimumNumberOfSamplesInLeaves > 0 + minSampleCountInLeaves > 0 } { /** * The maximum depth of the tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of the tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -46,6 +43,6 @@ class DecisionTreeClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: DecisionTreeClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/GradientBoostingClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/GradientBoostingClassifier.sdsstub index 526e50208..488aa073a 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/GradientBoostingClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/GradientBoostingClassifier.sdsstub @@ -7,7 +7,7 @@ from safeds.ml.classical.classification import Classifier /** * Gradient boosting classification. * - * @param numberOfTrees The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large + * @param treeCount The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large * number usually results in better performance. * @param learningRate The larger the value, the more the model is influenced by each additional tree. If the learning rate is too * low, the model might underfit. If the learning rate is too high, the model might overfit. @@ -16,21 +16,21 @@ from safeds.ml.classical.classification import Classifier * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val classifier = GradientBoostingClassifier(numberOfTrees = 50).fit(training); + * val classifier = GradientBoostingClassifier(treeCount = 50).fit(training); * val accuracy = classifier.accuracy(test); * } */ class GradientBoostingClassifier( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, + @PythonName("number_of_trees") const treeCount: Int = 100, @PythonName("learning_rate") const learningRate: Float = 0.1 ) sub Classifier where { - numberOfTrees >= 1, + treeCount >= 1, learningRate > 0.0 } { /** * Get the number of trees (estimators) in the ensemble. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * Get the learning rate. */ @@ -47,6 +47,6 @@ class GradientBoostingClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: GradientBoostingClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/KNearestNeighborsClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/KNearestNeighborsClassifier.sdsstub index 03ebccd7f..d1e30afa8 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/KNearestNeighborsClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/KNearestNeighborsClassifier.sdsstub @@ -7,7 +7,7 @@ from safeds.ml.classical.classification import Classifier /** * K-nearest-neighbors classification. * - * @param numberOfNeighbors The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and + * @param neighborCount The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and * less than or equal to the sample size (validated when calling `fit`). * * @example @@ -19,14 +19,14 @@ from safeds.ml.classical.classification import Classifier * } */ class KNearestNeighborsClassifier( - @PythonName("number_of_neighbors") const numberOfNeighbors: Int + @PythonName("number_of_neighbors") const neighborCount: Int ) sub Classifier where { - numberOfNeighbors >= 1 + neighborCount >= 1 } { /** * Get the number of neighbors used for interpolation. */ - @PythonName("number_of_neighbors") attr numberOfNeighbors: Int + @PythonName("number_of_neighbors") attr neighborCount: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -39,6 +39,6 @@ class KNearestNeighborsClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: KNearestNeighborsClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticRegressionClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticClassifier.sdsstub similarity index 74% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticRegressionClassifier.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticClassifier.sdsstub index 3787c6562..a8149b4ef 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticRegressionClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/LogisticClassifier.sdsstub @@ -11,11 +11,11 @@ from safeds.ml.classical.classification import Classifier * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val classifier = LogisticRegressionClassifier().fit(training); + * val classifier = LogisticClassifier().fit(training); * val accuracy = classifier.accuracy(test); * } */ -class LogisticRegressionClassifier() sub Classifier { +class LogisticClassifier() sub Classifier { /** * Create a copy of this classifier and fit it with the given training data. * @@ -27,6 +27,6 @@ class LogisticRegressionClassifier() sub Classifier { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: LogisticRegressionClassifier + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: LogisticClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/RandomForestClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/RandomForestClassifier.sdsstub index 94c7b152e..3cbf54484 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/RandomForestClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/RandomForestClassifier.sdsstub @@ -7,38 +7,38 @@ from safeds.ml.classical.classification import Classifier /** * Random forest classification. * - * @param numberOfTrees The number of trees to be used in the random forest. Has to be greater than 0. - * @param maximumDepth The maximum depth of each tree. If None, the depth is not limited. Has to be greater than 0. - * @param minimumNumberOfSamplesInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. + * @param treeCount The number of trees to be used in the random forest. Has to be greater than 0. + * @param maxDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. + * @param minSampleCountInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. * * @example * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val classifier = RandomForestClassifier(numberOfTrees = 10).fit(training); + * val classifier = RandomForestClassifier(treeCount = 10).fit(training); * val accuracy = classifier.accuracy(test); * } */ class RandomForestClassifier( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1, + @PythonName("number_of_trees") const treeCount: Int = 100, + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1, ) sub Classifier where { - numberOfTrees > 0, - minimumNumberOfSamplesInLeaves > 0, + treeCount > 0, + minSampleCountInLeaves > 0, } { /** * Get the number of trees used in the random forest. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * The maximum depth of each tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of each tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this classifier and fit it with the given training data. @@ -51,6 +51,6 @@ class RandomForestClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedClassifier: RandomForestClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorMachineClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorClassifier.sdsstub similarity index 64% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorMachineClassifier.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorClassifier.sdsstub index 9ae72af95..e73a14f34 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorMachineClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/classification/SupportVectorClassifier.sdsstub @@ -5,24 +5,24 @@ from safeds.data.tabular.containers import Table from safeds.ml.classical.classification import Classifier /** - * Support vector machine. + * Support vector machine for classification. * - * @param c The strength of regularization. Must be strictly positive. - * @param kernel The type of kernel to be used. Defaults to None. + * @param c The strength of regularization. Must be greater than 0. + * @param kernel The type of kernel to be used. Defaults to a radial basis function kernel. * * @example * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val classifier = SupportVectorMachineClassifier( - * kernel = SupportVectorMachineClassifier.Kernel.Linear + * val classifier = SupportVectorClassifier( + * kernel = SupportVectorClassifier.Kernel.Linear * ).fit(training); * val accuracy = classifier.accuracy(test); * } */ -class SupportVectorMachineClassifier( +class SupportVectorClassifier( const c: Float = 1.0, - kernel: SupportVectorMachineClassifier.Kernel = SupportVectorMachineClassifier.Kernel.RadialBasisFunction + kernel: SupportVectorClassifier.Kernel = SupportVectorClassifier.Kernel.RadialBasisFunction ) sub Classifier where { c > 0.0 } { @@ -33,6 +33,7 @@ class SupportVectorMachineClassifier( /** * A linear kernel. */ + @PythonName("linear") Linear /** @@ -40,16 +41,21 @@ class SupportVectorMachineClassifier( * * @param degree The degree of the polynomial. */ - Polynomial(degree: Int) + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } /** * A sigmoid kernel. */ + @PythonName("sigmoid") Sigmoid /** * A radial basis function kernel. */ + @PythonName("radial_basis_function") RadialBasisFunction } @@ -60,7 +66,7 @@ class SupportVectorMachineClassifier( /** * Get the type of kernel used. */ - attr kernel: SupportVectorMachineClassifier.Kernel + attr kernel: SupportVectorClassifier.Kernel /** * Create a copy of this classifier and fit it with the given training data. @@ -73,6 +79,6 @@ class SupportVectorMachineClassifier( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedClassifier: SupportVectorMachineClassifier + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedClassifier: SupportVectorClassifier } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/AdaBoostRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/AdaBoostRegressor.sdsstub index ab520c7dc..733ff04da 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/AdaBoostRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/AdaBoostRegressor.sdsstub @@ -8,7 +8,7 @@ from safeds.ml.classical.regression import Regressor * Ada Boost regression. * * @param learner The learner from which the boosted ensemble is built. - * @param maximumNumberOfLearners The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure + * @param maxLearnerCount The maximum number of learners at which boosting is terminated. In case of perfect fit, the learning procedure * is stopped early. Has to be greater than 0. * @param learningRate Weight applied to each regressor at each boosting iteration. A higher learning rate increases the contribution * of each regressor. Has to be greater than 0. @@ -17,16 +17,16 @@ from safeds.ml.classical.regression import Regressor * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = AdaBoostRegressor(maximumNumberOfLearners = 100).fit(training); + * val regressor = AdaBoostRegressor(maxLearnerCount = 100).fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ class AdaBoostRegressor( learner: Regressor = DecisionTreeRegressor(), - @PythonName("maximum_number_of_learners") const maximumNumberOfLearners: Int = 50, + @PythonName("maximum_number_of_learners") const maxLearnerCount: Int = 50, @PythonName("learning_rate") const learningRate: Float = 1.0 ) sub Regressor where { - maximumNumberOfLearners >= 1, + maxLearnerCount >= 1, learningRate > 0.0 } { /** @@ -36,7 +36,7 @@ class AdaBoostRegressor( /** * Get the maximum number of learners in the ensemble. */ - @PythonName("maximum_number_of_learners") attr maximumNumberOfLearners: Int + @PythonName("maximum_number_of_learners") attr maxLearnerCount: Int /** * Get the learning rate. */ @@ -53,6 +53,6 @@ class AdaBoostRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: AdaBoostRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/DecisionTreeRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/DecisionTreeRegressor.sdsstub index 142203c90..65c1009b7 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/DecisionTreeRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/DecisionTreeRegressor.sdsstub @@ -7,8 +7,8 @@ from safeds.ml.classical.regression import Regressor /** * Decision tree regression. * - * @param maximumDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. - * @param minimumNumberOfSamplesInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. + * @param maxDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. + * @param minSampleCountInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. * * @example * pipeline example { @@ -19,19 +19,19 @@ from safeds.ml.classical.regression import Regressor * } */ class DecisionTreeRegressor( - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1 + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1 ) sub Regressor where { - minimumNumberOfSamplesInLeaves > 0 + minSampleCountInLeaves > 0 } { /** * The maximum depth of the tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of the tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -44,6 +44,6 @@ class DecisionTreeRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: DecisionTreeRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/ElasticNetRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/ElasticNetRegressor.sdsstub index 9a7eb1adc..b92bad02f 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/ElasticNetRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/ElasticNetRegressor.sdsstub @@ -47,6 +47,6 @@ class ElasticNetRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: ElasticNetRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/GradientBoostingRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/GradientBoostingRegressor.sdsstub index 80af34a17..458a2d390 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/GradientBoostingRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/GradientBoostingRegressor.sdsstub @@ -7,7 +7,7 @@ from safeds.ml.classical.regression import Regressor /** * Gradient boosting regression. * - * @param numberOfTrees The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large + * @param treeCount The number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large * number usually results in better performance. * @param learningRate The larger the value, the more the model is influenced by each additional tree. If the learning rate is too * low, the model might underfit. If the learning rate is too high, the model might overfit. @@ -16,21 +16,21 @@ from safeds.ml.classical.regression import Regressor * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = GradientBoostingRegressor(numberOfTrees = 50).fit(training); + * val regressor = GradientBoostingRegressor(treeCount = 50).fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ class GradientBoostingRegressor( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, + @PythonName("number_of_trees") const treeCount: Int = 100, @PythonName("learning_rate") const learningRate: Float = 0.1 ) sub Regressor where { - numberOfTrees >= 1, + treeCount >= 1, learningRate > 0.0 } { /** * Get the number of trees (estimators) in the ensemble. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * Get the learning rate. */ @@ -47,6 +47,6 @@ class GradientBoostingRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: GradientBoostingRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/KNearestNeighborsRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/KNearestNeighborsRegressor.sdsstub index 34fbc2f6c..6f9e1d4bb 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/KNearestNeighborsRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/KNearestNeighborsRegressor.sdsstub @@ -7,26 +7,26 @@ from safeds.ml.classical.regression import Regressor /** * K-nearest-neighbors regression. * - * @param numberOfNeighbors The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and + * @param neighborCount The number of neighbors to use for interpolation. Has to be greater than 0 (validated in the constructor) and * less than or equal to the sample size (validated when calling `fit`). * * @example * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = KNearestNeighborsRegressor(numberOfNeighbors = 5).fit(training); + * val regressor = KNearestNeighborsRegressor(neighborCount = 5).fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ class KNearestNeighborsRegressor( - @PythonName("number_of_neighbors") const numberOfNeighbors: Int + @PythonName("number_of_neighbors") const neighborCount: Int ) sub Regressor where { - numberOfNeighbors >= 1 + neighborCount >= 1 } { /** * Get the number of neighbors used for interpolation. */ - @PythonName("number_of_neighbors") attr numberOfNeighbors: Int + @PythonName("number_of_neighbors") attr neighborCount: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -39,6 +39,6 @@ class KNearestNeighborsRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: KNearestNeighborsRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LassoRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LassoRegressor.sdsstub index a80ac9f93..1bbfdbcde 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LassoRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LassoRegressor.sdsstub @@ -38,6 +38,6 @@ class LassoRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: LassoRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressionRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressor.sdsstub similarity index 75% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressionRegressor.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressor.sdsstub index 656b40d82..c9d3974f0 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressionRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/LinearRegressor.sdsstub @@ -11,11 +11,11 @@ from safeds.ml.classical.regression import Regressor * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = LinearRegressionRegressor().fit(training); + * val regressor = LinearRegressor().fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ -class LinearRegressionRegressor() sub Regressor { +class LinearRegressor() sub Regressor { /** * Create a copy of this regressor and fit it with the given training data. * @@ -27,6 +27,6 @@ class LinearRegressionRegressor() sub Regressor { */ @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: LinearRegressionRegressor + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: LinearRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RandomForestRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RandomForestRegressor.sdsstub index 464cfccc6..bf0ab2e31 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RandomForestRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RandomForestRegressor.sdsstub @@ -7,38 +7,38 @@ from safeds.ml.classical.regression import Regressor /** * Random forest regression. * - * @param numberOfTrees The number of trees to be used in the random forest. Has to be greater than 0. - * @param maximumDepth The maximum depth of each tree. If None, the depth is not limited. Has to be greater than 0. - * @param minimumNumberOfSamplesInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. + * @param treeCount The number of trees to be used in the random forest. Has to be greater than 0. + * @param maxDepth The maximum depth of each tree. If null, the depth is not limited. Has to be greater than 0. + * @param minSampleCountInLeaves The minimum number of samples that must remain in the leaves of each tree. Has to be greater than 0. * * @example * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = RandomForestRegressor(numberOfTrees = 10).fit(training); + * val regressor = RandomForestRegressor(treeCount = 10).fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ class RandomForestRegressor( - @PythonName("number_of_trees") const numberOfTrees: Int = 100, - @PythonName("maximum_depth") maximumDepth: Int? = null, - @PythonName("minimum_number_of_samples_in_leaves") const minimumNumberOfSamplesInLeaves: Int = 1, + @PythonName("number_of_trees") const treeCount: Int = 100, + @PythonName("maximum_depth") maxDepth: Int? = null, + @PythonName("minimum_number_of_samples_in_leaves") const minSampleCountInLeaves: Int = 1, ) sub Regressor where { - numberOfTrees > 0, - minimumNumberOfSamplesInLeaves > 0, + treeCount > 0, + minSampleCountInLeaves > 0, } { /** * Get the number of trees used in the random forest. */ - @PythonName("number_of_trees") attr numberOfTrees: Int + @PythonName("number_of_trees") attr treeCount: Int /** * The maximum depth of each tree. */ - @PythonName("maximum_depth") attr maximumDepth: Int? + @PythonName("maximum_depth") attr maxDepth: Int? /** * The minimum number of samples that must remain in the leaves of each tree. */ - @PythonName("minimum_number_of_samples_in_leaves") attr minimumNumberOfSamplesInLeaves: Int + @PythonName("minimum_number_of_samples_in_leaves") attr minSampleCountInLeaves: Int /** * Create a copy of this regressor and fit it with the given training data. @@ -51,6 +51,6 @@ class RandomForestRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RandomForestRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/Regressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/Regressor.sdsstub index d7450bedf..ed994eeee 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/Regressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/Regressor.sdsstub @@ -2,78 +2,124 @@ package safeds.ml.classical.regression from safeds.data.labeled.containers import TabularDataset from safeds.data.tabular.containers import Table +from safeds.ml.classical import SupervisedModel /** - * Abstract base class for all regressors. + * A model for regression tasks. */ -class Regressor { +class Regressor sub SupervisedModel { /** - * Whether the regressor is fitted. + * Summarize the regressor's metrics on the given data. + * + * @param validationOrTestSet The validation or test set. + * + * @result metrics A table containing the regressor's metrics. */ - @PythonName("is_fitted") attr isFitted: Boolean + @Pure + @PythonName("summarize_metrics") + fun summarizeMetrics( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> metrics: Table /** - * Create a copy of this regressor and fit it with the given training data. + * Compute the coefficient of determination (R²) of the regressor on the given data. + * + * The coefficient of determination compares the regressor's predictions to another model that always predicts the + * mean of the target values. It is a measure of how well the regressor explains the variance in the target values. * - * This regressor is not modified. + * The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity + * to 1.0. You can interpret the coefficient of determination as follows: * - * @param trainingSet The training data containing the feature and target vectors. + * | R² | Interpretation | + * | ---------- | ------------------------------------------------------------------------------------------ | + * | 1.0 | The model perfectly predicts the target values. Did you overfit? | + * | (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | + * | 0.0 | The model is as good as predicting the mean of the target values. Try something else. | + * | (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | * - * @result fittedRegressor The fitted regressor. + * **Note:** Some other libraries call this metric `r2_score`. + * + * @param validationOrTestSet The validation or test set. + * + * @result coefficientOfDetermination The coefficient of determination of the regressor. */ @Pure - fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: Regressor + @PythonName("coefficient_of_determination") + fun coefficientOfDetermination( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> coefficientOfDetermination: Float /** - * Predict a target vector using a dataset containing feature vectors. The model has to be trained first. + * Compute the mean absolute error (MAE) of the regressor on the given data. + * + * The mean absolute error is the average of the absolute differences between the predicted and expected target + * values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive + * infinity. * - * @param dataset The dataset containing the feature vectors. + * @param validationOrTestSet The validation or test set. * - * @result prediction A dataset containing the given feature vectors and the predicted target vector. + * @result meanAbsoluteError The mean absolute error of the regressor. */ @Pure - fun predict( - dataset: union - ) -> prediction: TabularDataset + @PythonName("mean_absolute_error") + fun meanAbsoluteError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanAbsoluteError: Float /** - * Summarize the regressor's metrics on the given data. + * Compute the mean directional accuracy (MDA) of the regressor on the given data. + * + * This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) + * matches the expected direction. The mean directional accuracy is the proportion of correctly predicted + * directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to + * 1.0. + * + * This metric is useful for time series data, where the order of the target values has a meaning. It is not useful + * for other types of data. Because of this, it is not included in the `summarize_metrics` method. * * @param validationOrTestSet The validation or test set. * - * @result metrics A table containing the regressor's metrics. + * @result meanDirectionalAccuracy The mean directional accuracy of the regressor. */ @Pure - @PythonName("summarize_metrics") - fun summarizeMetrics( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> metrics: Table + @PythonName("mean_directional_accuracy") + fun meanDirectionalAccuracy( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanDirectionalAccuracy: Float /** - * Compute the mean absolute error (MAE) of the regressor on the given data. + * Compute the mean squared error (MSE) of the regressor on the given data. + * + * The mean squared error is the average of the squared differences between the predicted and expected target + * values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * **Note:** To get the root mean squared error (RMSE), take the square root of the result. * * @param validationOrTestSet The validation or test set. * - * @result meanAbsoluteError The calculated mean absolute error (the average of the distance of each individual row). + * @result meanSquaredError The mean squared error of the regressor. */ @Pure - @PythonName("mean_absolute_error") - fun meanAbsoluteError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanAbsoluteError: Float + @PythonName("mean_squared_error") + fun meanSquaredError( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> meanSquaredError: Float /** - * Compute the mean squared error (MSE) on the given data. + * Compute the median absolute deviation (MAD) of the regressor on the given data. + * + * The median absolute deviation is the median of the absolute differences between the predicted and expected + * target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to + * positive infinity. * * @param validationOrTestSet The validation or test set. * - * @result meanSquaredError The calculated mean squared error (the average of the distance of each individual row squared). + * @result medianAbsoluteDeviation The median absolute deviation of the regressor. */ @Pure - @PythonName("mean_squared_error") - fun meanSquaredError( - @PythonName("validation_or_test_set") validationOrTestSet: union - ) -> meanSquaredError: Float + @PythonName("median_absolute_deviation") + fun medianAbsoluteDeviation( + @PythonName("validation_or_test_set") validationOrTestSet: union + ) -> medianAbsoluteDeviation: Float } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RidgeRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RidgeRegressor.sdsstub index f69460ce9..f91095e75 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RidgeRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/RidgeRegressor.sdsstub @@ -38,6 +38,6 @@ class RidgeRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union + @PythonName("training_set") trainingSet: TabularDataset ) -> fittedRegressor: RidgeRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorMachineRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorRegressor.sdsstub similarity index 64% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorMachineRegressor.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorRegressor.sdsstub index 747c4215a..ba248f647 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorMachineRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/classical/regression/SupportVectorRegressor.sdsstub @@ -5,24 +5,24 @@ from safeds.data.tabular.containers import Table from safeds.ml.classical.regression import Regressor /** - * Support vector machine. + * Support vector machine for regression. * - * @param c The strength of regularization. Must be strictly positive. - * @param kernel The type of kernel to be used. Defaults to None. + * @param c The strength of regularization. Must be greater than 0. + * @param kernel The type of kernel to be used. Defaults to a radial basis function kernel. * * @example * pipeline example { * val training = Table.fromCsvFile("training.csv").toTabularDataset("target"); * val test = Table.fromCsvFile("test.csv").toTabularDataset("target"); - * val regressor = SupportVectorMachineRegressor( - * kernel = SupportVectorMachineRegressor.Kernel.Linear + * val regressor = SupportVectorRegressor( + * kernel = SupportVectorRegressor.Kernel.Linear * ).fit(training); * val meanSquaredError = regressor.meanSquaredError(test); * } */ -class SupportVectorMachineRegressor( +class SupportVectorRegressor( const c: Float = 1.0, - kernel: SupportVectorMachineRegressor.Kernel = SupportVectorMachineRegressor.Kernel.RadialBasisFunction + kernel: SupportVectorRegressor.Kernel = SupportVectorRegressor.Kernel.RadialBasisFunction ) sub Regressor where { c > 0.0 } { @@ -33,6 +33,7 @@ class SupportVectorMachineRegressor( /** * A linear kernel. */ + @PythonName("linear") Linear /** @@ -40,16 +41,21 @@ class SupportVectorMachineRegressor( * * @param degree The degree of the polynomial. */ - Polynomial(degree: Int) + @PythonName("polynomial") + Polynomial(const degree: Int) where { + degree > 0 + } /** * A sigmoid kernel. */ + @PythonName("sigmoid") Sigmoid /** * A radial basis function kernel. */ + @PythonName("radial_basis_function") RadialBasisFunction } @@ -60,7 +66,7 @@ class SupportVectorMachineRegressor( /** * Get the type of kernel used. */ - attr kernel: SupportVectorMachineRegressor.Kernel + attr kernel: SupportVectorRegressor.Kernel /** * Create a copy of this regressor and fit it with the given training data. @@ -73,6 +79,6 @@ class SupportVectorMachineRegressor( */ @Pure fun fit( - @PythonName("training_set") trainingSet: union - ) -> fittedRegressor: SupportVectorMachineRegressor + @PythonName("training_set") trainingSet: TabularDataset + ) -> fittedRegressor: SupportVectorRegressor } diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/ClassificationMetrics.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/ClassificationMetrics.sdsstub new file mode 100644 index 000000000..96c4b86e8 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/ClassificationMetrics.sdsstub @@ -0,0 +1,100 @@ +package safeds.ml.metrics + +from safeds.data.labeled.containers import TabularDataset +from safeds.data.tabular.containers import Table + +/** + * A collection of classification metrics. + */ +class ClassificationMetrics { + /** + * Summarize classification metrics on the given data. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result metrics A table containing the classification metrics. + */ + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> metrics: Table + + /** + * Compute the accuracy on the given data. + * + * The accuracy is the proportion of predicted target values that were correct. The **higher** the accuracy, the + * better. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * + * @result accuracy The calculated accuracy. + */ + @Pure + static fun accuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> accuracy: Float + + /** + * Compute the F₁ score on the given data. + * + * The F₁ score is the harmonic mean of precision and recall. The **higher** the F₁ score, the better the + * classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result f1Score The calculated F₁ score. + */ + @Pure + @PythonName("f1_score") + static fun f1Score( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> f1Score: Float + + /** + * Compute the precision on the given data. + * + * The precision is the proportion of positive predictions that were correct. The **higher** the precision, the + * better the classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result precision The calculated precision. + */ + @Pure + static fun precision( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> precision: Float + + /** + * Compute the recall on the given data. + * + * The recall is the proportion of actual positives that were predicted correctly. The **higher** the recall, the + * better the classifier. Results range from 0.0 to 1.0. + * + * @param predicted The predicted target values produced by the classifier. + * @param expected The expected target values. + * @param positiveClass The class to be considered positive. All other classes are considered negative. + * + * @result recall The calculated recall. + */ + @Pure + static fun recall( + predicted: union, TabularDataset>, + expected: union, TabularDataset>, + @PythonName("positive_class") positiveClass: Any + ) -> recall: Float +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/RegressionMetrics.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/RegressionMetrics.sdsstub new file mode 100644 index 000000000..fc25baffa --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/metrics/RegressionMetrics.sdsstub @@ -0,0 +1,135 @@ +package safeds.ml.metrics + +from safeds.data.labeled.containers import TabularDataset +from safeds.data.tabular.containers import Table + +/** + * A collection of regression metrics. + */ +class RegressionMetrics { + /** + * Summarize regression metrics on the given data. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result metrics A table containing the regression metrics. + */ + @Pure + static fun summarize( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> metrics: Table + + /** + * Compute the coefficient of determination (R²) on the given data. + * + * The coefficient of determination compares the regressor's predictions to another model that always predicts the + * mean of the target values. It is a measure of how well the regressor explains the variance in the target values. + * + * The **higher** the coefficient of determination, the better the regressor. Results range from negative infinity + * to 1.0. You can interpret the coefficient of determination as follows: + * + * | R² | Interpretation | + * | ---------- | ------------------------------------------------------------------------------------------ | + * | 1.0 | The model perfectly predicts the target values. Did you overfit? | + * | (0.0, 1.0) | The model is better than predicting the mean of the target values. You should be here. | + * | 0.0 | The model is as good as predicting the mean of the target values. Try something else. | + * | (-∞, 0.0) | The model is worse than predicting the mean of the target values. Something is very wrong. | + * + * **Note:** Some other libraries call this metric `r2_score`. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result coefficientOfDetermination The calculated coefficient of determination. + */ + @Pure + @PythonName("coefficient_of_determination") + static fun coefficientOfDetermination( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> coefficientOfDetermination: Float + + /** + * Compute the mean absolute error (MAE) on the given data. + * + * The mean absolute error is the average of the absolute differences between the predicted and expected target + * values. The **lower** the mean absolute error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanAbsoluteError The calculated mean absolute error. + */ + @Pure + @PythonName("mean_absolute_error") + static fun meanAbsoluteError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanAbsoluteError: Float + + /** + * Compute the mean directional accuracy (MDA) on the given data. + * + * This metric compares two consecutive target values and checks if the predicted direction (down/unchanged/up) + * matches the expected direction. The mean directional accuracy is the proportion of correctly predicted + * directions. The **higher** the mean directional accuracy, the better the regressor. Results range from 0.0 to + * 1.0. + * + * This metric is useful for time series data, where the order of the target values has a meaning. It is not useful + * for other types of data. Because of this, it is not included in the `summarize` method. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanDirectionalAccuracy The calculated mean directional accuracy. + */ + @Pure + @PythonName("mean_directional_accuracy") + static fun meanDirectionalAccuracy( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanDirectionalAccuracy: Float + + /** + * Compute the mean squared error (MSE) on the given data. + * + * The mean squared error is the average of the squared differences between the predicted and expected target + * values. The **lower** the mean squared error, the better the regressor. Results range from 0.0 to positive + * infinity. + * + * **Note:** To get the root mean squared error (RMSE), take the square root of the result. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result meanSquaredError The calculated mean squared error. + */ + @Pure + @PythonName("mean_squared_error") + static fun meanSquaredError( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> meanSquaredError: Float + + /** + * Compute the median absolute deviation (MAD) on the given data. + * + * The median absolute deviation is the median of the absolute differences between the predicted and expected + * target values. The **lower** the median absolute deviation, the better the regressor. Results range from 0.0 to + * positive infinity. + * + * @param predicted The predicted target values produced by the regressor. + * @param expected The expected target values. + * + * @result medianAbsoluteDeviation The calculated median absolute deviation. + */ + @Pure + @PythonName("median_absolute_deviation") + static fun medianAbsoluteDeviation( + predicted: union, TabularDataset>, + expected: union, TabularDataset> + ) -> medianAbsoluteDeviation: Float +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/AvgPooling2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/AvgPooling2DLayer.sdsstub deleted file mode 100644 index e143dadf3..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/AvgPooling2DLayer.sdsstub +++ /dev/null @@ -1,14 +0,0 @@ -package safeds.ml.nn - -/** - * @param kernelSize the size of the kernel - * @param stride the stride of the pooling - * @param padding the padding of the pooling - */ -// TODO Safe-DS does not support required but name only parameter assignments. -@Experimental -class AvgPooling2DLayer( - @PythonName("kernel_size") kernelSize: Int, - stride: Int, - padding: Int = 0 -) sub Layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/FlattenLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/FlattenLayer.sdsstub deleted file mode 100644 index 11d025290..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/FlattenLayer.sdsstub +++ /dev/null @@ -1,7 +0,0 @@ -package safeds.ml.nn - -from safeds.data.image.typing import ImageSize -from safeds.ml.nn import Layer - -@Experimental -class FlattenLayer() sub Layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ForwardLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ForwardLayer.sdsstub deleted file mode 100644 index 07b287d1e..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ForwardLayer.sdsstub +++ /dev/null @@ -1,16 +0,0 @@ -package safeds.ml.nn - -/** - * @param outputSize The number of neurons in this layer - * @param inputSize The number of neurons in the previous layer - * - * @example - * pipeline example { - * // TODO - * } - */ -@Experimental -class ForwardLayer( - @PythonName("output_size") outputSize: Int, - @PythonName("input_size") inputSize: Int? = null -) sub Layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Layer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Layer.sdsstub deleted file mode 100644 index 5f12f65e5..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Layer.sdsstub +++ /dev/null @@ -1,13 +0,0 @@ -package safeds.ml.nn - -@Experimental -class Layer { - /** - * The input_size of this layer. - */ - @PythonName("input_size") attr inputSize: Int - /** - * The output_size of this layer. - */ - @PythonName("output_size") attr outputSize: Int -} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/MaxPooling2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/MaxPooling2DLayer.sdsstub deleted file mode 100644 index 9cf67d30f..000000000 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/MaxPooling2DLayer.sdsstub +++ /dev/null @@ -1,14 +0,0 @@ -package safeds.ml.nn - -/** - * @param kernelSize the size of the kernel - * @param stride the stride of the pooling - * @param padding the padding of the pooling - */ -// TODO Safe-DS does not support required but name only parameter assignments. -@Experimental -class MaxPooling2DLayer( - @PythonName("kernel_size") kernelSize: Int, - stride: Int, - padding: Int = 0 -) sub Layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkClassifier.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkClassifier.sdsstub index ff22ade73..06bd998fb 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkClassifier.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkClassifier.sdsstub @@ -2,7 +2,7 @@ package safeds.ml.nn from safeds.data.labeled.containers import TabularDataset from safeds.data.tabular.containers import Table -from safeds.ml.nn import Layer +from safeds.ml.nn.layers import Layer /** * A NeuralNetworkClassifier is a neural network that is used for classification tasks. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkRegressor.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkRegressor.sdsstub index 0a6a74d1d..bc75417ad 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkRegressor.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/NeuralNetworkRegressor.sdsstub @@ -2,7 +2,7 @@ package safeds.ml.nn from safeds.data.labeled.containers import TabularDataset from safeds.data.tabular.containers import Table -from safeds.ml.nn import Layer +from safeds.ml.nn.layers import Layer /** * A NeuralNetworkRegressor is a neural network that is used for regression tasks. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversion.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversion.sdsstub similarity index 83% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversion.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversion.sdsstub index da8f3ce9f..ef32c7d98 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversion.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversion.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The input conversion for a neural network, defines the input parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionImage.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionImage.sdsstub similarity index 90% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionImage.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionImage.sdsstub index 0048bb4f1..5a6c49a87 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionImage.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionImage.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters from safeds.data.image.typing import ImageSize diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTable.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTable.sdsstub similarity index 92% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTable.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTable.sdsstub index 3315cfbe7..18ab8c40d 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTable.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTable.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The input conversion for a neural network defines the input parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTimeSeries.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTimeSeries.sdsstub similarity index 92% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTimeSeries.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTimeSeries.sdsstub index 812cc95cb..ed9430f24 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/InputConversionTimeSeries.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/InputConversionTimeSeries.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The input conversion for a neural network, defines the input parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversion.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversion.sdsstub similarity index 84% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversion.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversion.sdsstub index a090225f8..1f0c58aa3 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversion.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversion.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The output conversion for a neural network, defines the output parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToColumn.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToColumn.sdsstub similarity index 73% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToColumn.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToColumn.sdsstub index d1af23c67..01c61d891 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToColumn.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToColumn.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters @Experimental class OutputConversionImageToColumn() sub OutputConversion diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToImage.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToImage.sdsstub similarity index 73% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToImage.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToImage.sdsstub index 63f441257..f032f2b4e 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToImage.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToImage.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters @Experimental class OutputConversionImageToImage() sub OutputConversion diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToTable.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToTable.sdsstub similarity index 73% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToTable.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToTable.sdsstub index bcc7af2ad..94869f212 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionImageToTable.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionImageToTable.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters @Experimental class OutputConversionImageToTable() sub OutputConversion diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTable.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTable.sdsstub similarity index 91% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTable.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTable.sdsstub index fccbb0576..ba0f3f607 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTable.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTable.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The output conversion for a neural network defines the output parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTimeSeries.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTimeSeries.sdsstub similarity index 91% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTimeSeries.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTimeSeries.sdsstub index 1a08a61ce..1d0f47133 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/OutputConversionTimeSeries.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/converters/OutputConversionTimeSeries.sdsstub @@ -1,4 +1,4 @@ -package safeds.ml.nn +package safeds.ml.nn.converters /** * The output conversion for a neural network, defines the output parameters for the neural network. diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/AveragePooling2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/AveragePooling2DLayer.sdsstub new file mode 100644 index 000000000..214f5d658 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/AveragePooling2DLayer.sdsstub @@ -0,0 +1,24 @@ +package safeds.ml.nn.layers + +from safeds.ml.nn.layers import Layer + +/** + * @param kernelSize the size of the kernel + * @param stride the stride of the pooling + * @param padding the padding of the pooling + */ +@Experimental +class AveragePooling2DLayer( + @PythonName("kernel_size") kernelSize: Int, + stride: Int = -1, + padding: Int = 0 +) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Convolutional2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Convolutional2DLayer.sdsstub similarity index 58% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Convolutional2DLayer.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Convolutional2DLayer.sdsstub index 16d2344b1..331edadf3 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/Convolutional2DLayer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Convolutional2DLayer.sdsstub @@ -1,7 +1,7 @@ -package safeds.ml.nn +package safeds.ml.nn.layers from safeds.data.image.typing import ImageSize -from safeds.ml.nn import Layer +from safeds.ml.nn.layers import Layer /** * @param outputChannel the amount of output channels @@ -15,4 +15,13 @@ class Convolutional2DLayer( @PythonName("kernel_size") kernelSize: Int, stride: Int = 1, padding: Int = 0 -) sub Layer +) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ConvolutionalTranspose2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.sdsstub similarity index 88% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ConvolutionalTranspose2DLayer.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.sdsstub index b7e5762f9..c83ea7970 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/ConvolutionalTranspose2DLayer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ConvolutionalTranspose2DLayer.sdsstub @@ -1,7 +1,7 @@ -package safeds.ml.nn +package safeds.ml.nn.layers from safeds.data.image.typing import ImageSize -from safeds.ml.nn import Convolutional2DLayer +from safeds.ml.nn.layers import Convolutional2DLayer /** * @param outputChannel the amount of output channels diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/FlattenLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/FlattenLayer.sdsstub new file mode 100644 index 000000000..585a09de9 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/FlattenLayer.sdsstub @@ -0,0 +1,16 @@ +package safeds.ml.nn.layers + +from safeds.data.image.typing import ImageSize +from safeds.ml.nn.layers import Layer + +@Experimental +class FlattenLayer() sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: Int +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ForwardLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ForwardLayer.sdsstub new file mode 100644 index 000000000..7546b2e54 --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/ForwardLayer.sdsstub @@ -0,0 +1,22 @@ +package safeds.ml.nn.layers + +from safeds.ml.nn.layers import Layer + +/** + * @param outputSize The number of neurons in this layer + * @param inputSize The number of neurons in the previous layer + */ +@Experimental +class ForwardLayer( + @PythonName("output_size") outputSize: Int, + @PythonName("input_size") inputSize: Int? = null +) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: Int + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: Int +} diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/LSTMLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/LSTMLayer.sdsstub similarity index 88% rename from packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/LSTMLayer.sdsstub rename to packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/LSTMLayer.sdsstub index 119e4463b..ace1f92c8 100644 --- a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/LSTMLayer.sdsstub +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/LSTMLayer.sdsstub @@ -1,6 +1,6 @@ -package safeds.ml.nn +package safeds.ml.nn.layers -from safeds.ml.nn import Layer +from safeds.ml.nn.layers import Layer /** * @param outputSize The number of neurons in this layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Layer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Layer.sdsstub new file mode 100644 index 000000000..fd2b348ea --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/Layer.sdsstub @@ -0,0 +1,6 @@ +package safeds.ml.nn.layers + +from safeds.data.image.typing import ImageSize + +@Experimental +class Layer diff --git a/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/MaxPooling2DLayer.sdsstub b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/MaxPooling2DLayer.sdsstub new file mode 100644 index 000000000..0d807e6df --- /dev/null +++ b/packages/safe-ds-lang/src/resources/builtins/safeds/ml/nn/layers/MaxPooling2DLayer.sdsstub @@ -0,0 +1,24 @@ +package safeds.ml.nn.layers + +from safeds.ml.nn.layers import Layer + +/** + * @param kernelSize the size of the kernel + * @param stride the stride of the pooling + * @param padding the padding of the pooling + */ +@Experimental +class MaxPooling2DLayer( + @PythonName("kernel_size") kernelSize: Int, + stride: Int = -1, + padding: Int = 0 +) sub Layer { + /** + * Get the input_size of this layer. + */ + @PythonName("input_size") attr inputSize: ImageSize + /** + * Get the output_size of this layer. + */ + @PythonName("output_size") attr outputSize: ImageSize +} diff --git a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map deleted file mode 100644 index 90244b709..000000000 --- a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["input.sdsdev"],"names":["test","f","g","h","result1","result2","c","a","b","factory","c1","v","d","p","r","q","factorynested","nestedinstance","nestedresult","onehotencoder","encoder"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAwDA,IAASA,IAAI;IACTC,CAAC,CAAC;;QAAAC,CAAC;;;;;IACHD,CAAC,CAAC;;QAAAE,CAAC;;;;MAAGC,CAAO;IACbH,CAAC,CAAC;;QAAAE,CAAC;;;;MAAGE,CAAO;IACbJ,CAAC,CAAC;;QAAAK,CAAC;;;;MAAGC,CAAC;IACPN,CAAC,CAAC;;QAAAK,CAAC;;;;MAAGE,CAAC;IACPP,CAAC,CAAU,6BAAC,CAAV;;QAAAQ,OAAO;;;;QAAIF,CAAC;IACdN,CAAC,CAAU,6BAAC,CAAV;;QAAAQ,OAAO;;;;QAAID,CAAC;IACZ,mBAAA;;QAAAF,CAAC;;;;;IAAHL,CAAC,CAAC,CAAA,CAAM,CAAC;IACT,WAAS;;QAAAK,CAAC;;;;;IAAV;IACEI,mBAAAA,QAAE;IAAJT,CAAC,CAAC,CAAA,CAAK,CAAC;IACN,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;SAAM,GAAG;;;;IACT,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;SAAM,KAAK;;;;IACXK,mBAAAA,CAAC;IAAHL,CAAC,CAAC,CAAA,CAAI,CAAC;IACL,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;;SAAM,SAAA,GAAG;;;IACTS,mBAAAA,QAAE;IAAJT,CAAC,CAAC;;;;SAAK,SAAA,GAAG;;;IACVA,CAAC,CAAC;;;;SAAI,SAAA,GAAG;;;IACJ,mBAAA;;;;kBAxCqB,EAAE;;;IAwC5BA,CAAC,CAAC;;;;SAAQ,SAAA,GAAG;;;IACR,mBAAA;;;;kBAzCqB,EAAE;;;IAyC5BA,CAAC,CAAC;;;SAAQ,GAAG;;;;IACR,mBAAA;;;;;;;IAALA,CAAC,CAAC;;;SAAQ,GAAG;;;;IACbA,CAAC,CAAC;;;SAAgB,4BAAA,SAAS;;SAAT,yBAAA,SAAS;;IAC3B,UAAQ;;;SAAkB,4BAAA,SAAS;;SAAT,yBAAA,SAAS;;IAAnC;IAC0B,oBAAA;;;SAAC,4BAAA,SAAS;;SAAT,yBAAA,SAAS;;IAApC,WAAS;;;SAA2C,CAAC,GAAG;;;;IAAxD;IACQM,oBAAAA,OAAC;IAAT,UAAQ;;;SAAY,GAAG;;;;IAAvB;IACQI,oBAAAA,OAAC;IAAT,UAAQ;;;;2BAke8C;;;IAletD;IACQJ,oBAAAA,OAAC;IAAU,oBAAA;;;SAAC,GAAG;;;;IAAvB,UAAQ;;;;2BAie8C;;;IAjetD;IACQA,oBAAAA,OAAC;IAAU,oBAAA;;;SAAC,GAAG;;;;IAAe,oBAAA;;;;2BAgegB;;;IAhetD,UAAQ;;;;;;;IAAR;IACQA,oBAAAA,OAAC;IAAU,oBAAA;;;SAAC,GAAG;;;;IAAe,oBAAA;;;;2BA+dgB;;;IA/dC,oBAAA;;;;;;;IAAvD,UAAQ;;;SAAiE,GAAG;;;;IAA5E;IACAN,CAAC,CAACW,OAAC;IACHX,CAAC,CAACY,OAAC;IACHZ,CAAC,CAACa,OAAC;IACHb,CAAC,CAACc,OAAC;IACHd,CAAC,CAAC;;;;;;;IACF,uBAAqB;;QAAAe,aAAa;;;;;IAAlC;IACmBC,oBAAAA,oBAAc;IAAjC,qBAAmB;;;;;;;IAAnB;IACAhB,CAAC,CAACiB,kBAAY;IACA,oBAAA;;QAAAC,aAAa;;;;;IAA3B,gBAAc;;;SAAoBZ,OAAC,EAAE,CAAC,GAAG;;;;IAAzC;IACuBa,oBAAAA,aAAO;IAA9B,yBAAuB;;;SAAkBb,OAAC;;;;IAA1C","file":"gen_input.py"} \ No newline at end of file diff --git a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py similarity index 77% rename from packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py rename to packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py index 56f5a321f..3f9419eb2 100644 --- a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py +++ b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py @@ -197,7 +197,7 @@ def test(): "safeds.data.tabular.containers.Table.from_csv_file", Table.from_csv_file, [safeds_runner.absolute_path('abc.csv')], - {}, + {"separator": ','}, [safeds_runner.file_mtime('abc.csv')] ) safeds_runner.save_placeholder('a', __gen_a) @@ -205,7 +205,7 @@ def test(): "safeds.data.tabular.containers.Table.from_csv_file", Table.from_csv_file, [safeds_runner.absolute_path('abc.csv')], - {}, + {"separator": ','}, [safeds_runner.file_mtime('abc.csv')] ) __gen_a2 = safeds_runner.memoized_dynamic_call( @@ -225,88 +225,6 @@ def test(): [] ) safeds_runner.save_placeholder('v', __gen_v) - __gen_receiver_12 = __gen_v - __gen_d = safeds_runner.memoized_dynamic_call( - __gen_receiver_12, - "plot_histogram", - [], - {"number_of_bins": 10}, - [] - ) - safeds_runner.save_placeholder('d', __gen_d) - __gen_receiver_13 = __gen_a - __gen_receiver_14 = safeds_runner.memoized_dynamic_call( - __gen_receiver_13, - "get_column", - ['b'], - {}, - [] - ) - __gen_p = safeds_runner.memoized_dynamic_call( - __gen_receiver_14, - "plot_histogram", - [], - {"number_of_bins": 10}, - [] - ) - safeds_runner.save_placeholder('p', __gen_p) - __gen_receiver_15 = __gen_a - __gen_receiver_16 = safeds_runner.memoized_dynamic_call( - __gen_receiver_15, - "get_column", - ['b'], - {}, - [] - ) - __gen_receiver_17 = safeds_runner.memoized_dynamic_call( - __gen_receiver_16, - "plot_histogram", - [], - {"number_of_bins": 10}, - [] - ) - __gen_r = safeds_runner.memoized_dynamic_call( - __gen_receiver_17, - "flip_vertically", - [], - {}, - [] - ) - safeds_runner.save_placeholder('r', __gen_r) - __gen_receiver_18 = __gen_a - __gen_receiver_19 = safeds_runner.memoized_dynamic_call( - __gen_receiver_18, - "get_column", - ['b'], - {}, - [] - ) - __gen_receiver_20 = safeds_runner.memoized_dynamic_call( - __gen_receiver_19, - "plot_histogram", - [], - {"number_of_bins": 10}, - [] - ) - __gen_receiver_21 = safeds_runner.memoized_dynamic_call( - __gen_receiver_20, - "flip_vertically", - [], - {}, - [] - ) - __gen_q = safeds_runner.memoized_dynamic_call( - __gen_receiver_21, - "adjust_contrast", - [1.2], - {}, - [] - ) - safeds_runner.save_placeholder('q', __gen_q) - f(__gen_d) - f(__gen_p) - f(__gen_r) - f(__gen_q) f(safeds_runner.memoized_static_call( "tests.generator.memberAccessWithRunnerIntegration.Outer.Nested.f", Outer.Nested.f, @@ -322,9 +240,9 @@ def test(): [] ) safeds_runner.save_placeholder('nestedInstance', __gen_nestedInstance) - __gen_receiver_22 = __gen_nestedInstance + __gen_receiver_12 = __gen_nestedInstance __gen_nestedResult = safeds_runner.memoized_dynamic_call( - __gen_receiver_22, + __gen_receiver_12, "g", [], {}, @@ -332,24 +250,24 @@ def test(): ) safeds_runner.save_placeholder('nestedResult', __gen_nestedResult) f(__gen_nestedResult) - __gen_receiver_23 = safeds_runner.memoized_static_call( + __gen_receiver_13 = safeds_runner.memoized_static_call( "safeds.data.tabular.transformation.OneHotEncoder", OneHotEncoder, [], - {}, + {"separator": '__'}, [] ) __gen_encoder = safeds_runner.memoized_dynamic_call( - __gen_receiver_23, + __gen_receiver_13, "fit", [__gen_a, ['b']], {}, [] ) safeds_runner.save_placeholder('encoder', __gen_encoder) - __gen_receiver_24 = __gen_encoder + __gen_receiver_14 = __gen_encoder __gen_transformedTable = safeds_runner.memoized_dynamic_call( - __gen_receiver_24, + __gen_receiver_14, "transform", [__gen_a], {}, diff --git a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map new file mode 100644 index 000000000..83900c46f --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input.py.map @@ -0,0 +1 @@ +{"version":3,"sources":["input.sdsdev"],"names":["test","f","g","h","result1","result2","c","a","b","factory","c1","factorynested","nestedinstance","nestedresult","onehotencoder","encoder"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAwDA,IAASA,IAAI;IACTC,CAAC,CAAC;;QAAAC,CAAC;;;;;IACHD,CAAC,CAAC;;QAAAE,CAAC;;;;MAAGC,CAAO;IACbH,CAAC,CAAC;;QAAAE,CAAC;;;;MAAGE,CAAO;IACbJ,CAAC,CAAC;;QAAAK,CAAC;;;;MAAGC,CAAC;IACPN,CAAC,CAAC;;QAAAK,CAAC;;;;MAAGE,CAAC;IACPP,CAAC,CAAU,6BAAC,CAAV;;QAAAQ,OAAO;;;;QAAIF,CAAC;IACdN,CAAC,CAAU,6BAAC,CAAV;;QAAAQ,OAAO;;;;QAAID,CAAC;IACZ,mBAAA;;QAAAF,CAAC;;;;;IAAHL,CAAC,CAAC,CAAA,CAAM,CAAC;IACT,WAAS;;QAAAK,CAAC;;;;;IAAV;IACEI,mBAAAA,QAAE;IAAJT,CAAC,CAAC,CAAA,CAAK,CAAC;IACN,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;SAAM,GAAG;;;;IACT,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;SAAM,KAAK;;;;IACXK,mBAAAA,CAAC;IAAHL,CAAC,CAAC,CAAA,CAAI,CAAC;IACL,mBAAA;;QAAAK,CAAC;;;;;IAAHL,CAAC,CAAC;;;;SAAM,SAAA,GAAG;;;IACTS,mBAAAA,QAAE;IAAJT,CAAC,CAAC;;;;SAAK,SAAA,GAAG;;;IACVA,CAAC,CAAC;;;;SAAI,SAAA,GAAG;;;IACJ,mBAAA;;;;kBAxCqB,EAAE;;;IAwC5BA,CAAC,CAAC;;;;SAAQ,SAAA,GAAG;;;IACR,mBAAA;;;;kBAzCqB,EAAE;;;IAyC5BA,CAAC,CAAC;;;SAAQ,GAAG;;;;IACR,mBAAA;;;;;;;IAALA,CAAC,CAAC;;;SAAQ,GAAG;;;;IACbA,CAAC,CAAC;;;SAAgB,4BAAA,SAAS;;SAAT,yBAAA,SAAS;;IAC3B,UAAQ;;;SAAkB,4BAAA,SAAS;SAAT,aAiBF;SAjBE,yBAAA,SAAS;;IAAnC;IAC0B,oBAAA;;;SAAC,4BAAA,SAAS;SAAT,aAgBH;SAhBG,yBAAA,SAAS;;IAApC,WAAS;;;SAA2C,CAAC,GAAG;;;;IAAxD;IACQM,oBAAAA,OAAC;IAAT,UAAQ;;;SAAY,GAAG;;;;IAAvB;IACAN,CAAC,CAAC;;;;;;;IACF,uBAAqB;;QAAAU,aAAa;;;;;IAAlC;IACmBC,oBAAAA,oBAAc;IAAjC,qBAAmB;;;;;;;IAAnB;IACAX,CAAC,CAACY,kBAAY;IACA,oBAAA;;QAAAC,aAAa;;sBAxCP;;;IAwCpB,gBAAc;;;SAAoBP,OAAC,EAAE,CAAC,GAAG;;;;IAAzC;IACuBQ,oBAAAA,aAAO;IAA9B,yBAAuB;;;SAAkBR,OAAC;;;;IAA1C","file":"gen_input.py"} \ No newline at end of file diff --git a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input_test.py b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input_test.py similarity index 100% rename from packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input_test.py rename to packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/generated/tests/generator/memberAccessWithRunnerIntegration/gen_input_test.py diff --git a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/input.sdsdev b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/input.sdsdev similarity index 89% rename from packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/input.sdsdev rename to packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/input.sdsdev index d983432e5..5e75b683b 100644 --- a/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/member access/input.sdsdev +++ b/packages/safe-ds-lang/tests/resources/generation/python/runner integration/expressions/skip-member access/input.sdsdev @@ -78,10 +78,10 @@ pipeline test { val a = Table.fromCsvFile("abc.csv"); val a2 = Table.fromCsvFile("abc.csv").removeColumns(["u"]); val v = a.getColumn("b"); - val d = v.plotHistogram(); - val p = a.getColumn("b").plotHistogram(); - val r = a.getColumn("b").plotHistogram().flipVertically(); - val q = a.getColumn("b").plotHistogram().flipVertically().adjustContrast(1.2); + val d = v.plot.histogram(); + val p = a.getColumn("b").plot.histogram(); + val r = a.getColumn("b").plot.histogram().flipVertically(); + val q = a.getColumn("b").plot.histogram().flipVertically().adjustContrast(1.2); f(d); f(p); f(r); diff --git a/packages/safe-ds-vscode/src/extension/eda/apis/runnerApi.ts b/packages/safe-ds-vscode/src/extension/eda/apis/runnerApi.ts index 85382f178..e55e55ce3 100644 --- a/packages/safe-ds-vscode/src/extension/eda/apis/runnerApi.ts +++ b/packages/safe-ds-vscode/src/extension/eda/apis/runnerApi.ts @@ -206,7 +206,7 @@ export class RunnerApi { tablePlaceholder + '.getColumn("' + columnName + - '").plotHistogram(); \n' + '").plot.histogram(); \n' ); } @@ -218,7 +218,7 @@ export class RunnerApi { tablePlaceholder + '.getColumn("' + columnName + - '").plotBoxplot(); \n' + '").plot.boxPlot(); \n' ); } @@ -233,9 +233,9 @@ export class RunnerApi { newPlaceholderName + ' = ' + tablePlaceholder + - '.plotLineplot(xColumnName="' + + '.plot.linePlot(xName="' + xAxisColumnName + - '", yColumnName="' + + '", yName="' + yAxisColumnName + '"); \n' ); @@ -252,16 +252,16 @@ export class RunnerApi { newPlaceholderName + ' = ' + tablePlaceholder + - '.plotScatterplot(xColumnName="' + + '.plot.scatterPlot(xName="' + xAxisColumnName + - '", yColumnName="' + + '", yName="' + yAxisColumnName + '"); \n' ); } private sdsStringForCorrelationHeatmap(tablePlaceholder: string, newPlaceholderName: string) { - return 'val ' + newPlaceholderName + ' = ' + tablePlaceholder + '.plotCorrelationHeatmap(); \n'; + return 'val ' + newPlaceholderName + ' = ' + tablePlaceholder + '.plot.correlationHeatmap(); \n'; } //#endregion