Ejemplo n.º 1
0
def get_reslut(d_to_str, time, storeId, pred):
    args = dict()
    args['storeId'] = storeId
    args['starttime'] = time
    args['preds'] = pred  # 人流客流特征参数 'traffic'/'customer'
    args['day'] = d_to_str
    args_pref_features = data_helper.data_loader(train=False, args=args)
    model = joblib.load('train_model.m')
    return model.predict([args_pref_features])
Ejemplo n.º 2
0
def run():
    args = dict()
    args['storeId'] = 5
    args['starttime'] = 11
    args['preds'] = 'customer'  #人流客流特征参数 'traffic'/'customer'
    args['day'] = '2017-08-08'
    args_pref_features = data_helper.data_loader(train=False, args=args)
    model = joblib.load('train_model.m')
    print model.predict([args_pref_features])
Ejemplo n.º 3
0
def get_reslut(d_to_str, time, storeId, pred,model):
    args = dict()
    args['storeId'] = storeId
    args['starttime'] = time
    args['preds'] = pred  # 人流客流特征参数 'traffic'/'customer'
    args['day'] = d_to_str
    try :
        args_pref_features = data_helper.data_loader(train=False, args=args)  
        res=model.predict([args_pref_features])
    except BaseException as e:
        app.logger.error(e)
    return res
Ejemplo n.º 4
0
def train_task():
    #load train data
    train_X_data, train_y_data = data_helper.data_loader()

    #split the train data and test data
    X_train, X_test, y_train, y_test = train_test_split(train_X_data, train_y_data, \
    test_size=0.25, random_state=33)

    # new model and train model
    GBR = GradientBoostingRegressor()
    GBR = GBR.fit(X_train, y_train)

    #save model
    joblib.dump(GBR, "train_model.m")
Ejemplo n.º 5
0
def train_task():
    #load train data
    try:
        train_X_data, train_y_data, storeId = data_helper.data_loader()
    except BaseException as e:
        logger.error(e)

    #保存下来所有店铺id
    pkl.dump(storeId, open('storeId.pkl', 'wb'))

    #train model
    try:
        GBR = GradientBoostingRegressor()
        GBR = GBR.fit(train_X_data, train_y_data)
    except BaseException as e:
        logger.error(e)

    #save model
    joblib.dump(GBR, "train_model.m")
Ejemplo n.º 6
0
        'The results dir including log, model, vocabulary and some images.(default=./results/)'
    )

    parser.add_argument('--data_path',
                        default='data/baidu_95.csv',
                        type=str,
                        help='data path')
    parser.add_argument('--vocab_save_dir',
                        default='data/',
                        type=str,
                        help='data path')

    parser.add_argument('--workers',
                        default=32,
                        type=int,
                        help='use worker count')

    params = parser.parse_args()
    print('Parameters:', params, '\n')

    if not os.path.exists(params.results_dir):
        os.mkdir(params.results_dir)
    timestamp = time.strftime("%Y-%m-%d-%H-%M", time.localtime(time.time()))
    os.mkdir(os.path.join(params.results_dir, timestamp))
    os.mkdir(os.path.join(params.results_dir, timestamp, 'log/'))

    X_train, X_test, y_train, y_test = data_loader(params)

    train(X_train, X_test, y_train, y_test, params,
          os.path.join(params.results_dir, 'TextCNN.h5'))
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.cross_validation import train_test_split
from sklearn.externals import joblib
import data_helper
# update mysql.user set authentication_string=password("123456") where user="******";
# UPDATE mysql.user SET Password=PASSWORD("123456")  WHERE User='******' and Host='localhost';


if __name__ == '__main__':
	#load train data
	# df=data_helper.data_loader()
	# print df
	train_X_data,train_y_data=data_helper.data_loader()
	
	#split the train data and test data
	X_train, X_test, y_train, y_test = train_test_split(train_X_data, train_y_data, \
	test_size=0.25, random_state=33)

	# new model and train model
	GBR=GradientBoostingRegressor()
	GBR=GBR.fit(X_train, y_train)

	#save model
	joblib.dump(GBR, "train_model.m")

	pred=GBR.predict(X_test) 

	#test the model score
	result=zip(y_test,pred)
	print "real_value\tpred_value"
Ejemplo n.º 8
0
import numpy as np
from sklearn.linear_model import SGDRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.svm import SVR

from data_helper import data_loader, mae, model_saver

train_x, train_y, test_x, test_y = data_loader()
train_y = np.array(train_y)
test_y = np.array(test_y)
train_y_in, train_y_out = train_y[:, 0], train_y[:, 1]
test_y_in, test_y_out = test_y[:, 0], test_y[:, 1]


def svr_model():
    svr_rbf = SVR(kernel='rbf', C=100, gamma=0.1, epsilon=.1, verbose=True)
    svr_rbf.fit(train_x, train_y_in)
    pre_y = svr_rbf.predict(test_x)
    print(mae(np.array(pre_y), test_y_in))


def sgd_model():
    sgd = SGDRegressor(loss='huber',
                       max_iter=1000000,
                       learning_rate='invscaling',
                       eta0=20,
                       verbose=True)
    sgd.fit(train_x, train_y_in)
    pre_y = sgd.predict(test_x)
    print(mae(np.array(pre_y), test_y_in))