BAR-Classification Modelling
BAR-Classification Modelling
BAR-Classification Modelling
#logistic regression
y<-ifelse(concrete$comp_strength>50,1,0)
concrete<-cbind(concrete,y)
logreg_fit<-glm(y~.,concrete,family = "binomial")
summary(logreg_fit)
predict <- predict(logreg_fit, type = 'response')
pred<-ifelse(predict > 0.5, 1,0)
#confusion matrix
table(y, pred)
#ROCR Curve
library(ROCR)
ROCRpred <- prediction(pred, y)
ROCRperf <- performance(ROCRpred, 'tpr','fpr')
plot(ROCRperf, colorize = TRUE, text.adj = c(-0.2,1.7))
logreg_fit_2<-glm(y~.,train,family = "binomial")
summary(logreg_fit_2)
predict <- predict(logreg_fit_2, test[,-9],type = 'response')
pred<-ifelse(predict > 0.5, 1,0)
#confusion matrix
table(test$y, pred)
ROCRpred <- prediction(pred, test$y)
#ROCRperf <- performance(ROCRpred, 'prec','rec','f','auc')
library(glmnet)
x<-as.matrix(concrete[,1:8])
y<-ifelse(concrete$comp_strength>50,1,0)
coef(model_logreg)
#x: matrix of predictor variables
#y: the response or outcome variable, which is a binary variable.
#family: the response type. Use �binomial� for a binary outcome variable
#alpha: the elasticnet mixing parameter. Allowed values include:
#�1�: for lasso regression; 0�: for ridge regression
#a value between 0 and 1 (say 0.3) for elastic net regression.
#lamba: a numeric value defining the amount of shrinkage. Should be specify by
analyst.
#In penalized regression, you need to specify a constant lambda to adjust the
amount of the coefficient shrinkage. The best lambda for your data, can be defined
as the lambda that minimize the cross-validation prediction error rate. This can be
determined automatically using the function cv.glmnet().
# Fit the lasso penalized regression model & predict on test data:
##OLR
library(MASS)
z<-ifelse(concrete$comp_strength<50,1,ifelse(concrete$comp_strength<70,2,3))
concrete<-cbind(concrete,z)
train<-concrete[1:800,-(9:10)]
test<-concrete[801:1030,-(9:10)]
## Confusion matrix
table(test$z, predictedClass)
#predicting probabilities
predictedScores <- predict(olr_model, test[,-9], type="p") # predict the
probabilites
head(predictedScores)