当前位置:网站首页>Error in na.fail. default(list(Purchase = c(“CH“, “CH“, “CH“, “MM“, “CH“, : missing values in obj
Error in na.fail. default(list(Purchase = c(“CH“, “CH“, “CH“, “MM“, “CH“, : missing values in obj
2022-07-23 10:51:00 【Data+Science+Insight】
Error in na.fail.default(list(Purchase = c("CH", "CH", "CH", "MM", "CH", : missing values in object
Catalog
Error in na.fail.default(list(Purchase = c("CH", "CH", "CH", "MM", "CH", : missing values in object
problem :
The data has missing values , Training error
#
# install.packages(c('caret', 'skimr', 'RANN', 'randomForest', 'fastAdaboost', 'gbm', 'xgboost', 'caretEnsemble', 'C50', 'earth'))
# Load the caret package
library(caret)
# Import dataset
orange <- read.csv('https://raw.githubusercontent.com/selva86/datasets/master/orange_juice_withmissing.csv')
# Structure of the dataframe
str(orange)
# See top 6 rows and 10 columns
head(orange[, 1:10])
# Create the training and test datasets
set.seed(100)
# Step 1: Get row numbers for the training data
trainRowNumbers <- createDataPartition(orange$Purchase, p=0.8, list=FALSE)
# Step 2: Create the training dataset
trainData <- orange[trainRowNumbers,]
# Step 3: Create the test dataset
testData <- orange[-trainRowNumbers,]
# Store X and Y for later use.
x = trainData[, 2:18]
y = trainData$Purchase
# Define the training control
fitControl <- trainControl(
method = 'cv', # k-fold cross validation
number = 5, # number of folds
savePredictions = 'final', # saves predictions for optimal tuning parameter
classProbs = T, # should class probabilities be returned
summaryFunction=twoClassSummary # results summary function
)
# Step 1: Tune hyper parameters by setting tuneLength
set.seed(100)
model_mars2 = train(Purchase ~ ., data=trainData, method='earth', tuneLength = 5, metric='ROC', trControl = fitControl)
model_mars2
solve :
# Data preprocessing - Missing value
preProcess_missingdata_model <- preProcess(trainData, method='knnImpute')
preProcess_missingdata_model
library(RANN) # required for knnInpute
trainData <- predict(preProcess_missingdata_model, newdata = trainData)
anyNA(trainData)
#
# install.packages(c('caret', 'skimr', 'RANN', 'randomForest', 'fastAdaboost', 'gbm', 'xgboost', 'caretEnsemble', 'C50', 'earth'))
# Load the caret package
library(caret)
# Import dataset
orange <- read.csv('https://raw.githubusercontent.com/selva86/datasets/master/orange_juice_withmissing.csv')
# Structure of the dataframe
str(orange)
# See top 6 rows and 10 columns
head(orange[, 1:10])
# Create the training and test datasets
set.seed(100)
# Step 1: Get row numbers for the training data
trainRowNumbers <- createDataPartition(orange$Purchase, p=0.8, list=FALSE)
# Step 2: Create the training dataset
trainData <- orange[trainRowNumbers,]
# Step 3: Create the test dataset
testData <- orange[-trainRowNumbers,]
# Store X and Y for later use.
x = trainData[, 2:18]
y = trainData$Purchase
# Data preprocessing - Missing value
preProcess_missingdata_model <- preProcess(trainData, method='knnImpute')
preProcess_missingdata_model
library(RANN) # required for knnInpute
trainData <- predict(preProcess_missingdata_model, newdata = trainData)
anyNA(trainData)
# Define the training control
fitControl <- trainControl(
method = 'cv', # k-fold cross validation
number = 5, # number of folds
savePredictions = 'final', # saves predictions for optimal tuning parameter
classProbs = T, # should class probabilities be returned
summaryFunction=twoClassSummary # results summary function
)
# Step 1: Tune hyper parameters by setting tuneLength
set.seed(100)
model_mars2 = train(Purchase ~ ., data=trainData, method='earth', tuneLength = 5, metric='ROC', trControl = fitControl)
model_mars2
> model_mars2
Multivariate Adaptive Regression Spline
857 samples
17 predictor
2 classes: 'CH', 'MM'
No pre-processing
Resampling: Cross-Validated (5 fold)
Summary of sample sizes: 685, 686, 685, 686, 686
Resampling results across tuning parameters:
nprune ROC Sens Spec
2 0.8837092 0.8757143 0.7094075
5 0.9045666 0.8756960 0.7483944
9 0.8958465 0.8776190 0.7483039
13 0.8942303 0.8719048 0.7513342
17 0.8942303 0.8719048 0.7513342
Tuning parameter 'degree' was held constant at a value of 1
ROC was used to select the optimal model using the largest value.
The final values used for the model were nprune = 5 and degree = 1.
>
Complete error :
> # Step 2: Predict on testData and Compute the confusion matrix
> predicted2 <- predict(model_mars2, testData4)
Error in predict.train(model_mars2, testData4) :
object 'testData4' not found
> confusionMatrix(reference = testData$Purchase, data = predicted2, mode='everything', positive='MM')
Error in confusionMatrix(reference = testData$Purchase, data = predicted2, :
object 'predicted2' not found
>
>

边栏推荐
- Comprehensive experiment of realizing private network interworking under mGRE environment
- MySQL index operation
- [unity] avpro uses stepping pits, and the editor mode uses video playback. The video cannot be played after packaging
- C ivalueconverter interface usage example
- SQLZOO——SELECT Quiz
- Exciting metauniverse! Wealth outlet of next generation Internet
- Redis源码与设计剖析 -- 10.列表对象
- Global event bus
- Error in na.fail.default(list(Purchase = c(“CH“, “CH“, “CH“, “MM“, “CH“, : missing values in obj
- 【信息系统项目管理师】第六章 复盘进度管理知识架构
猜你喜欢

网络安全等级保护2.0标准解析

软件测试基本概念篇

赫克Hurco工控机维修WinMax数控机床控制器维修

【Unity日常Bug】Unity报错Unexpected character ‘‘

When flutter runs flutter pub get, it reports an error: "the client does not have the required privileges“

52832Dongle的安装

Optimization Net application CPU and memory 11 practices

Redis源码与设计剖析 -- 13.有序集合对象

Redis源码与设计剖析 -- 7.快速列表

MGRE环境下实现私网互通综合实验
随机推荐
ROS2的topic pub 指令出现:Failed to populate field: ‘Vector3‘ object has no attribute ‘x:1‘错误
Clion + mingw64 configure C language development environment visual studio installation
Database process stuck solution
第12届 蓝桥杯 嵌入式设计与开发项目
Recommend a shell installation force artifact, which has been open source! Netizen: really fragrant...
编译构建工具-bazel
3dMax先蒙皮刷权重,再附加合并
Chapter 1 Overview - Section 1 - 1.2 overview of the Internet
Switch exchanges
12 open source background management systems suitable for outsourcing projects
记一次 .NET 某智能交通后台服务 CPU爆高分析
0 basic career change software test, the necessary skills with a monthly salary of 6000 and 11000 are quite different
Redis source code and design analysis -- 13. Ordered collection objects
PyQt5_ Pyqtgraph mouse draws line segments on the line graph
Comprehensive experiment of realizing private network interworking under mGRE environment
Global event bus
Basic knowledge of C language (I)
单点登录-认证服务器与客户端的session过期时间如何统一
20.有效的括号
SVG, canvas, drawing line segments and filling polygon, rectangle, curve drawing and filling