示例#1
0
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()
示例#2
0
def testModel(testData, model):

    # Create algorithm objects to predict values of the Naive Bayes model with the defaultDense method
    algorithm = prediction.Batch(nClasses)

    # Pass the test data to the algorithm
    parts_List = testData.collect()
    for key, (t1, t2) in parts_List:
        deserialized_t1 = deserializeNumericTable(t1)
        algorithm.input.setTable(classifier.prediction.data, deserialized_t1)

    algorithm.input.setModel(classifier.prediction.model, model)

    # Compute the prediction results
    predictionResult = algorithm.compute()

    # Retrieve the results
    return predictionResult.get(classifier.prediction.prediction)
示例#3
0
def testModel(testData, model):

    # 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)
示例#4
0
def testModel():
    global predictionResult

    # Initialize FileDataSource to retrieve the input data from a .csv file
    testDataSource = FileDataSource(testDatasetFileName,
                                    DataSourceIface.doAllocateNumericTable,
                                    DataSourceIface.doDictionaryFromContext)

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

    # Create an algorithm object to predict values of the Naive Bayes model
    algorithm = prediction.Batch(nClasses)

    # Pass a testing data set and the trained model to the algorithm
    algorithm.input.setTable(classifier.prediction.data,  testDataSource.getNumericTable())
    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()
示例#5
0
## Testing
# Initialize FileDataSource<CSVFeatureManager> to retrieve the test data from a .csv file
testDataSource = FileDataSource(testDatasetFileName,
                                DataSourceIface.notAllocateNumericTable,
                                DataSourceIface.doDictionaryFromContext)

# 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 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)
T_dense_test = np.array([])
for i in range(0, 100):
    t = time.process_time()
    predictionResult = algorithm.compute()  # Retrieve the algorithm results
    t = time.process_time() - t
    T_dense_test = np.append(T_dense_test, t)
    del t
print("Median Prediction Time: ", np.median(T_denrse_test), " seconds\n")
示例#6
0
# Initialize FileDataSource<CSVFeatureManager> to retrieve the test data from a .csv file
testDataSource = FileDataSource(testDatasetFileName,
                                DataSourceIface.notAllocateNumericTable,
                                DataSourceIface.doDictionaryFromContext)

# 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 an algorithm object to predict Naive Bayes values
algorithm_test = prediction.Batch(nClasses)

# Pass a testing data set and the trained model to the algorithm
algorithm_test.input.setTable(classifier.prediction.data, testData)

n_experiments = 1

t_train_100 = np.zeros(n_experiments)
t_train_500 = np.zeros(n_experiments)
t_train_1000 = np.zeros(n_experiments)
t_train_2000 = np.zeros(n_experiments)
t_train_5000 = np.zeros(n_experiments)

test_acc_100 = np.array([])
test_acc_500 = np.array([])
test_acc_1000 = np.array([])