Giter VIP home page Giter VIP logo

grey_model's Introduction

2022.3.30更新

  • 将灰色预测模型移动至GreyForecasting文件夹中
  • 新增了GreyIncidence文件夹,已更新部分灰色关联度模型,后续将继续更新

对部分代码进行了重写

如需使用GM(1,1)模型、GM(1,N)模型、GM(1,N|sin)幂模型,请使用文件GreyForecasting中的gm11.pygm1n.pypgm1nsin.py代码

灰色预测模型

  • 灰色多变量周期幂模型

    • 针对Grey_Model.py中最小二乘部分的一些错误进行了修改

    • 针对Grey_Model.pypgm1nsin模型代码进行了重写与优化

    • 使pgm1nsin模型可以自行选择哪一变量进行幂指数运算或周期正弦运算

具体使用方法如下:

定义GM(1,N|sin)幂模型

参数设置:
sys_data:系统行为序列
rel_p_data:相关因素序列(指数因素)
rel_s_data:相关因素序列(周期因素)
predict_step:预测步长,会截取上面三组数据的最后predict_step行数据作为预测
gamma:幂指数
p:周期系数
使用方法:
1.实例化对象 model = pgm1nsin(sys_data=sys_data,rel_p_data=rel_p_data,rel_s_data=rel_s_data)\n
2.训练模型  model.fit()\n
3.进行预测  model.predict
  • 灰色单变量预测模型
    • 对代码进行了重写与优化
model = gm11(data,predstep=2)
fitted_values = model.fit()
predict_values = model.predict()
  • 灰色多变量预测模型

    • 更新了GM(1,N)模型,建议使用连续型情况的,离散形式的我自己做的时候发现拟合误差比较大,后面应该需要使用另外一种离散模式
    • 参数解释可以通过model.__doc__查看
    使用方法:
    data = pd.read_excel('Power.xlsx', sheet_name='Sheet3',header=None)
    system_data = data.iloc[:, 0]
    relevent_data = data.iloc[:, 1:]
    
    model = gm1n(relevent_data, system_data,predict_step=3,discrete=False)
    fit_values = model.fit()
    predict_values = model.predict()
    
    • 在使用灰色多变量模型进行预测时,相关因素序列应该比系统因素序列长predict_step,可以看Power.xlsx中Sheet3表格示例数据,其中第一列是系统行为变量,第二第三列是相关因素
  • 灰色多变量幂模型

    • 参考*王正新.灰色多变量GM(1,N)幂模型及其应用[J].系统工程理论与实践,2014,34(09):2357-2363.*编写的代码
    • 后续会按照灰色多变量周期幂模型的格式重构代码,当前如需使用,请使用Grey_Model_v2.py中的pgm1ns模型,令其p=1
model = pgm1ns()
model.fit(data, predict_step=2, gama=[1.7254, 0.86642], p=0)
values = model.get_all_sim_val()
  • 测试数据

Power.xlsx文件中保存着江苏省季度用电量、温度、GDP等数据,用于对模型进行测试

用电量 GDP 温度
1170.66 1727.29 7.80
1238.95 2380.31 21.49
1331.82 2112.61 25.55
1271.11 2600.54 11.96

灰色关联模型

当前更新了三个关联模型,分别是:

  • 邓聚龙教授的绝对关联模型

  • 叶莉莉等在[叶莉莉,谢乃明,罗党.累积时滞非线性ATNDGM(1,N)模型构建及应用[J].系统工程理论与实践,2021,41(09):2414-2427.]中构建的关联模型

  • 王俊杰在[王俊杰. 时滞性与周期性的灰建模技术研究及其在雾霾治理中的应用[D].南京航空航天大学,2018.DOI:10.27239/d.cnki.gnhhu.2018.000204.]中构建的等周期关联模型

  • 灰色绝对关联模型

代码在Greyinc.py

data_in = mean_process(data_in)
data_out = mean_process(data_out)
inc_mat = gery_inci(data_in, data_in)
  • 叶莉莉等的灰色关联模型(主要用于寻找时滞期)

代码在Time_lag_model.py

# 支持相关因素与系统因素都有多个,返回一个矩阵,行是相关因素,列是系统因素
data_input = data.iloc[14:,1:9]
data_output = data.iloc[14:,9:]
inc_mat = time_lag_inc(data_input,data_output,3)
  • 等周期关联模型

代码在GreyDelayTrendModeltl.py

 # 仅支持一个相关因素与一个系统因素,返回不同趋势t下的点关联度,行为不同趋势,矩阵最后一列是该趋势下的平均关联度
 data1 = mean_process(data.iloc[:, 0:1])
 data2 = mean_process(data.iloc[:, 1:2])
 a = gdtep_t(data1, data2)

grey_model's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

grey_model's Issues

关于GM(1,N)的一些疑问

1.请问power.xlsx文件的sheet3是否是针对本GM(1,N)代码的?我好像在pycharm上运行时课运行但无数据出现
2.请问本GM(1,N)代码需要输入的数据行、列分别代表着什么的?第几行(列)代表着所需预测的数据?第几行(列)代表着影响结果数据的数据,sheet3没有讲明白、本人水平也不够看不太懂实在不好意思......

GM(1,N)

作者你好,首先感谢你的贡献。接下来我有几个疑问想向您请教一下。
1.由于我python版本问题,所以你文件中的xlsx文件均被我用csv格式文件打开,请问这对整体代码在处理数据是否有影响呢?
2.我运行GM(1,1)模型的时候,打印出来 print(fit_values),print(predict_values),但结果却显示[1170.66, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],请问这是什么原因呢?
3.我目前想利用灰色预测模型来进行碳排放,我目前有2000到2020年的数据,请问我可以利用这个模型预测2020-2030每一年的数据吗?如果可以请赐教,对于新手小白真的非常重要,也期待你的回复。

gm(1,n)预测值疑问

楼主,小白求教,我运行你的代码结果如下
fit_values:[20556.0, 8288.479987319675, 11105.662939219459, 13364.70443357066, 15010.55616216264, 18024.062450851052]
predict_values:[51233.43876822575, 73618.88341107947, 92433.72966214709]

这个predict_values应该是未来三期的预测值,可是明显不是递增,这是为何?
另请问fit_values是指过去六期的拟合值吗?这个为何跟原值不同?
感谢楼主答疑

我把自己的数据带入,结果fit_values出现负值,这是为何?

关于gm1n预测结果的问题

楼主你好,我刚开始学习做python的灰色模型,请问下,你的GM1N模型最后的预测函数为空,这部分是需要自己填写吗?我做的是一个腐蚀模型,不太清楚这部分代码的内容,还请大佬解惑

GM(1,n)的问题

作者你好。我想问一下,用gm(1,n)代码运行,特征序列是8个数,两个自变序列,建立模型输出的拟合值为什么只有5个,不应该是8个吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.