-3

周围有500价值观planned,在此基础上我必须预测新的价值观actual

请帮助我进行编码,在这里我展示了我正在手动执行的操作:

predict(poly_reg, data.frame(planned= 48.80000,
                             Level2 = 48.80000^2,
                             Level3 = 48.80000^3))

lin_reg = lm(formula = actual ~ ., data = dataset)
summary(lin_reg)
# Fitting Polynomial Regression to the dataset
dataset$Level2 = dataset$planned^2
dataset$Level3 = dataset$planned^3
dataset$Level4 = dataset$Planned_FTM^0.25000
poly_reg = lm(formula = actual~ ., data = dataset)
# Visualising the Linear Regression results
# install.packages('ggplot2')
library(ggplot2)
ggplot() + geom_point(aes(x = dataset$planned, y = dataset$actual), colour = 'red') + geom_line(aes(x = dataset$planned, y = predict(lin_reg, newdata = dataset)), colour = 'blue') + ggtitle('Truth or Bluff (Linear Regression)') + xlab('planned') + ylab('actual')

# Predicting a new result with Linear Regression
predict(lin_reg, data.frame(planned= 48.80000))
# Predicting a new result with Polynomial Regression
predict(poly_reg, data.frame(planned= 48.80000, Level2 = 48.80000^2, Level3 = 48.80000^3)) 
4

1 回答 1

0

尝试使用您正在使用polyplanned任何阶多项式(我使用了 4):

# Fitting Linear Regression to the dataset
lin_reg = lm(formula = actual ~ planned, data = dataset)

# Fitting Polynomial Regression to the dataset
poly_reg = lm(formula = actual ~ poly(planned, 4), data = dataset)

# Predicting a new result with Linear Regression
predict(lin_reg)

# Predicting a new result with Polynomial Regression
predict(poly_reg)
于 2018-10-23T17:56:01.710 回答