Exemplo n.º 1
0
    def metric(self):
        totalTimer = Timer()
        with totalTimer:
            model = mlpy.Golub()
            model.learn(self.data_split[0], self.data_split[1])

            if len(self.data) >= 2:
                predictions = model.pred(self.data[1])

        metric = {}
        metric["runtime"] = totalTimer.ElapsedTime()

        if len(self.data) == 3:
            confusionMatrix = Metrics.ConfusionMatrix(self.data[2],
                                                      predictions)
            metric['ACC'] = Metrics.AverageAccuracy(confusionMatrix)
            metric['MCC'] = Metrics.MCCMultiClass(confusionMatrix)
            metric['Precision'] = Metrics.AvgPrecision(confusionMatrix)
            metric['Recall'] = Metrics.AvgRecall(confusionMatrix)
            metric['MSE'] = Metrics.SimpleMeanSquaredError(
                self.data[2], predictions)

        return metric
Exemplo n.º 2
0
 def BuildModel(self, data, labels):
   # Create and train the classifier.
   golub = mlpy.Golub()
   golub.learn(data, labels)
   return golub
Exemplo n.º 3
0


directory = raw_input("What directory are the XML files located:\n")
regexParse = raw_input("How would you like to parse the words, leave it blank if you would like to parse by whitespace:\n")
if(regexParse == ""):
	regexParse = None
[vocab,indexToWord,fullDataPoints] = parseDataPoints(directory,regexParse)
[X,Y] = packageData(fullDataPoints,regexParse,vocab, indexToWord)


testModel(mlpy.Perceptron(alpha=0.1, thr=0.05, maxiters=1000), X, Y, "Perceptron")
testModel(mlpy.ElasticNetC(lmb=0.01, eps=0.001),X,Y, "ElasticNet")
testModel(mlpy.LibLinear(solver_type='l2r_l2loss_svc_dual', C=1), X, Y, "LibLinear")
testModel(mlpy.DLDA(delta=0.1), X, Y, "DLDA")
testModel(mlpy.Golub(), X, Y, "Golub")
testModel(mlpy.Parzen(),X,Y,"Parzen")
testModel(mlpy.KNN(2),X,Y,"KNN")
testModel(mlpy.ClassTree(),X,Y,"Classification Tree")
testModel(mlpy.MaximumLikelihoodC(),X,Y,"Maximum Likelihood Classifer")










Exemplo n.º 4
0
    elnet = mlpy.ElasticNetC(lmb=0.01, eps=0.001)
    elnet.learn(x, y)
    test = elnet.pred(xcontrol)  # test points
    print 'Elastic Net: %.1f percent predicted' % (
        100 * len(test[test == ycontrol]) / len(test))
    dic['elnet'].append(100 * len(test[test == ycontrol]) / len(test))

    da = mlpy.DLDA(delta=0.1)
    da.learn(x, y)
    test = da.pred(xcontrol)  # test points
    print 'DLDA: %.1f percent predicted' % (100 * len(test[test == ycontrol]) /
                                            len(test))
    dic['da'].append(100 * len(test[test == ycontrol]) / len(test))

    golub = mlpy.Golub()
    golub.learn(x, y)
    test = golub.pred(xcontrol)  # test points
    print 'Golub: %.1f percent predicted' % (
        100 * len(test[test == ycontrol]) / len(test))
    dic['golub'].append(100 * len(test[test == ycontrol]) / len(test))

    knn = mlpy.KNN(k=7)
    knn.learn(x, y)
    test = knn.pred(xcontrol)  # test points
    print 'KNN: %.1f percent predicted' % (100 * len(test[test == ycontrol]) /
                                           len(test))
    dic['knn'].append(100 * len(test[test == ycontrol]) / len(test))

    tree = mlpy.ClassTree(stumps=0, minsize=100)
    tree.learn(x, y)