0

我正在尝试构建一个多元回归模型 (multi_model),我想构建 3 个不同的多元回归模型,这些模型根据每小时温度和每小时风速预测一天的每小时需求,这些模型因天气水平(1、2 和3)。

我的数据集样本名为“共享单车需求:

    datetime    season  holiday workingday  weather temp    atemp   humidity    windspeed   casual  registered  count
1/1/2011 0:00        1      0         0         1   9.84    14.395        81       0           3     13          16
1/1/2011 1:00        1      0          0        2   9.02    13.635        80       0           8    32           40
1/1/2011 2:00         1     0          0        3   9.02    13.635        80       0           5    27           32

除了,有 10,887 行。但你明白了。

library(tidyverse)
library(reticulate)
library(readxl)
library(modelr)
library(lubridate)
library(ggplot2)
library(dplyr)
library(scales)

type_1 <- read.csv("Bike Share Demand.csv")


type_1 %>%
  separate(datetime, into = c("month", "day",
                              "year", "hour", sep = "/")) -> type_1

我一直在尝试为这个问题构建我的代码:

avg_windspeed <- type_1$windspeed
avg_windspeed <- mean(avg_windspeed)

demand <- type_1$registered
total_demand <- sum(demand)

type_1 %>%
  separate(hour, into = c("v_hour", "v_min", sep = ":")) -> type_1
type_1


class(type_1$hour)
hours <- type_1$v_hour
hours

hour <- type_1$hour

rm(total_hours)
hours <- as.numeric(hours)
total_hours <- sum(hours,na.rm = TRUE)
total_hours

temperature <- type_1$temp
temperature
total_temperature <- sum(total_temperature)
total_temperature

windspeed <- type_1$windspeed
hourly_windspeed <- windspeed / hours 
hourly_windspeed

hourly_demand <- demand / total_hours
hourly_demand

hourly_temperate <- temperature / hours
hourly_temperate

multi_model <- lm(data = type_1, demand ~ hourly_windspeed)
summary(multi_model)

但我得到了错误: lm.fit 中的错误(x,y,offset = offset,singular.ok =singular.ok,...): 'x' 中的 NA/NaN/Inf

有没有更简单的方法来构建这个多模型?我通过创建所有这些变量来过度复杂化?

4

0 回答 0