Last active
June 29, 2019 06:15
-
-
Save Harshit1694/0689f05e2938906bdf8876a885a9ffd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("rsq") | |
library(rsq) | |
train<-read.table(file.choose(),sep = ",",header = T) #Importing the train set | |
train[train==""] <- NA #Filling blank values with NA | |
names(train) | |
X<-train[c(6,8)] #Creating new data with two variables | |
names((X)) | |
Y<-train[c(12)] #Storing the dependent variable | |
names((Y)) | |
#Splitting the data | |
set.seed(567) | |
part <- sample(2, nrow(X), replace = TRUE, prob = c(0.7, 0.3)) | |
X_train<- X[part == 1,] | |
X_cv<- X[part == 2,] | |
Y_train<- Y[part == 1,] | |
Y_cv<- Y[part == 2,] | |
train_2<-data.frame(Y_train,X_train) | |
model1<-lm(Y_train~Item_MRP+Outlet_Establishment_Year,data =train_2 ) #linear model function | |
summary(model1) | |
predict_1<-predict(model1,X_cv) #Predicting the values | |
m<-mean((Y_cv - predict_1)^2) #Calculating mse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment