Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def my_setup(self, train):
self.p = VectorDataClassificationProblem(train, 0)
self.c = MockClassifier(train, self.p)
def setUp(self):
self.p = VectorDataClassificationProblem(self.train, 0)
self.c = MockClassifier(self.train, self.p)
def main():
# line count
N = 0
for _ in open(IRIS_PATH):
N += 1
testindexes = set(random.sample(xrange(N), N / 10))
dataset = IrisDataset(IRIS_PATH, lambda i: i not in testindexes)
testset = IrisDataset(IRIS_PATH, lambda i: i in testindexes)
problem = VectorDataClassificationProblem(dataset, dataset.target_index)
# Distance without target
problem.distance = lambda x, y: euclidean_vector_distance(x[:-1], y[:-1])
classifiers = {
"K-Nearest Neighbours": KNearestNeighbors,
"Naive Bayes": NaiveBayes,
"Decision Tree": DecisionTreeLearner_Queued,
}
print "Precision:\n"
for name, method in classifiers.iteritems():
classifier = method(dataset, problem)
p = precision(classifier, testset)
print "{:>20} = {:.2}".format(name, p)