-3

There are around 500 values planned and on the basis of this I have to predict new values actual.

Kindly help me with the coding, here I'm showing what I am doing manually:

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)) 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Something is not right, you should not have a square and a cube of your variable in the data, these terms should only be present in the model. – user2974951 Oct 23 '18 at 07:32
  • okay can you tell me how to do predictions for around 500 values – Pragyesh Mishra Oct 23 '18 at 07:43
  • Its okay to create square or cube. This is called transformation. But, I am not sure what is 48.8 doing there. I suspect you are trying to forecast 501th value using 500 data point. Is this right? You don't need LM for this. Look at ARIMA or other forecasting algorithms. – Espanta Nov 05 '18 at 22:39

1 Answers1

0

Try using poly on planned to whatever order polynomial you're using (I used 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)
cgrafe
  • 443
  • 1
  • 6
  • 14