Skip to content

Instantly share code, notes, and snippets.

@Harshit1694
Created June 29, 2019 06:23
Show Gist options
  • Save Harshit1694/ba70fc897bcbb68a4a28adfbb11b6810 to your computer and use it in GitHub Desktop.
Save Harshit1694/ba70fc897bcbb68a4a28adfbb11b6810 to your computer and use it in GitHub Desktop.
library(dummies)
train$Item_Weight[is.na(train$Item_Weight)] <- mean(train$Item_Weight, na.rm = TRUE)
train$Outlet_Size[is.na(train$Outlet_Size)] <- "Small"
train$Item_Visibility[train$Item_Visibility == 0] <- mean(train$Item_Visibility)
train$Outlet_Establishment_Year=2013 - train$Outlet_Establishment_Year
X<-train[c(-1,-12)]
X <- dummy.data.frame(X, names=c("Item_Type","Item_Fat_Content","Outlet_Identifier","Outlet_Size",
"Outlet_Location_Type","Outlet_Type"), sep="_")
names(train)
head(X)
names(X)
Y<-train[c(12)]
names((Y))
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~.,data =train_2 )
summary(model1)
predict_1<-predict(model1,X_cv)
m<-mean((Y_cv - predict_1)^2)
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment