Пример #1
0
def handwritingClassTest(train_X, train_y, test_X, test_y):
    clf = knn.KNNClassifier(k=3)
    len_test = len(test_y)
    error_count = 0.0
    results = clf.classify(test_X, train_X, train_y)
    arr_res = np.array(results) - np.array(test_y)
    for elem in arr_res:
        error_count += np.abs(elem)
    error_rate = error_count / len_test
    print error_rate
    return error_rate
Пример #2
0
    def __init__(self, norm_type="Normalization", iterations=5, base_classifier="SVM"):
        self.iterations = iterations
        self.norm_type = norm_type
        self.prediction = None
        self.probability = None
        self.classifier_set = None

        if base_classifier == "SVM":
            self.base_classifier = SVM.SVMClassifier()
        elif base_classifier == "KNN":
            self.base_classifier = KNN.KNNClassifier()
        elif base_classifier == "DecisionTree":
            self.base_classifier = DecisionTree.DecisionTreeClassifier()
        elif base_classifier == "Logistic":
            self.base_classifier = Logistic.LogisticRegressionClassifier()
        elif base_classifier == "Perceptron":
            self.base_classifier = Perceptron.PerceptronClassifier()
Пример #3
0
            [float(param1),
             float(param2),
             float(param3),
             float(param4)])
        xTest = np.vstack([xTest, newRow])
        newTrue = np.array([classification])
        trues = np.vstack([trues, newTrue])

    count = count + 1

k = int(sys.argv[1])

timingFile = open(r"KNN/KNNTiming.txt", "a")

# Call our python KNN implementation and time classification
ourClass = KNN.KNNClassifier(xTrain, yTrain, k)

ourStart = time.time()

ourPred = ourClass.classify(xTest)

ourEnd = time.time()

ourTime = (ourEnd - ourStart) * 1000000

# Call the scikit KNN implementation and time classification
scikitImp = neighbors.KNeighborsClassifier(k)

sciStart = time.time()

scikitImp.fit(xTrain, yTrain)