Skip to content

🧪 NeuralNetworkClassifier

A NeuralNetworkClassifier is a neural network that is used for classification tasks.

Parameters:

Name Type Description Default
inputConversion InputConversion<D, F> to convert the input data for the neural network -
layers List<Layer> a list of layers for the neural network to learn -

Type parameters:

Name Upper Bound Description Default
D Any? The type of the full dataset. It's the input to fit and the output of predict. -
F Any? The type of the features. It's the input to predict. -
Stub code in NeuralNetworkClassifier.sdsstub

@Experimental
class NeuralNetworkClassifier<D, in F>(
    @PythonName("input_conversion") inputConversion: InputConversion<D, F>,
    layers: List<Layer>,
) {
    /**
     * Whether the classifier is fitted.
     */
    @PythonName("is_fitted") attr isFitted: Boolean

    /**
     * Load a pretrained model from a [Huggingface repository](https://huggingface.co/models/).
     *
     * @param huggingfaceRepo the name of the huggingface repository
     *
     * @result pretrainedModel the pretrained model as a NeuralNetworkClassifier
     */
    @Pure
    @PythonName("from_pretrained_model")
    static fun fromPretrainedModel(
        @PythonName("huggingface_repo") huggingfaceRepo: String
    ) -> pretrainedModel: NeuralNetworkClassifier<Any, Any>

    /**
     * Train the neural network with given training data.
     *
     * The original model is not modified.
     *
     * @param trainData The data the network should be trained on.
     * @param epochCount The number of times the training cycle should be done.
     * @param batchSize The size of data batches that should be loaded at one time.
     * @param learningRate The learning rate of the neural network.
     * @param callbackOnBatchCompletion Function used to view metrics while training. Gets called after a batch is completed with the index of the
     * last batch and the overall loss average.
     * @param callbackOnEpochCompletion Function used to view metrics while training. Gets called after an epoch is completed with the index of the
     * last epoch and the overall loss average.
     *
     * @result fittedClassifier The trained Model
     *
     * @example
     * pipeline example {
     *     // TODO
     * }
     */
    @Pure
    fun fit(
        @PythonName("train_data") trainData: D,
        @PythonName("epoch_count") const epochCount: Int = 25,
        @PythonName("batch_size") const batchSize: Int = 1,
        @PythonName("learning_rate") learningRate: Float = 0.001,
        @PythonName("callback_on_batch_completion") callbackOnBatchCompletion: (param1: Int, param2: Float) -> () = (param1, param2) {},
        @PythonName("callback_on_epoch_completion") callbackOnEpochCompletion: (param1: Int, param2: Float) -> () = (param1, param2) {}
    ) -> fittedClassifier: NeuralNetworkClassifier<D, F> where {
        epochCount >= 1,
        batchSize >= 1
    }

    /**
     * Make a prediction for the given test data.
     *
     * The original Model is not modified.
     *
     * @param testData The data the network should predict.
     *
     * @result prediction The given test_data with an added "prediction" column at the end
     *
     * @example
     * pipeline example {
     *     // TODO
     * }
     */
    @Pure
    fun predict(
        @PythonName("test_data") testData: F
    ) -> prediction: D
}

isFitted

Whether the classifier is fitted.

Type: Boolean

fit

Train the neural network with given training data.

The original model is not modified.

Parameters:

Name Type Description Default
trainData D The data the network should be trained on. -
epochCount Int The number of times the training cycle should be done. 25
batchSize Int The size of data batches that should be loaded at one time. 1
learningRate Float The learning rate of the neural network. 0.001
callbackOnBatchCompletion (param1: Int, param2: Float) -> () Function used to view metrics while training. Gets called after a batch is completed with the index of the last batch and the overall loss average. (param1, param2) {}
callbackOnEpochCompletion (param1: Int, param2: Float) -> () Function used to view metrics while training. Gets called after an epoch is completed with the index of the last epoch and the overall loss average. (param1, param2) {}

Results:

Name Type Description
fittedClassifier NeuralNetworkClassifier<D, F> The trained Model

Examples:

pipeline example {
    // TODO
}
Stub code in NeuralNetworkClassifier.sdsstub

@Pure
fun fit(
    @PythonName("train_data") trainData: D,
    @PythonName("epoch_count") const epochCount: Int = 25,
    @PythonName("batch_size") const batchSize: Int = 1,
    @PythonName("learning_rate") learningRate: Float = 0.001,
    @PythonName("callback_on_batch_completion") callbackOnBatchCompletion: (param1: Int, param2: Float) -> () = (param1, param2) {},
    @PythonName("callback_on_epoch_completion") callbackOnEpochCompletion: (param1: Int, param2: Float) -> () = (param1, param2) {}
) -> fittedClassifier: NeuralNetworkClassifier<D, F> where {
    epochCount >= 1,
    batchSize >= 1
}

predict

Make a prediction for the given test data.

The original Model is not modified.

Parameters:

Name Type Description Default
testData F The data the network should predict. -

Results:

Name Type Description
prediction D The given test_data with an added "prediction" column at the end

Examples:

pipeline example {
    // TODO
}
Stub code in NeuralNetworkClassifier.sdsstub

@Pure
fun predict(
    @PythonName("test_data") testData: F
) -> prediction: D

fromPretrainedModel

Load a pretrained model from a Huggingface repository.

Parameters:

Name Type Description Default
huggingfaceRepo String the name of the huggingface repository -

Results:

Name Type Description
pretrainedModel NeuralNetworkClassifier<Any, Any> the pretrained model as a NeuralNetworkClassifier
Stub code in NeuralNetworkClassifier.sdsstub

@Pure
@PythonName("from_pretrained_model")
static fun fromPretrainedModel(
    @PythonName("huggingface_repo") huggingfaceRepo: String
) -> pretrainedModel: NeuralNetworkClassifier<Any, Any>