def ball_only_classifier(circles, color_image, bonus_radius): model = svmlight.read_model("./output/best_single_cup_model_for_ball") ff = find_features() # TODO: fix label = 0 best_classification = 0.5 best_circle = None best_circle_pixels = None for c in circles[:6]: pixels, circle = find_pixels(c, color_image, bonus_radius) # create features for that circle features = ff.generate_features(pixels, label) features = parse_one_line(features) print features # run the classifier on that circle classification = svmlight.classify(model, [features]) print classification if classification[0] > best_classification: best_classification = classification best_circle = [c] best_circle_pixels = pixels # make a decision about whether that circle is circly enough # cv2.imshow("Image processed", circle) # cv2.waitKey() # for the strict form of the classifier, I require that all of the detected circles # are in fact circles. other classifiers may be more lenient return best_circle, best_classification, best_circle_pixels
def prepare_data(self): self._make_documents() self._append_all_words() self.word_features = list(nltk.FreqDist( self.all_words_list).keys())[:self.feature_number] self.feature_sets = [(find_features(rev, self.word_features), category) for (rev, category) in self.documents_list] random.shuffle(self.feature_sets)
def simple_classifier(circles, color_image, bonus_radius): model = svmlight.read_model("./output/best_single_cup_model") ff = find_features() # TODO: fix label = 0 new_circles = [] for c in circles[:6]: circle = find_pixels(c, color_image, bonus_radius) new_circles.append(circle) # create features for that circle features = ff.generate_features(circle[0], label) features = parse_one_line(features) print features # run the classifier on that circle classification = svmlight.classify(model, [features]) print classification # make a decision about whether that circle is circly enough # cv2.imshow("Image processed", circle) # cv2.waitKey() # for the strict form of the classifier, I require that all of the detected circles # are in fact circles. other classifiers may be more lenient return new_circles
def sentiment(text, word_features, voted_classifier): feats = find_features(text, word_features) return voted_classifier.classify(feats), \ voted_classifier.confidence(feats)