-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiesel_Price_Prediction.R
50 lines (40 loc) · 1.34 KB
/
Diesel_Price_Prediction.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#READ DATA FROM FILE, here program will be read from first line because hader is not there
x<-read.csv("Diesel_Retail_Price_Weekly_Average_by_Region__Beginning_2007.csv",header=FALSE)
#FIND OUT ATTRIBUTES NAMES
names(x)
#NORMALISE DATA, TYPE CASTING DATE->CHARACTER
p<-as.character(x$Date)
s<-as.character(seq(from=as.Date("2007-10-29"),to=as.Date("2018-08-27"),by="week"))
r<-seq(1:length(p))
#ENCODE VALUE OF P USING REFRENCE "S" & "R"
f<-factor(p,s,r)
#ASSIGNE ENCODE VALUE TO REAL DATA
x$Date=as.numeric(f)
#(1)TAKE DATA FOR PREDECT AND TASTE WITH ONE VALUE
p<-x$Date
q<-x$New_York_Average
var(q)
rel<-lm(q~p)
a<-data.frame(p=600)
g<-predict(rel,a)
plot(p,q,type="l",pch=1)
#(2)DIVIDE YOUR SCREEN INTO GRID 1-ROW,2-COLUMNS AND DRAW ACTUAL AND PREDICTED GRAPH(LINEAR)
par(mfrow=c(1,2))
rel<-lm(q~p)
a<-predict(rel,data.frame(p))
cor(a,q)#DEGREE OF LINEARITY BETWEEN TWO VARIABLE
plot(p,a,col="red",pch=2)
plot(p,q,type="l",pch=1)
#(3)POLYNOMIAL REGRATION
rel<-lm(q~p+I(p^2)+I(p^3)+I(p^4)+I(p^5))
a<-predict(rel,data.frame(p))
cor(a,q)#HIGH MEANS MORE ACURATE
lines(p,a,col="blue",pch=2)
#COMPAIR ALL AT THE SAME TIME
p<-subset(x,select=1)
q<-subset(data.frame(x),select=c(2:4))
pairs(cbind(p,q),labels=c("DATE",c("New_York","Binghamton","Buffalo")))
#REDIRECTING OUTPUT
sink("new.txt")
source("pro1.R")
sink()