Create classification dataset (from Python code)

Create a classification dataset from Python code and store the result as a pickle file.

Usage:

  1. Open the algorithm from the processing toolbox.

  2. Modify the python script to match your needs, then click run.

    ../../../../_images/classpython.png
  3. The output classification dataset will be listed under Models in your Data Sources panel.

Parameters

Code [string]

Python code specifying the classification dataset.

Default:

from enmapboxprocessing.typing import Number, List, Category, ClassifierDump

# specify categories and feature names
categories: List[Category] = [
    Category(value=1, name='class 1', color='#ff0000'),
    Category(value=2, name='class 2', color='#00ff00')
]
features: List[str] = ['Feature 1', 'Feature 2', 'Feature 3']

# specify features X as 2d-array with shape (samples, features)
X: List[List[Number]] = [
    [1, 2, 3],
    [4, 5, 6]
]
# specify targets y as 2d-array with shape (samples, 1)
y: List[List[int]] = [
    [1], [2]
]

Outputs

Output dataset [fileDestination]

Pickle file destination.

Command-line usage

>qgis_process help enmapbox:CreateClassificationDatasetFromPythonCode:

----------------
Arguments
----------------

code: Code
    Default value:  from enmapboxprocessing.typing import Number, List, Category, ClassifierDump

# specify categories and feature names
categories: List[Category] = [
    Category(value=1, name='class 1', color='#ff0000'),
    Category(value=2, name='class 2', color='#00ff00')
]
features: List[str] = ['Feature 1', 'Feature 2', 'Feature 3']

# specify features X as 2d-array with shape (samples, features)
X: List[List[Number]] = [
    [1, 2, 3],
    [4, 5, 6]
]
# specify targets y as 2d-array with shape (samples, 1)
y: List[List[int]] = [
    [1], [2]
]

    Argument type:  string
    Acceptable values:
            - String value
            - field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field
            - expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression
outputClassificationDataset: Output dataset
    Argument type:  fileDestination
    Acceptable values:
            - Path for new file

----------------
Outputs
----------------

outputClassificationDataset: <outputFile>
    Output dataset