1

I'm having the same issue as here, but the solutions are not working for me. I'm not sure what I'm doing wrong...

Here is my code:

# ensure results are repeatable
set.seed(7)

# load the library
library(caret)

# load the dataset
dataset <- read.csv("C:\\Users\\asholmes\\Documents\\diabetes_r.csv", na.strings='.')

#convert to data frame
as.data.frame(dataset, stringsAsFactors=TRUE)

#create x and y
x <- dataset[, 1:15]
y <- dataset[, 16]

# prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)

# train the model
model <- train(x, y, data=dataset, method="lvq", preProcess="scale", trControl=control)

And here's my data:

> str(dataset)
'data.frame':   2777 obs. of  16 variables:
 $ A1c          : num  5 8.5 5.5 5.9 5.1 6.2 6.4 5.7 4.8 5.4 ...
 $ BP_CAT       : Factor w/ 3 levels "Hypertension",..: 3 1 1 3 1 3 3 3 3 3 ...
 $ BMI_CAT      : Factor w/ 4 levels "Normal","Obese",..: 3 2 2 2 2 2 2 2 2 3 ...
 $ Creatinine   : num  0.8 0.8 0.7 0.7 0.6 1.2 0.6 1.4 1.1 0.6 ...
 $ LDL          : num  86 51 107 102 NA 79 82 79 150 NA ...
 $ BUN          : num  14 9 10 15 12 13 7 15 16 16 ...
 $ Triglycerides: num  221 77 98 121 NA 324 151 88 97 841 ...
 $ Age          : num  55 57 24 55 38 51 44 35 25 48 ...
 $ Gender       : Factor w/ 2 levels "F","M": 1 1 1 1 1 2 1 1 1 1 ...
 $ Claims       : num  13 394 15 18 11 33 9 1 13 3 ...
 $ Presc        : num  47 227 85 58 29 190 0 2 6 6 ...
 $ Months       : Factor w/ 12 levels "1","2","3","4",..: 9 12 12 12 12 12 12 12 12 12 ...
 $ Expenditure  : num  2877 71859 7494 5196 2500 ...
 $ Health.Plan  : Factor w/ 20 levels "AFFMCD ","HFMCD",..: 9 6 2 2 2 2 4 2 2 2 ...
 $ Flag         : Factor w/ 12 levels "Asthma","CKD",..: 1 4 8 8 1 3 10 10 10 10 ...
 $ Case.Status  : Factor w/ 6 levels "Closed","Deferred",..: 6 4 4 4 1 4 6 4 4 4 ...

However, when I run the last line of code, I'm getting the error:

Something is wrong; all the Accuracy metric values are missing:
    Accuracy       Kappa    
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :9     NA's   :9    
Error in train.default(x, y, data = dataset, method = "lvq", preProcess = "scale",  : 
  Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)

Any help that anyone can provide would be extremely helpful.

Community
  • 1
  • 1
Ashley A Holmes
  • 69
  • 3
  • 5
  • 10
  • what is `x` and `y` in your dataset? – tcash21 Mar 23 '16 at 15:11
  • check the warnings. They tend to give an idea what is going on. – phiver Mar 23 '16 at 15:12
  • @tcash21 it's in the code section. x is the first 15 variables, and y is the 16th variable (Case.Status) – Ashley A Holmes Mar 23 '16 at 15:13
  • @phiver The warnings all look like this: '> warnings() Warning messages: 1: In eval(expr, envir, enclos) : model fit failed for Fold01.Rep1: size=30, k= 1 Error in lvq3(x, y, lvqinit(x, y, size = param$size, k = min(param$k, : unused argument (data = list(A1c = c(5, 8.5, 5.5, 5.9, 5.1, 6.2, 6.4, 5.7, 4.8, 5.4, 6, 5.9, 7.3, 5.4, 6.2, 6.3, 10.2, 7, 8.5, 5.6, 6.2, 8.5, 12.7, 6, 6.1, [... truncated]' – Ashley A Holmes Mar 23 '16 at 15:15

1 Answers1

3

You are using the default notation (x and y) and not the formula notation (Y ~ .). No need to specify data = argument. Change it to:

model <- train(x, y, method="lvq", preProcess="scale", trControl=control)

That should do the trick.

phiver
  • 23,048
  • 14
  • 44
  • 56
  • 1
    i tried removing the data= argument, but i'm still getting the error. now all of my warnings look like this: Warning messages: 1: In eval(expr, envir, enclos) : model fit failed for Fold01.Rep1: size=30, k= 1 Error in lvq3(x, y, lvqinit(x, y, size = param$size, k = min(param$k, : no missing values are allowed – Ashley A Holmes Mar 23 '16 at 16:08
  • Problem one solved. Problem two, you have missing values in your data. You have to solve this either by imputing the missing values or by removing the cases where this is happening. – phiver Mar 23 '16 at 18:16