Skip to content

Instantly share code, notes, and snippets.

@Harshit1694 Harshit1694/lin_reg1.R
Last active Jun 29, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.