Question: Create a R script or R markdown file. # read the 'HousePrice.csv ' , load it to a dataframe. house 2 read.csv ( ' HousePrice

Create a R script or R markdown file.
# read the 'HousePrice.csv', load it to a dataframe.
house 2 read.csv('HousePrice.csv')
# convert continuous house price values to labels
house2$Price-factor(with(house2, ifelse((house2$Price1000000), 'low','high')))
# check number of samples in each category
table(house2$Price)
# Divide as training and testing: 20% test 80% train and get the training
data size
sample_size - floor(0.8*nrow(house))
# check the training data size
sample_size
# get train data index
train_ind - sample(seq_len(nrow(house2)), size = sample_size)
# generate training and test dataset
train - house2[train_ind,]
test - house2[-train_ind,]
# use glm to build logistic model
glm.fit - glm(Price Sqft_Area+Lot_Area+Age+Crime, data = train,
family = binomial)
summary(glm.fit)
data = train)
Coefficients:
Null deviance: 3597.9 on 5835 degrees of freedam Residual deviance: 2388.4 on 5831 degrees of freedom (70 observatians deleted due to missingness) AIC: 2318.4
# predict on test dataset
predictedprob - predict(glm.fit, newdata = test, type = "response")
head(predictedprob)
# check the probability
newdata - data.frame(test$Sqft_Area, test$Price, predictedprob)
head(newdata)
ggplot(newdata,aes(x=test.Sqft_Area, y=predictedprob))+ geom_point()
# evaluate the prediction results
glm.pred = factor(ifelse(predictedprob >0.5, 'low','high'))
confusionMatrix(test$Price, glm.pred)
Create a R script or R markdown file. # read the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!