Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(testData, testGroundTruth)
# Retrieve the data from input file
testDataSource.loadDataBlock(mergedData)
# Create an algorithm object to predict multi-class SVM values
algorithm = multi_class_classifier.prediction.Batch(nClasses)
algorithm.parameter.training = trainingBatch
algorithm.parameter.prediction = predictionBatch
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model,
trainingResult.get(classifier.training.model))
# Predict multi-class SVM values
# and retrieve Result class from classifier.prediction
predictionResult = algorithm.compute() # Retrieve the algorithm results
def printResults():
testGroundTruth = FileDataSource(testGroundTruthFileName,
DataSourceIface.doAllocateNumericTable,
DataSourceIface.doDictionaryFromContext)
testGroundTruth.loadDataBlock()
printNumericTables(testGroundTruth.getNumericTable(),
predictionResult.get(classifier.prediction.prediction),
"Ground truth",
"Classification results",
"NaiveBayes classification results (first 20 observations):",
20,
interval=15,
flt64=False)
# Create algorithm objects to predict values of the Naive Bayes model with the fastCSR method
algorithm = prediction.Batch(nClasses, method=prediction.fastCSR)
# Pass the test data to the algorithm
parts_list = testData.collect()
for _, (csr, homogen) in parts_list:
deserialized_csr = deserializeCSRNumericTable(csr)
algorithm.input.setTable(classifier.prediction.data, deserialized_csr)
algorithm.input.setModel(classifier.prediction.model, model)
# Compute the prediction results
predictionResult = algorithm.compute()
# Retrieve the results
return predictionResult.get(classifier.prediction.prediction)
def testModel():
global predictionResult
# Create Numeric Tables for testing data
testData = createSparseTable(testDatasetFileName)
# Create an algorithm object to predict SVM values
algorithm = prediction.Batch()
algorithm.parameter.kernel = kernel
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
# Predict SVM values
algorithm.compute()
# Retrieve the algorithm results
predictionResult = algorithm.getResult()
)
# Create Numeric Tables for testing data and labels
testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(testData, testGroundTruth)
# Retrieve the data from input file
testDataSource.loadDataBlock(mergedData)
# Create algorithm objects for LogitBoost prediction with the default method
algorithm = prediction.Batch(nClasses)
# Pass the testing data set and trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model, model)
# Compute prediction results and retrieve algorithm results
# (Result class from classifier.prediction)
predictionResult = algorithm.compute()
DataSourceIface.doDictionaryFromContext
)
# Create Numeric Tables for testing data and labels
testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(testData, testGroundTruth)
# Retrieve the data from input file
testDataSource.loadDataBlock(mergedData)
# Create an algorithm object to predict Naive Bayes values
algorithm = prediction.Batch(nClasses)
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
# Predict Naive Bayes values (Result class from classifier.prediction)
predictionResult = algorithm.compute() # Retrieve the algorithm results
# Create Numeric Tables for testing data and labels
testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
mergedData = MergedNumericTable(testData, testGroundTruth)
# Retrieve the data from input file
testDataSource.loadDataBlock(mergedData)
# Create algorithm objects for decision tree classification prediction with the default method
algorithm = prediction.Batch()
# Pass the testing data set and trained model to the algorithm
#print("Number of columns: {}".format(testData.getNumberOfColumns()))
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model, model)
# Compute prediction results and retrieve algorithm results
# (Result class from classifier.prediction)
predictionResult = algorithm.compute()
def testModel():
global predictionResult
# Create Numeric Tables for testing data
testData = createSparseTable(testDatasetFileName)
# Create an algorithm object to predict multi-class SVM values
algorithm = multi_class_classifier.prediction.Batch(nClasses)
algorithm.parameter.training = trainingAlg
algorithm.parameter.prediction = predictionAlg
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testData)
algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
# Predict multi-class SVM values and retrieve the algorithm results
# (Result class from classifier.prediction)
predictionResult = algorithm.compute()
def testModel():
global predictionResult
# Retrieve the input data from a .csv file
testDataTable = createSparseTable(testDatasetFileName)
# Create an algorithm object to predict values of the Naive Bayes model
algorithm = prediction.Batch(nClasses, method=prediction.fastCSR)
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(classifier.prediction.data, testDataTable)
algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
# Predict values of the Naive Bayes model
# Result class from classifier.prediction
predictionResult = algorithm.compute()