def run(self): S = loader.get_S() scorer = Scorer() for _ in xrange(10000): keys = self.weights_dict.keys() shuffle(keys) for k in keys: sc = -float("inf") best_dev = .02 base = self.weights_dict[k] for dev in [.02, 0, -.02]: self.weights_dict[k] = base + dev w = self.weights_dict.values() S_prime = [Si * wi for Si, wi in zip(S, w)] S_prime = reduce(lambda x, y: x + y, S_prime) classifications = [] for i in xrange(10000): argmax = np.argmax(S_prime[i, :]) ide = column_to_code[argmax] classifications.append((row_to_bizid[i], ide)) loader.write_rows_algo_classified_set(classifications) pred, total, _ = scorer.scoreClassifications() score = pred / total if score > sc: sc = score best_dev = dev print sc self.weights_dict[k] = base + best_dev w = self.weights_dict.values() S_prime = [Si * wi for Si, wi in zip(S, w)] S_prime = reduce(lambda x, y: x + y, S) classifications = [] for i in xrange(10000): ide = column_to_code[np.argmax(S_prime[i, :])] classifications.append((row_to_bizid[i], ide)) loader.write_rows_algo_classified_set(classifications) pred, total, _ = scorer.scoreClassifications() score = pred / total if score > sc: sc = score best_dev = dev print sc print self.weights_dict
def run(self): S = loader.get_S() scorer = Scorer() for _ in xrange(10000): keys = self.weights_dict.keys() shuffle(keys) for k in keys: sc = -float("inf") best_dev = .02 base = self.weights_dict[k] for dev in [.02, 0, -.02]: self.weights_dict[k] = base + dev w = self.weights_dict.values() S_prime = [Si * wi for Si, wi in zip(S, w)] S_prime = reduce(lambda x, y: x + y, S_prime) classifications = [] for i in xrange(10000): argmax = np.argmax(S_prime[i, :]) ide = column_to_code[argmax] classifications.append( (row_to_bizid[i], ide) ) loader.write_rows_algo_classified_set(classifications) pred , total , _ = scorer.scoreClassifications() score = pred / total if score > sc: sc = score best_dev = dev print sc self.weights_dict[k] = base + best_dev w = self.weights_dict.values() S_prime = [Si * wi for Si, wi in zip(S, w)] S_prime = reduce(lambda x, y: x + y, S) classifications = [] for i in xrange(10000): ide = column_to_code[np.argmax(S_prime[i, :])] classifications.append( (row_to_bizid[i], ide) ) loader.write_rows_algo_classified_set(classifications) pred , total , _ = scorer.scoreClassifications() score = pred / total if score > sc: sc = score best_dev = dev print sc print self.weights_dict
def classify(self, implement_rules=True, use_training_data=True): classifications = [] S = loader.get_S() S = [Si * wi for Si, wi in zip(S, self.weights_dict.values())] S = reduce(lambda x, y: x + y, S) for i in xrange(10000): bizid = row_to_bizid[i] code = self.ruleBasedClassification(bizid) if use_training_data: code = self.hand_classified_set.get(bizid) if code is None or not implement_rules: score = np.max(S[i, :]) if score > self.threshhold: code = column_to_code[np.argmax(S[i, :])] else: code = 'None' # no guess classifications.append((row_to_bizid[i], code)) return classifications
def classify(self, implement_rules = True, use_training_data=True): classifications = [] S = loader.get_S() S = [Si * wi for Si, wi in zip(S, self.weights_dict.values())] S = reduce(lambda x, y: x + y, S) for i in xrange(10000): bizid = row_to_bizid[i] code = self.ruleBasedClassification(bizid) if use_training_data: code = self.hand_classified_set.get(bizid) if code is None or not implement_rules: score = np.max(S[i, :]) if score > self.threshhold: code = column_to_code[np.argmax(S[i, :])] else: code = 'None' # no guess classifications.append( (row_to_bizid[i], code) ) return classifications