You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用FB Prophet预测出勤人数时遇日期解析错误求助

解决FB Prophet日期格式解析错误问题

你执行m <- prophet(df)时遇到以下错误:

Error in setup_dataframe(m, history, initialize_scales = TRUE) :
Unable to parse date format in column ds. Convert to date format (%Y-%m-%d or %Y-%m-%d %H:%M:%S) and check that there are no NAs.

问题根源是你的CSV中ds列的日期格式为月/日/年(如1/1/2020),而Prophet默认仅识别年-月-日或带时间戳的标准格式,需要手动将ds列转换为R的日期类型。

解决步骤:

  • 读取CSV数据:你的数据是制表符分隔的,用read.delim读取:
    df <- read.delim("your_file.csv", sep = "\t", stringsAsFactors = FALSE)
    
  • 转换日期格式:
    方法1:使用lubridate包的mdy函数(推荐,自动识别月/日/年格式):
    library(lubridate)
    df$ds <- mdy(df$ds)
    
    方法2:使用base R的as.Date函数,指定格式:
    df$ds <- as.Date(df$ds, format = "%m/%d/%Y")
    
  • 验证转换结果:检查是否存在NA值(确保所有日期都被正确解析):
    sum(is.na(df$ds))
    
    若输出为0,说明转换成功。
  • 重新运行Prophet:
    library(prophet)
    m <- prophet(df)
    

内容的提问来源于stack exchange,提问作者Carlos Danso

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 00:39:17