Example #1
0
    def setUp(self):
        self.config = {
            "method": "PA1",
            "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": {
                "sensitivity": 0.1,
                "regularization_weight": 3.402823e+38
            }
        }

        TestUtil.write_file('config_regression.json', json.dumps(self.config))
        self.srv = TestUtil.fork_process('regression', port,
                                         'config_regression.json')
        try:
            self.cli = Regression(host, port, "name")
        except:
            TestUtil.kill_process(self.srv)
            raise
Example #2
0
def main():
  args = parse_options()

  client = Regression('127.0.0.1', 9199, '')

  # train
  num = 0
  if args.traindata:
    with open(args.traindata, 'r') as traindata:
      for data in traindata:

        # skip comments
        if not len(data) or data.startswith('#'):
          continue
        num += 1

        rent, distance, space, age, stair, aspect = map(str.strip, data.strip().split(','))
        d = Datum({
            'aspect': aspect,
            'distance': float(distance),
            'space': float(space),
            'age': float(age),
            'stair': float(stair) })
        train_data = [[float(rent), d]]

        # train
        client.train(train_data)

    # print train number
    print 'train ...', num

  # anaylze
  with open(args.analyzedata, 'r') as analyzedata:
    myhome = yaml.load(analyzedata)
    d = Datum({
        'aspect': str(myhome['aspect']),
        'distance': float(myhome['distance']),
        'space': float(myhome['space']),
        'age': float(myhome['age']),
        'stair': float(myhome['stair'])
        })
    analyze_data = [d]
    result = client.estimate(analyze_data)

    print 'rent ....', round(result[0], 1)