Hi all
I am using the caret package and having difficulty in obtaining the results
using regression, I used the glmnet to model and trying to get the
coefficients and the model parameters I am trying to use the
extractPrediction to obtain a confusion matrix and it seems to be giving me
errors.
x<-read.csv("x.csv", header=TRUE);
y<-read.csv("y.csv", header=TRUE);
tc=trainControl(method="cv", number=10 );
glmmat<-train(x,y,method="glmnet", trControl=tc);
extractPrediction(list(glmmat,testX=x,testY = y));
any help would be great
thanks
vss
[[alternative HTML version deleted]]
Hi Sonny Vic, how about you send a reproducible code? cheers milton On Mon, Jun 8, 2009 at 11:25 AM, sunny vic <vss.0116@gmail.com> wrote:> Hi all > I am using the caret package and having difficulty in obtaining the > results > using regression, I used the glmnet to model and trying to get the > coefficients and the model parameters I am trying to use the > extractPrediction to obtain a confusion matrix and it seems to be giving me > errors. > > > x<-read.csv("x.csv", header=TRUE); > y<-read.csv("y.csv", header=TRUE); > tc=trainControl(method="cv", number=10 ); > glmmat<-train(x,y,method="glmnet", trControl=tc); > extractPrediction(list(glmmat,testX=x,testY = y)); > > any help would be great > thanks > vss > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Dear Sunny Vic, I am forwarding it to the list, to help the helpers :-) bests.. milton On Mon, Jun 8, 2009 at 12:41 PM, sunny vic <vss.0116@gmail.com> wrote:> Hi Milton, > here you go > > X1=rnorm(11, 50, 10) > X2=rnorm(11, 20, 10) > X3=rnorm(11, 50, 60) > X4=rnorm(11, 10, 2) > X5=rnorm(11, 5, 22) > > x<-cbind(X1,X2,X3,X4,X5); > y <- c(0, 0, 0,0,0,0,1,1,1,1,1) ; > > tc=trainControl(method="cv", number=10 ); > glmmat<-train(x,y,method="glmnet", trControl=tc); > extractPrediction(list(glmmat,testX=x,testY = y)); > > Error in models[[i]]$finalModel : > $ operator is invalid for atomic vectors > __________________________________________________ > > to give you more why I included list in the extractPrediction, without that > it looks for a list of models , so I found that in the help and used list > which eliminated that error and is now giving something new. > > > ERROR without List in extractPrediction > > extractPrediction(glmmat,testX=x,testY = y); > > Error in models[[1]]$trainingData : > $ operator is invalid for atomic vectors > _____________________________________________ > > I am actually trying to get the confusion matrix so I can calculate the > accuracy, sensitivity and specificity of the model > > cheers > vss > > > On Mon, Jun 8, 2009 at 10:42 AM, milton ruser <milton.ruser@gmail.com>wrote: > >> Hi Sonny Vic, >> >> how about you send a reproducible code? >> >> cheers >> milton >> >> On Mon, Jun 8, 2009 at 11:25 AM, sunny vic <vss.0116@gmail.com> wrote: >> >>> Hi all >>> I am using the caret package and having difficulty in obtaining the >>> results >>> using regression, I used the glmnet to model and trying to get the >>> coefficients and the model parameters I am trying to use the >>> extractPrediction to obtain a confusion matrix and it seems to be giving >>> me >>> errors. >>> >>> >>> x<-read.csv("x.csv", header=TRUE); >>> y<-read.csv("y.csv", header=TRUE); >>> tc=trainControl(method="cv", number=10 ); >>> glmmat<-train(x,y,method="glmnet", trControl=tc); >>> extractPrediction(list(glmmat,testX=x,testY = y)); >>> >>> any help would be great >>> thanks >>> vss >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >[[alternative HTML version deleted]]
The help page for extractPredictions suggests and testing confirms
that the function expects a _list_ of models. The predict function
is suggested as the method to get predictions from a single model.
Giving the argument as a list does work with a single model, however:
> predict(glmmat)
[1] 0.23544700 -0.03144066 0.24465107 0.59015641 0.22073566
0.20842277 0.98223087 0.72512869
[9] 0.79939904 0.48652752 0.53874162
> extractPrediction(list(glmmat))
obs pred model dataType
1 0 0.23544700 glmnet Training
2 0 -0.03144066 glmnet Training
3 0 0.24465107 glmnet Training
4 0 0.59015641 glmnet Training
5 0 0.22073566 glmnet Training
6 0 0.20842277 glmnet Training
7 1 0.98223087 glmnet Training
8 1 0.72512869 glmnet Training
9 1 0.79939904 glmnet Training
10 1 0.48652752 glmnet Training
11 1 0.53874162 glmnet Training
Invoking it the manner you did would create redundant information
since the input was the same as the training set:
> extractPrediction(list(glmmat),testX=x,testY = y)
obs pred model dataType
1 0 0.23544700 glmnet Training
2 0 -0.03144066 glmnet Training
3 0 0.24465107 glmnet Training
4 0 0.59015641 glmnet Training
5 0 0.22073566 glmnet Training
6 0 0.20842277 glmnet Training
7 1 0.98223087 glmnet Training
8 1 0.72512869 glmnet Training
9 1 0.79939904 glmnet Training
10 1 0.48652752 glmnet Training
11 1 0.53874162 glmnet Training
12 0 0.23544700 glmnet Test
13 0 -0.03144066 glmnet Test
14 0 0.24465107 glmnet Test
15 0 0.59015641 glmnet Test
16 0 0.22073566 glmnet Test
17 0 0.20842277 glmnet Test
18 1 0.98223087 glmnet Test
19 1 0.72512869 glmnet Test
20 1 0.79939904 glmnet Test
21 1 0.48652752 glmnet Test
22 1 0.53874162 glmnet Test
--
David
On Jun 8, 2009, at 12:53 PM, milton ruser wrote:
> Dear Sunny Vic,
>
> I am forwarding it to the list, to help the helpers :-)
>
> bests..
> milton
>
> On Mon, Jun 8, 2009 at 12:41 PM, sunny vic <vss.0116 at gmail.com>
wrote:
>
>> Hi Milton,
>> here you go
>>
>> X1=rnorm(11, 50, 10)
>> X2=rnorm(11, 20, 10)
>> X3=rnorm(11, 50, 60)
>> X4=rnorm(11, 10, 2)
>> X5=rnorm(11, 5, 22)
>>
>> x<-cbind(X1,X2,X3,X4,X5);
>> y <- c(0, 0, 0,0,0,0,1,1,1,1,1) ;
>>
>> tc=trainControl(method="cv", number=10 );
>> glmmat<-train(x,y,method="glmnet", trControl=tc);
>> extractPrediction(list(glmmat,testX=x,testY = y));
>>
>> Error in models[[i]]$finalModel :
>> $ operator is invalid for atomic vectors
>> __________________________________________________
>>
>> to give you more why I included list in the extractPrediction,
>> without that
>> it looks for a list of models , so I found that in the help and
>> used list
>> which eliminated that error and is now giving something new.
>>
>>
>> ERROR without List in extractPrediction
>>
>> extractPrediction(glmmat,testX=x,testY = y);
>>
>> Error in models[[1]]$trainingData :
>> $ operator is invalid for atomic vectors
>> _____________________________________________
>>
>> I am actually trying to get the confusion matrix so I can calculate
>> the
>> accuracy, sensitivity and specificity of the model
>>
>> cheers
>> vss
>>
>>
>> On Mon, Jun 8, 2009 at 10:42 AM, milton ruser
>> <milton.ruser at gmail.com>wrote:
>>
>>> Hi Sonny Vic,
>>>
>>> how about you send a reproducible code?
>>>
>>> cheers
>>> milton
>>>
>>> On Mon, Jun 8, 2009 at 11:25 AM, sunny vic <vss.0116 at
gmail.com>
>>> wrote:
>>>
>>>> Hi all
>>>> I am using the caret package and having difficulty in obtaining
the
>>>> results
>>>> using regression, I used the glmnet to model and trying to get
the
>>>> coefficients and the model parameters I am trying to use the
>>>> extractPrediction to obtain a confusion matrix and it seems to
be
>>>> giving
>>>> me
>>>> errors.
>>>>
>>>>
>>>> x<-read.csv("x.csv", header=TRUE);
>>>> y<-read.csv("y.csv", header=TRUE);
>>>> tc=trainControl(method="cv", number=10 );
>>>> glmmat<-train(x,y,method="glmnet", trControl=tc);
>>>> extractPrediction(list(glmmat,testX=x,testY = y));
>>>>
>>>> any help would be great
>>>> thanks
>>>> vss
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT