Ejemplo n.º 1
0
 def setUp(self):
     self.srv = TestUtil.fork_process("regression", port)
     self.cli = regression(host, port)
     method = "PA"
     self.converter = '{\n"string_filter_types":{}, \n"string_filter_rules":[], \n"num_filter_types":{}, \n"num_filter_rules":[], \n"string_types":{}, \n"string_rules":\n[{"key":"*", "type":"space", \n"sample_weight":"bin", "global_weight":"bin"}\n], \n"num_types":{}, \n"num_rules":[\n{"key":"*", "type":"num"}\n]\n}'
     cd = config_data(method, self.converter)
     self.cli.set_config("name", cd)
Ejemplo n.º 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(","))
                string_values = [["aspect", aspect]]
                num_values = [
                    ["distance", float(distance)],
                    ["space", float(space)],
                    ["age", float(age)],
                    ["stair", float(stair)],
                ]
                d = datum(string_values, num_values)
                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)
        string_values = [["aspect", str(myhome["aspect"])]]
        num_values = [
            ["distance", float(myhome["distance"])],
            ["space", float(myhome["space"])],
            ["age", float(myhome["age"])],
            ["stair", float(myhome["stair"])],
        ]
        d = datum(string_values, num_values)
        analyze_data = [d]
        result = client.estimate("", analyze_data)

        print "rent ....", round(result[0], 1)
Ejemplo n.º 3
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(','))
                string_values = [['aspect', aspect]]
                num_values = [['distance', float(distance)],
                              ['space', float(space)], ['age',
                                                        float(age)],
                              ['stair', float(stair)]]
                d = datum(string_values, num_values)
                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)
        string_values = [['aspect', str(myhome['aspect'])]]
        num_values = [['distance', float(myhome['distance'])],
                      ['space', float(myhome['space'])],
                      ['age', float(myhome['age'])],
                      ['stair', float(myhome['stair'])]]
        d = datum(string_values, num_values)
        analyze_data = [d]
        result = client.estimate('', analyze_data)

        print 'rent ....', round(result[0], 1)
Ejemplo n.º 4
0
  def setUp(self):
    self.config = {
        "method": "PA",
        "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')
    self.cli = regression(host, port)
Ejemplo n.º 5
0
    dest     = 'analyzedata'
  )
  parser.add_argument(
    '-t',
    help     = 'train data file (CSV)',
    metavar  = 'FILE',
    dest     = 'traindata'
  )
  return parser.parse_args()


if __name__ == '__main__':

  args = parse_options()

  client = regression('localhost', 9199)
  method = "PA"
  converter = """
    {
      \"string_filter_types\" : {},
      \"string_filter_rules\" : [],
      \"num_filter_types\" : {},
      \"num_filter_rules\" : [],
      \"string_types\" : {},
      \"string_rules\" : [
        {
          \"key\" : \"aspect\",
          \"type\" : \"str\",
          \"sample_weight\" : \"bin\",
          \"global_weight\" : \"bin\"
        }