首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在我的环境中自动创建更多的模型,同时更改3个参数?

如何在我的环境中自动创建更多的模型,同时更改3个参数?
EN

Stack Overflow用户
提问于 2021-07-02 12:06:20
回答 1查看 35关注 0票数 1

一个完全可复制的例子。

代码语言:javascript
运行
AI代码解释
复制
library(forecast)
date = seq(as.Date("2019/01/01"), by = "month", length.out = 48)

productB = rep("B",48)
productB = rep("B",48)
productA = rep("A",48)
productA = rep("A",48)

subproducts1=rep("1",48)
subproducts2=rep("2",48)
subproductsx=rep("x",48)
subproductsy=rep("y",48)

b1 <- c(rnorm(30,5), rep(0,18))
b2 <- c(rnorm(30,5), rep(0,18))
b3 <-c(rnorm(30,5), rep(0,18))
b4 <- c(rnorm(30,5), rep(0,18))

创建了下面的数据

代码语言:javascript
运行
AI代码解释
复制
dfone <- data.frame("date"= rep(date,4),
            "product"= c(rep(productB,2),rep(productA,2)),
            "subproduct"= 
c(subproducts1,subproducts2,subproductsx,subproductsy),
            "actuals"= c(b1,b2,b3,b4))

export_df <- split(dfone[1:4], dfone[3])

基于独特子产品的数据帧的创建

代码语言:javascript
运行
AI代码解释
复制
dummy_list <- split(dfone[1:4], dfone[3]) %>% lapply( function(x) 
x[(names(x) %in% c("date", "actuals"))])
dummy_list <-  lapply(dummy_list, function(x) { x["date"] <- NULL; x })


list_dfs <- list()
for (i in 1:length(unique(dfone$subproduct))) {
  #assign(paste0("df", i), as.data.frame(dummy_list[[i]]))
  list_dfs <-append(list_dfs,dummy_list[[i]])
}

combined_dfs <- Reduce(function(x, y) merge(x, y, all = TRUE,  
by='date'), list(list_dfs))

创建时间序列

代码语言:javascript
运行
AI代码解释
复制
list_ts <- lapply(list_dfs, function(t) 
ts(t,start=c(2019,1),end=c(2021,6), frequency = 12)) %>%
  lapply( function(t) ts_split(t,sample.out=(0.2*length(t))))    # 
creates my train test split
list_ts <- do.call("rbind", list_ts)  #Creates a list of time series

有个问题。这不会给我超过9种型号。例如,我想要一个n1 =.1 n2=.99和n3= .3的模型,这样我们就有了9种以上的模型。

代码语言:javascript
运行
AI代码解释
复制
n1 <- seq(0.1, 0.99, by = 0.1)
n2 <- seq(0.1, 0.99, by = 0.1)
n3 <- seq(0.1, 0.99, by = 0.1)

out<- lapply(seq_along(n1), function(i) {
   cw_triple_holtwinters_additive <- lapply(list_ts[1: 
(length(list_ts)/2)], function(x) 
       forecast::forecast(ses(x,h=24,alpha = 
n1[i],beta=n2[i],gamma=n3[i])))
    cw_triple_holtwinters_additive <- 
 lapply(cw_triple_holtwinters_additive, "[", "mean")
  assign(paste0("cw_triple_holtwinters_additive", i), 
cw_triple_holtwinters_additive, envir = .GlobalEnv)
 cw_triple_holtwinters_additive})

附加问题:对于order=c(1,1,1)和order=c(0,1,0),我是否可以创建类似这些值的列表,并同时遍历它们,就像Akrun的解决方案一样?

代码语言:javascript
运行
AI代码解释
复制
cw_seasonal_autoregressive_integratedmovingaverage1 <- lapply(list_ts[1: 
(length(list_ts)/2)], function(x)
 forecast::forecast(arima(x,order=c(1,1,1),seasonal=list(order=c(0,1,0),
period=12)) ,h=24))

cw_seasonal_autoregressive_integratedmovingaverage1 <- 
lapply(cw_seasonal_autoregressive_integratedmovingaverage1, "[",  
c("mean"))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-02 12:10:15

