How to use the daal.algorithms.classifier.training function in daal

To help you get started, we’ve selected a few daal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github intel / daal / examples / python / source / svm / svm_two_class_csr_batch.py View on Github external
)

    # Create numeric table for training data
    trainData = createSparseTable(trainDatasetFileName)

    # Retrieve the data from the input file
    trainLabelsDataSource.loadDataBlock()

    # Create an algorithm object to train the SVM model
    algorithm = training.Batch()

    algorithm.parameter.kernel = kernel
    algorithm.parameter.cacheSize = 40000000

    # Pass a training data set and dependent values to the algorithm
    algorithm.input.set(classifier.training.data, trainData)
    algorithm.input.set(classifier.training.labels, trainLabelsDataSource.getNumericTable())

    # Build the SVM model
    trainingResult = algorithm.compute()
github intel / daal / samples / python / mpi / sources / multinomial_naive_bayes_csr_distributed_mpi.py View on Github external
# Retrieve the input data from a .csv file
    trainDataTable = createSparseTable(trainDatasetFileNames[rankId])

    # Initialize FileDataSource to retrieve the input data from a .csv file
    trainLabelsSource = FileDataSource(trainGroundTruthFileNames[rankId],
                                       DataSourceIface.doAllocateNumericTable,
                                       DataSourceIface.doDictionaryFromContext)

    # Retrieve the data from input files
    trainLabelsSource.loadDataBlock()

    # Create an algorithm object to train the Naive Bayes model based on the local-node data
    localAlgorithm = training.Distributed(step1Local, nClasses, method=training.fastCSR)

    # Pass a training data set and dependent values to the algorithm
    localAlgorithm.input.set(classifier.training.data, trainDataTable)
    localAlgorithm.input.set(classifier.training.labels, trainLabelsSource.getNumericTable())

    # Train the Naive Bayes model on local nodes
    pres = localAlgorithm.compute()

    # Serialize partial results required by step 2
    dataArch = InputDataArchive()
    pres.serialize(dataArch)

    nodeResults = dataArch.getArchiveAsArray()

    # Transfer partial results to step 2 on the root node
    serializedData = comm.gather(nodeResults)

    if rankId == MPI_ROOT:
        # Create an algorithm object to build the final Naive Bayes model on the master node
github intel / daal / examples / python / source / logistic_regression / log_reg_binary_dense_batch.py View on Github external
)

    # Create Numeric Tables for training data and labels
    trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
    trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
    mergedData = MergedNumericTable(trainData, trainGroundTruth)

    # Retrieve the data from the input file
    trainDataSource.loadDataBlock(mergedData)

    # Create an algorithm object to train the logistic regression model
    algorithm = training.Batch(nClasses)

    # Pass the training data set and dependent values to the algorithm
    algorithm.input.set(classifier.training.data, trainData)
    algorithm.input.set(classifier.training.labels, trainGroundTruth)

    # Train the logistic regression model and retrieve the results of the training algorithm
    trainingResult = algorithm.compute()
    model = trainingResult.get(classifier.training.model)
    printNumericTable(model.getBeta(), "Logistic Regression coefficients:")
github intel / daal / examples / python / source / boosting / adaboost_dense_batch.py View on Github external
DataSourceIface.doDictionaryFromContext
    )

    # Create Numeric Tables for training data and labels
    trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
    trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
    mergedData = MergedNumericTable(trainData, trainGroundTruth)

    # Retrieve the data from the input file
    trainDataSource.loadDataBlock(mergedData)

    # Create an algorithm object to train the AdaBoost model
    algorithm = training.Batch()

    # Pass the training data set and dependent values to the algorithm
    algorithm.input.set(classifier.training.data, trainData)
    algorithm.input.set(classifier.training.labels, trainGroundTruth)

    # Train the AdaBoost model and retrieve the results of the training algorithm
    trainingResult = algorithm.compute()
github intel / daal / examples / python / source / boosting / brownboost_dense_batch.py View on Github external
DataSourceIface.notAllocateNumericTable,
        DataSourceIface.doDictionaryFromContext
    )
    # Create Numeric Tables for training data and labels
    trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
    trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
    mergedData = MergedNumericTable(trainData, trainGroundTruth)

    # Retrieve the data from the input file
    trainDataSource.loadDataBlock(mergedData)

    # Create an algorithm object to train the BrownBoost model
    algorithm = training.Batch()

    # Pass the training data set and dependent values to the algorithm
    algorithm.input.set(classifier.training.data, trainData)
    algorithm.input.set(classifier.training.labels, trainGroundTruth)

    # Train the BrownBoost model and retrieve the results of the training algorithm
    trainingResult = algorithm.compute()
github intel / daal / samples / python / spark / sources / spark_NaiveBayesDense.py View on Github external
def mapper(tup):
        key, val = tup
        t1, t2 = val

        # Create an algorithm to train the Naive Bayes model on local nodes
        algorithm = training.Distributed(step1Local, nClasses)

        # Set the input data on local nodes
        deserialized_t1 = deserializeNumericTable(t1)
        deserialized_t2 = deserializeNumericTable(t2)
        algorithm.input.set(classifier.training.data, deserialized_t1)
        algorithm.input.set(classifier.training.labels, deserialized_t2)

        # Train the Naive Bayes model on local nodes
        pres = algorithm.compute()
        serialized_pres = serializeNumericTable(pres)

        return (key, serialized_pres)
    return trainDataRDD.map(mapper)
