Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
# 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()
# 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
)
# 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:")
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()
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()
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)
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)
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
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
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:")