Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Need help...FlightDelay data set

hi,
#The confusion matrix, while executing shows error as below-
#Error in !all.equal(nrow(data), ncol(data)) : invalid argument type


flight <- read.csv(file.choose())
View(flight)
str(flight)

flight$delay <- ifelse(flight$delay=="ontime",0,1) # ontime-0, delay-1
flight$delay <- as.factor(flight$delay)
flight$weather <- as.factor(flight$weather)
#missing values
apply(flight,2,function(x){sum(is.na(x))})

#training data
library(caTools)

sel <- sample.split(flight$distance, SplitRatio = 0.6)

flight_train <- subset(flight, sel==T)
flight_test <- subset(flight, sel==F)

# train model - logistics regression

flight_model <- glm(delay~ schedtime+deptime+weather, data=flight_train, family='binomial')
summary(flight_model)

# predict test results on this model
flight_predict <- predict(flight_model, flight_test)

View(flight_predict)

#bind this result to actual testing dataset
flight_final <- cbind(flight_test, flight_predict)
View(flight_final)

#confusion matrix-
library(caret)
confusionMatrix(table(flight_final$delay, flight_final$flight_predict), positive = '1')


#Kindly help and let me know what is the problem.
 

Kunal Guwalani

Well-Known Member
Staff member
Simplilearn Support
hi,
#The confusion matrix, while executing shows error as below-
#Error in !all.equal(nrow(data), ncol(data)) : invalid argument type


flight <- read.csv(file.choose())
View(flight)
str(flight)

flight$delay <- ifelse(flight$delay=="ontime",0,1) # ontime-0, delay-1
flight$delay <- as.factor(flight$delay)
flight$weather <- as.factor(flight$weather)
#missing values
apply(flight,2,function(x){sum(is.na(x))})

#training data
library(caTools)

sel <- sample.split(flight$distance, SplitRatio = 0.6)

flight_train <- subset(flight, sel==T)
flight_test <- subset(flight, sel==F)

# train model - logistics regression

flight_model <- glm(delay~ schedtime+deptime+weather, data=flight_train, family='binomial')
summary(flight_model)

# predict test results on this model
flight_predict <- predict(flight_model, flight_test)

View(flight_predict)

#bind this result to actual testing dataset
flight_final <- cbind(flight_test, flight_predict)
View(flight_final)

#confusion matrix-
library(caret)
confusionMatrix(table(flight_final$delay, flight_final$flight_predict), positive = '1')


#Kindly help and let me know what is the problem.

Try to reinstall the package.
 
Top