Im Aufruf am Ende des Codes zu:Fehler bei eval (ausdr, envir, enclos): Objekt 'roll_belt' gefunden, nicht in vorhersagen
predict(pml_training_rf_model_1, pml_validation$classe)
ich den Fehler:
Fehler bei eval (ausdr, envir, enclos): Objekt 'roll_belt' nicht gefunden
das war, weil ich die Funktion wie folgt aufrufen werden soll:
predict(pml_training_rf_model_1, pml_validation)
Das "roll_belt" -Attribut erscheint in den Datenrahmen, die ich benutze, also machte ich eindeutig einen anderen Fehler, der jetzt korrigiert und für die Nachwelt gespeichert wurde.
#Start code
rm(list=ls())
library("caret")
library("data.table")
library("randomForest")
set.seed(12345)
pml_training_file <- "pml-training.csv"
pml_testing_file <- "pml-testing.csv"
if (!file.exists(pml_training_file)) {
pml_training_url <- "http://d396qusza40orc.cloudfront.net/predmachlearn/pml-training.csv"
download.file(pml_training_url, pml_training_file)
}
pml_testing_file <- "pml-testing.csv"
if (!file.exists(pml_testing_file)) {
pml_testing_url <- "http://d396qusza40orc.cloudfront.net/predmachlearn/pml-testing.csv"
download.file(pml_testing_url, pml_testing_file)
}
pml_training_original <- fread(pml_training_file, na.strings=c("NA","#DIV/0!",""), data.table = FALSE, stringsAsFactors = TRUE)
partition_index <- createDataPartition(y=pml_training_original$classe, p=0.6, list = FALSE)
pml_training <- pml_training_original[partition_index,]
pml_validation <- pml_training_original[-partition_index,]
#Remove metadata columns
pml_training <- pml_training[,-c(1:7)]
#Remove columns where the number of NA results is above a given level
na_level = .75
nrow_pml_training = nrow(pml_training)
na_col_nums <- numeric()
for(i in 1:length(pml_training)) {
sum_na = sum(is.na(pml_training[, i]))
if(sum_na/nrow_pml_training >= na_level) {
na_col_nums <- c(na_col_nums, i)
}
}
pml_training <- pml_training[-na_col_nums]
#Set the columns in the validation data to be the same as those in the training data
pml_training_colnames <- colnames(pml_training)
pml_validation <- pml_validation[, pml_training_colnames]
pml_training_rf_model_1 <- randomForest(classe ~ ., data=pml_training)
#Wrong! pml_training_predictions_1 <- predict(pml_training_rf_model_1, pml_validation$classe)
pml_training_predictions_1 <- predict(pml_training_rf_model_1, pml_validation)
confusionMatrix(pml_validation$classe, pml_training_predictions_1)
Beweisen Sie, dass roll_belt ist in pml_validation $ classe. Weil ich R glaube, wenn es sagt, dass es nicht da ist. – Roland
Sie müssten ein Beispiel für Eingabedaten angeben, die einen Fehler verursachen, sodass wir Ihr Problem reproduzieren und testen können. Vielen Dank. – lrnzcig
Dank @Irnzcig, das Laden der Eingabedaten ist auch im Codebeispiel enthalten. –