def callSuitable(mlalgo, v2): """use and evaluate the selected Machine Learning algorithm""" global X, Y, XT, YT if mlalgo == 'Decision Tree': model = models.DTModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'Naive Bayes': model = models.NBModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'SVM': model = models.SVMModel(X, Y, XT, YT, v2) model.start() else: model = models.KNNModel(X, Y, XT, YT, v2) model.start()
def callSuitable(mlalgo, v2): #evaluate the selected Machine Learning algorithm global X, Y, XT, YT if mlalgo == 'Decision Tree': model = models.DTModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'Naive Bayes': model = models.NBModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'SVM': model = models.SVMModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'K Nearest Neighbours': model = models.KNNModel(X, Y, XT, YT, v2) model.start() elif mlalgo == 'Logistic Regression': model = models.LogModel(X, Y, XT, YT, v2) model.start() else: model = models.ANNModel(X, Y, XT, YT, v2) model.start()
def loadModel(modelName, fileName=None): """load the modelName ML model and test the accuracy""" global X, Y, XT, YT mlalgo = modelName if mlalgo == 'Decision Tree': model = models.DTModel(X, Y, XT, YT) model.start() elif mlalgo == 'Naive Bayes': model = models.NBModel(X, Y, XT, YT) model.start() elif mlalgo == 'SVM': model = models.SVMModel(X, Y, XT, YT) model.start() elif mlalgo == 'K Nearest Neighbours': model = models.KNNModel(X, Y, XT, YT) model.start() elif mlalgo == 'Logistic Regression': model = models.LogModel(X, Y, XT, YT) model.start() else: model = models.ANNModel(X, Y, XT, YT) model.start()
reduced_features.append(feature_vector) reduced_labels.append(label) class_counts[label] += 1 reduced_features = torch.stack(reduced_features) return reduced_features, reduced_labels @staticmethod def _reduce_random(features: torch.Tensor, labels, reduction=0.2): """ Sample the features at random. :param features: Training features. :param labels: Training labels. :param reduction: Proportion to reduce to. :return: Reduced features and labels. """ num_features = features.shape[0] idxs = np.random.randint(low=0, high=num_features, size=int(reduction * num_features)) reduced_features = features[idxs] reduced_labels = labels[idxs] return reduced_features, reduced_labels if __name__ == "__main__": print("Creating LDA model") svm_model = models.SVMModel("svm_alexnet256_poly8") print("Creating feature extractor") trainer = FeatureTrainer(AlexNet256()) trainer.train(svm_model)