• 大小: 0.6M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: 其他  

资源简介

sh-demand-forecast-alg.zip

资源截图

代码片段和文件信息

#!/usr/bin/python
# -*- coding: UTF-8 -*-
“““
# @Time    : 2019/11/6 10:57
# @Author  : peng.wang
# @Email   : WangPeng4@sfmail.sf-express.com
# @FileName: main.py
# @ProjectName :sh-demand-forecast-alg
“““
import os
import yaml
import warnings
import pandas as pd
import numpy as np
from core import data_handle
from model.stlforcator_train import STLForecastorTrain
from utils.misc import Logger
from utils.util import GetExternalData

warnings.filterwarnings(“ignore“)
log = Logger(log_path=os.path.join(os.path.dirname(os.path.dirname(__file__)) ‘log‘)).logger

with open(os.path.join(os.path.dirname(__file__) ‘config/config.yaml‘)) as fp:
    config = yaml.load(fp)


def main(model_name):
    “““
    main function for run the offline training and validation process output the train error
    if the cross-validation selected then give the cross-validation results
    :param model_name:
    :return:
    “““
    # load data
    id = ‘2703‘
    data_path = config[‘DATA‘][‘data_path‘]
    time_column = config[‘DATA‘][‘time_column‘]
    id_column = config[‘DATA‘][‘id_column‘]
    target_column = config[“DATA“][‘target_column‘]

    ExternalData = GetExternalData(start_date=‘2018-01-01‘ end_date=‘2019-12-31‘)
    df_external = ExternalData.get_external()

    data_ins = data_handle.DataHandler(data_path=data_path time_column=time_column id_column=id_column
                                       target_column=target_column multiple_sku=True logger=log)
    data_dict = data_ins.df_by_id
    df = data_dict[id]
    df = df[df[time_column] >= ‘2018-01-01‘]
    df.reset_index(inplace=True drop=True)

    for model in model_name:
        forecastor = STLForecastorTrain(logger=log)
        forecastor.model_setup(model_name=model save_model=True feature_selection=False)
        forecastor.data_setup(df target_column id_column time_column with_external=True external_df=df_external
                              external_column=[‘holiday‘] forecast_period=‘1week‘)
        result_dict = forecastor.build_model(save_feature=True)
        # log.info(‘result_df:‘)
        # log.info(result_df)

        result_df = result_dict[‘train_result‘]
        result_df[‘time‘] = result_dict[‘time‘]
        result_df.to_csv(‘train_results.csv‘)
        result_dict[‘feature‘].to_csv(‘feature.csv‘)


if __name__ == “__main__“:
    main(model_name=[‘XGB‘])


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-12-04 10:49  sh-demand-forecast-alg\
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\
     文件          39  2019-12-04 10:44  sh-demand-forecast-alg\.gitignore
     文件         323  2019-12-04 10:44  sh-demand-forecast-alg\.git\config
     文件          73  2019-12-04 10:44  sh-demand-forecast-alg\.git\description
     文件          23  2019-12-04 10:44  sh-demand-forecast-alg\.git\HEAD
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\
     文件         478  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\applypatch-msg.sample
     文件         896  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\commit-msg.sample
     文件        3327  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\fsmonitor-watchman.sample
     文件         189  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\post-update.sample
     文件         424  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\pre-applypatch.sample
     文件        1638  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\pre-commit.sample
     文件        1348  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\pre-push.sample
     文件        4898  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\pre-rebase.sample
     文件         544  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\pre-receive.sample
     文件        1492  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\prepare-commit-msg.sample
     文件        3610  2019-12-04 10:44  sh-demand-forecast-alg\.git\hooks\update.sample
     文件        1863  2019-12-04 10:44  sh-demand-forecast-alg\.git\index
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\info\
     文件         240  2019-12-04 10:44  sh-demand-forecast-alg\.git\info\exclude
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\
     文件         213  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\HEAD
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\heads\
     文件         213  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\heads\master
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\remotes\
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\remotes\origin\
     文件         213  2019-12-04 10:44  sh-demand-forecast-alg\.git\logs\refs\remotes\origin\HEAD
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\objects\
     目录           0  2019-12-04 10:44  sh-demand-forecast-alg\.git\objects\02\
............此处省略165个文件信息

评论

共有 条评论