我们可以使用expand.grid来获得所有的组合

代码语言:javascript
运行
AI代码解释
复制
dat_n <- expand.grid(n1 = n1, n2= n2, n3 = n3) 

然后,我们遍历“dat_n”的行序列。

代码语言:javascript
运行
AI代码解释
复制
out<- lapply(seq_len(nrow(dat_n)), function(i) {
   cw_triple_holtwinters_additive <- lapply(list_ts[1: 
(length(list_ts)/2)], function(x) 
       forecast::forecast(ses(x,h=24,alpha = 
dat_n$n1[i],beta=dat_n$n2[i],gamma=dat_n$n3[i])))
    cw_triple_holtwinters_additive <- 
 lapply(cw_triple_holtwinters_additive, "[", "mean")
  assign(paste0("cw_triple_holtwinters_additive", i), 
cw_triple_holtwinters_additive, envir = .GlobalEnv)
 cw_triple_holtwinters_additive})

-checking

代码语言:javascript
运行
AI代码解释
复制
 ls(pattern = "cw_triple")
  [1] "cw_triple_holtwinters_additive1"   "cw_triple_holtwinters_additive10"  "cw_triple_holtwinters_additive100" "cw_triple_holtwinters_additive101"
  [5] "cw_triple_holtwinters_additive102" "cw_triple_holtwinters_additive103" "cw_triple_holtwinters_additive104" "cw_triple_holtwinters_additive105"
  [9] "cw_triple_holtwinters_additive106" "cw_triple_holtwinters_additive107" "cw_triple_holtwinters_additive108" "cw_triple_holtwinters_additive109"
 [13] "cw_triple_holtwinters_additive11"  "cw_triple_holtwinters_additive110" "cw_triple_holtwinters_additive111" "cw_triple_holtwinters_additive112"
 [17] "cw_triple_holtwinters_additive113" "cw_triple_holtwinters_additive114" "cw_triple_holtwinters_additive115" "cw_triple_holtwinters_additive116"
 [21] "cw_triple_holtwinters_additive117" 
...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68230752

