if DUMP_FEATURES: trainFeaturesExtractor.DumpFeaturesToTxt(trainExportFileName) testFeaturesExtractor.DumpFeaturesToTxt(testExportFileName) if (CLASSIFIER): # The serialization file to save the features modelSerializationFile = ".\\Classifier\\Output\classifier_model.bin" # Start the Classifier: #--------------------- if (SVM_CLASSIFIER): classifier = Classifier(modelSerializationFile, 'SVM', trainFeaturesExtractor.features, trainFeaturesExtractor.labels, testFeaturesExtractor.features, testFeaturesExtractor.labels) if not LOAD_MODEL: # Train classifier.Train() classifier.SaveModel() else: classifier.LoadModel() # Test labels, acc, val = classifier.Test() # Build the confusion matrix mConfusionMatrix, mNormalConfusionMatrix, vNumTrainExamplesPerClass, vAccuracyPerClass, nOverallAccuracy = classifier.BuildConfusionMatrix( testFeaturesExtractor.labels, labels) print(mConfusionMatrix)
classifier.SaveModel() ################## INDEPENDENT PROCESS TEST ################################# # Load language model from the the serialization file languageModelSerializationFile which was saved in training testLanguageModel = LanguageModel(configFileLanguageModel, stopWordsFileName, languageModelSerializationFile, linksDBFile, datasetBuilder.trainSet) testLanguageModel.LoadModel() # Extract features testFeaturesExtractor = FeaturesExtractor(configFileFeaturesExtractor, testFeaturesSerializationFile, testLabelsSerializationFile, testLanguageModel, datasetBuilder.testSet) testFeaturesExtractor.ExtractNumTfFeatures() # Load classifier testClassifier = Classifier(configFileClassifier, modelSerializationFile, trainFeaturesExtractor.features, trainFeaturesExtractor.labels, testFeaturesExtractor.features, testFeaturesExtractor.labels) testClassifier.LoadModel() labels, acc, val = testClassifier.Test() # Build the confusion matrix mConfusionMatrix, mNormalConfusionMatrix, vNumTrainExamplesPerClass, vAccuracyPerClass, nOverallAccuracy = classifier.BuildConfusionMatrix( testFeaturesExtractor.labels, labels) print(mConfusionMatrix)