Esempio n. 1
0
def LoadModel(model_name="predict_Model"):
    model = None
    rf = ReadCsvFile()
    model = rf.ReadValueFromFile(model_name)
    predict_result = None
    if model:
        # predict_result = model.predict_proba(test_data)
        print "Load Model success!"
    else:
        train_data = rf.ReadTrainFile()
        preProce = PreProcess()
        train_X,train_lab,train_loc_dic = preProce.preProcessTrainData(train_data)
        train_Xc =preProce.getFeatureScaler(train_data)
        model = TrainModel(train_Xc,train_lab)
        # predict_result = model.predict_proba(test_data)
    return model
Esempio n. 2
0
def LoadModel(model_name="predict_Model_new"):
    model = None
    rf = ReadCsvFile()
    try:
        model = rf.ReadValueFromFile(model_name)
        print "Load Model success!"
    except:
        train_data = rf.ReadTrainFile()
        print len(train_data)
        preP = PreProcess()
        train_X,train_lab,loc_dic = preP.preProcessTrainData(train_data)
        train_Xc = preP.getFeatureScaler(train_X)
        print "Train model"
        model = TrainModel(train_Xc,train_lab)
        logging.info("save model")
        wr = WriteResult()
        wr.WriteValueToFile(model,model_name)
    return model
Esempio n. 3
0
def LoadModel(model_name="predict_Model_new"):
    model = None
    rf = ReadCsvFile()
    try:
        model = rf.ReadValueFromFile(model_name)
        print "Load Model success!"
    except:
        train_data = rf.ReadTrainFile()
        print len(train_data)
        preP = PreProcess()
        train_X, train_lab, loc_dic = preP.preProcessTrainData(train_data)
        train_Xc = preP.getFeatureScaler(train_X)
        print "Train model"
        model = TrainModel(train_Xc, train_lab)
        logging.info("save model")
        wr = WriteResult()
        wr.WriteValueToFile(model, model_name)
    return model
Esempio n. 4
0
def main():
    print "Start......"
    rf = ReadCsvFile()
    train_data = rf.ReadTrainFile()
    preP = PreProcess()
    train_X,train_lab,loc_dic = preP.preProcessTrainData(train_data)
    train_Xc = preP.getFeatureScaler(train_X)
    # print "Train model"
    # TrainModel(train_Xc,train_lab)
    # train_lab = None
    # loc_dic = None
    # train_data = None
    # train_X = None
    # train_Xc = None
    # with open(Config.ResultDataPath+"result.csv","w") as fp:
    #     print "清空文件","result.csv"
    model = LoadModel()
    print model
    print "精确率:{0}".format(model.score(train_Xc[2000:3000],train_lab[2000:3000]))
Esempio n. 5
0
def main():
    print "Start......"
    rf = ReadCsvFile()
    train_data = rf.ReadTrainFile()
    preP = PreProcess()
    train_X, train_lab, loc_dic = preP.preProcessTrainData(train_data)
    train_Xc = preP.getFeatureScaler(train_X)
    # print "Train model"
    # TrainModel(train_Xc,train_lab)
    # train_lab = None
    # loc_dic = None
    # train_data = None
    # train_X = None
    # train_Xc = None
    # with open(Config.ResultDataPath+"result.csv","w") as fp:
    #     print "清空文件","result.csv"
    model = LoadModel()
    print model
    print "精确率:{0}".format(
        model.score(train_Xc[2000:3000], train_lab[2000:3000]))