复制
相关文章
Facebook 推送通知 Linkshim 绕过
在浏览和查找facebook漏洞时,我不小心发现了这个 facebook 推送通知链接
Khan安全团队
2022/01/21
1.2K0
Element NavMenu 默认展示一个菜单的子菜单,点击其它菜单会折叠的解决方法
遇到一个问题:NavMenu设置默认展开一个菜单,但是点击另一个菜单的子菜单赋值时会折叠起来 。
tianyawhl
2020/03/03
6.8K0
实现一个简单的类似不蒜子的PV统计器
内部的放到gitlab pages的博客,需要统计PV,不蒜子不能准确统计,原因在于gitlab的host设置了strict-origin-when-cross-origin, 导致不蒜子不能正确获取referer,从而PV只能统计到网站的PV。
JadePeng
2021/12/04
5660
mybatis中的动态sql表现为_MybatisPlus
Mybatis如何分页查询?Mysql中可以使用limit语句,但limit并不是标准SQL中的,如果是其它的数据库,则需要使用其它语句。MyBatis提供了RowBounds类,用于实现分页查询。RowBounds中有两个数字,offset和limit。
全栈程序员站长
2022/11/09
1.1K0
mybatis中的动态sql表现为_MybatisPlus
在鼠标点击的位置 ,添加一个div ,类似手表右键菜单
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> New Document </title> <script src="styles/default/js/jquery-2.1.0.min.js"></script> </head> <style type="text/css"> .modle { width: 100px; cursor: pointer;
用户7705674
2021/09/23
1.6K0
Ant Design Pro 中 点击子菜单的时候,其他菜单不自动收起来
记录一波自己在这段时间碰到的一个Ant Design Pro 的坑:  每次点击菜单都会将其他菜单自动收起来,导致一系列的用户体验不佳。
TimothyJia
2022/12/10
1.6K0
Android-SubMenu选项菜单和子菜单
简介: SubMenu:代表一个子菜单,包含1~N个MenuItem 实现效果: 具体实现方法: 主活动 MainActivity: public class MainActivity extends AppCompatActivity { //定义 “字体大小” 菜单项的标识 final int FONT_10 = 0x111; final int FONT_12 = 0x112; final int FONT_14 = 0x113; final int FON
圆号本昊
2021/09/24
1.3K0
Android-SubMenu选项菜单和子菜单
Jump Start Bootstrap 第3章
在这一章,我们将开始使用Bootstrap的一些非常有用的HTML组件。诸如按钮、标题(headers)、导航菜单和评论系统的组件经常被用在网站上。通过组件,Bootstrap可以简单和快速的帮我们在网站上添加这些功能。
Remember_Ray
2018/12/20
14.1K0
Jump Start Bootstrap 第3章
Facebook、苹果积极引导,AR市场形势乐观
近日,VR基金公布了第二季度的AR市场情况,该研究显示,共有150家公司致力于研究AR技术。 风险投资基金共募集了5000万美元投资于AR初创企业,与第一季度相比,重点关注AR的公司数量增长了60%。
VRPinea
2018/05/16
6010
CSS中的计数器
     <p>Place the flour in a large bowl, make a well in the centre and pour in the milk and eggs. Give the liquid mixture a quick whisk before incorporating the flour. Continue to whisk until you have a smooth batter.</p>
大江小浪
2018/07/25
1.4K0
五年五个头显的Facebook,下一站将走向何处?
(VRPinea 4月8日讯)自Facebook的第一款消费级VR头显问世之日起,已过去了5年的时间。作为一种媒介,VR依然处于非常早期的发展阶段,现在的从业者正在为将来的交互编写语法。五年前是这样,现在依然是这样。
VRPinea
2021/04/09
4760
五年五个头显的Facebook,下一站将走向何处?
实现一个栈类,类似STL中的栈
Christal_R
2017/12/25
1.1K0
实现一个栈类,类似STL中的栈
速读原著-GRUB_多系统引导(菜单命令)
菜单命令只能用于grub配置文件的全局配置部分,不能用在grub命令行交互界面,菜单命令在配置文件中应放在其它命令之前。 1、default //设置默认启动的菜单项 2、fallback //设置启动某菜单项失败后反回的菜单项 3、hiddenmenu //隐藏菜单界面 4、timeout //设置菜单自动启动的延时时间 5、title //开始一个菜单项
cwl_java
2020/02/14
9580
【说站】python PyQt子菜单的使用
以上就是python PyQt子菜单的使用,希望对大家有所帮助。更多Python学习指路:python基础教程
很酷的站长
2022/11/24
8780
android 软软的动画弹出菜单,基于Facebook的Rebuond
︿( ̄︶ ̄)︿我是路过的DEMO : https://github.com/CarGuo/AnimationMenu
GSYTech
2018/08/22
9450
android 软软的动画弹出菜单,基于Facebook的Rebuond
如何将深度学习研究论文实现为代码的几个要点
正如我所说的,能够将一篇论文转换成代码绝对是一种超超能力,尤其是在像机器学习这样每天都在快速发展的领域。
AiCharm
2023/05/15
2800
如何将深度学习研究论文实现为代码的几个要点
将新建文档添加回Ubuntu 18.04中的右键菜单
当我最近转移到Ubuntu 18.04时,我注意到Nautilus的右键菜单中没有选项来创建一个空文本文件。 当然,我可以使用命令行快速创建新文档,甚至可以使用文本编辑器创建新文件,但这不是我想要的。 我还在寻找旧样式的右键单击菜单,它可以帮助我创建一个新的文本文件,只需点击一两下即可。
知忆
2021/06/12
7740
windows&Ubuntu双系统修改启动菜单引导顺序
我的第三个是win11,所以修改成2,大家自己研究第一个为啥是0,第3个为啥是2。作为写代码的你,这还能难道你吗。
手撕代码八百里
2022/05/25
1.7K0
点击加载更多

相似问题

引导Navbar折叠下拉子菜单

10

引导3-带有子菜单的Navbar菜单

15

将资料UI菜单呈现为<nav>,其子菜单呈现为<a>?

13

Navbar没有显示子菜单。

13

引导活动菜单更改Navbar高度

13
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档