github intel / daal / samples / python / mpi / sources / multinomial_naive_bayes_dense_distributed_mpi.py View on Github external
DataSourceIface.doDictionaryFromContext)

    trainLabelsSource = FileDataSource(trainGroundTruthFileNames[rankId],
                                       DataSourceIface.doAllocateNumericTable,
                                       DataSourceIface.doDictionaryFromContext)

    # Retrieve the data from input files
    trainDataSource.loadDataBlock()
    trainLabelsSource.loadDataBlock()

    # Create an algorithm object to train the Naive Bayes model based on the local-node data
    localAlgorithm = training.Distributed(step1Local, nClasses)

    # Pass a training data set and dependent values to the algorithm
    localAlgorithm.input.set(classifier.training.data, trainDataSource.getNumericTable())
    localAlgorithm.input.set(classifier.training.labels, trainLabelsSource.getNumericTable())

    # Train the Naive Bayes model on local nodes
    pres = localAlgorithm.compute()

    # Serialize partial results required by step 2
    dataArch = InputDataArchive()
    pres.serialize(dataArch)

    nodeResults = dataArch.getArchiveAsArray()

    # Transfer partial results to step 2 on the root node
    serializedData = comm.gather(nodeResults)

    if rankId == MPI_ROOT:
        # Create an algorithm object to build the final Naive Bayes model on the master node
        masterAlgorithm = training.Distributed(step2Master, nClasses)
github intel / daal / examples / python / source / naive_bayes / mn_naive_bayes_csr_distr.py View on Github external
trainData[i] = createSparseTable(trainDatasetFileNames[i])

        # Initialize FileDataSource to retrieve the input data from a .csv file
        trainLabelsSource = FileDataSource(
            trainGroundTruthFileNames[i], DataSourceIface.doAllocateNumericTable,
            DataSourceIface.doDictionaryFromContext
        )

        # Retrieve the data from an input file
        trainLabelsSource.loadDataBlock(nTrainVectorsInBlock)

        # Create an algorithm object to train the Naive Bayes model on the local-node data
        localAlgorithm = training.Distributed(step1Local, nClasses, method=training.fastCSR)

        # Pass a training data set and dependent values to the algorithm
        localAlgorithm.input.set(classifier.training.data,   trainData[i])
        localAlgorithm.input.set(classifier.training.labels, trainLabelsSource.getNumericTable())

        # Build the Naive Bayes model on the local node
        # Set the local Naive Bayes model as input for the master-node algorithm
        masterAlgorithm.input.add(training.partialModels, localAlgorithm.compute())

    # Merge and finalize the Naive Bayes model on the master node
    masterAlgorithm.compute()
    trainingResult = masterAlgorithm.finalizeCompute()  # Retrieve the algorithm results
github intel / daal / examples / python / source / naive_bayes / mn_naive_bayes_dense_distr.py View on Github external
trainDatasetFileNames[i], DataSourceIface.notAllocateNumericTable,
            DataSourceIface.doDictionaryFromContext
        )
        # Create Numeric Tables for training data and labels
        trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
        trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
        mergedData = MergedNumericTable(trainData, trainGroundTruth)

        # Retrieve the data from the input file
        trainDataSource.loadDataBlock(mergedData)

        # Create an algorithm object to train the Naive Bayes model on the local-node data
        localAlgorithm = training.Distributed(step1Local, nClasses)

        # Pass a training data set and dependent values to the algorithm
        localAlgorithm.input.set(classifier.training.data,   trainData)
        localAlgorithm.input.set(classifier.training.labels, trainGroundTruth)

        # Build the Naive Bayes model on the local node and
        # Set the local Naive Bayes model as input for the master-node algorithm
        masterAlgorithm.input.add(training.partialModels, localAlgorithm.compute())

    # Merge and finalize the Naive Bayes model on the master node
    masterAlgorithm.compute()
    trainingResult = masterAlgorithm.finalizeCompute()  # Retrieve the algorithm results
github intel / daal / examples / python / source / logistic_regression / log_reg_binary_dense_batch.py View on Github external
DataSourceIface.doDictionaryFromContext
    )

    # Create Numeric Tables for training data and labels
    trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
    trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
    mergedData = MergedNumericTable(trainData, trainGroundTruth)

    # Retrieve the data from the input file
    trainDataSource.loadDataBlock(mergedData)

    # Create an algorithm object to train the logistic regression model
    algorithm = training.Batch(nClasses)

    # Pass the training data set and dependent values to the algorithm
    algorithm.input.set(classifier.training.data, trainData)
    algorithm.input.set(classifier.training.labels, trainGroundTruth)

    # Train the logistic regression model and retrieve the results of the training algorithm
    trainingResult = algorithm.compute()
    model = trainingResult.get(classifier.training.model)
    printNumericTable(model.getBeta(), "Logistic Regression coefficients:")