def run(self): logging.debug('Start running with name: {0}, count: {1}'.format( self.name, self.count)) client = Classifier('127.0.0.1', 9199, 'test') for i in range(0, self.count): client.save(self.name + str(i)) logging.debug('Finished running')
def setUp(self): self.config = { "method": "AROW", "converter": { "string_filter_types": {}, "string_filter_rules": [], "num_filter_types": {}, "num_filter_rules": [], "string_types": {}, "string_rules": [{ "key": "*", "type": "str", "sample_weight": "bin", "global_weight": "bin" }], "num_types": {}, "num_rules": [{ "key": "*", "type": "num" }] }, "parameter": { "regularization_weight": 1.001 } } TestUtil.write_file('config_classifier.json', json.dumps(self.config)) self.srv = TestUtil.fork_process('classifier', port, 'config_classifier.json') try: self.cli = Classifier(host, port, "name") except: TestUtil.kill_process(self.srv) raise
def main(): args = parse_options() client = Classifier('127.0.0.1', args.port, 'test', 0) for i in range(0, 10000): client.do_mix() if not i % 100: status = client.get_status() for node in status.keys(): print '\t'.join([str(i), node, status[node]['RSS']])
def main(): args = parse_options() client = Classifier('127.0.0.1', args.port, 'test', 0) d = Datum() # Learn same data rand = random.randint(0, 1) d.add_number('key', 1.0 if rand else 2.0) print client.classify([d]) print client.get_labels()
def main(): args = parse_options() client = Classifier('127.0.0.1', args.port, 'test', 0) for i in range(0, 1000000): d = Datum() # Learn same data rand = random.randint(0, 1) d.add_number('key', 1.0 if rand else 2.0) ld = LabeledDatum('Pos' if rand else 'Neg', d) client.train([ld]) if not i % 10000: print 'train ' + str(i) + ' data'
#!/usr/bin/env python from jubatus.classifier.client import Classifier for idx in xrange(1, 50): client = Classifier('127.0.0.1', 9199, 'test') for i in xrange(1, 10001): client.do_mix() if not i % 1000: status = client.get_status() for node in status.keys(): print '\t'.join( [str((idx * 10000) + i), node, status[node]['RSS']])
client.train(train_data) result = client.classify([predict_data[0]]) predicted = max(result[0], key=lambda x: x.score).label if answer == predicted: print('correct', end="\t") else: print('wrong', end="\t") print(answer, predicted, result, sep="\t") if __name__ == '__main__': try: exclude = sys.argv[3] training = sys.argv[2] port = int(sys.argv[1]) except: sys.stderr.write( "Usage: jubatus.py port_number training.tsv exclude name\n") sys.exit(7) localhost = '127.0.0.1' if len(sys.argv) > 4: name = sys.argv[4] else: name = 'Coded by Kohji' client = Classifier(localhost, port, name) # connect to Jubatus train_and_predict(client, training)
import argparse import socket from jubatus.classifier.client import Classifier parser = argparse.ArgumentParser() parser.add_argument("-n", "--name", help="set the name of the file to be saved") parser.add_argument("--host", help="set the host address") parser.add_argument("--port", help="set the port number") args = parser.parse_args() print(args) host_ip = args.host if args.host else socket.gethostbyname(socket.gethostname()) port = args.port if args.port else 9199 client = Classifier(host_ip, port, '') if args.name: client.save(args.name) print("file saved at /tmp of the "+host_ip+" unless you specified output path with -d/--datadir when you started server process.") else: print("[Error] specify the model's name to be saved!")
result = {} result[0] = '' result[1] = 0 for res in estm: if prob == None or res.score > prob: ans = res.label prob = res.score result[0] = ans result[1] = prob return result if __name__ == '__main__': options, remainder = parse_args() classifier = Classifier(options.server_ip, options.server_port, options.name, 10.0) print classifier.get_config() print classifier.get_status() for line in open('train.dat'): label, file = line[:-1].split(',') dat = open(file).read() datum = Datum({"message": dat}) classifier.train([LabeledDatum(label, datum)]) print classifier.get_status() print classifier.save("tutorial") print classifier.load("tutorial")
#!/usr/bin/env python from jubatus.classifier.client import Classifier client = Classifier('127.0.0.1', 9000, 'test', 0) client.do_mix()