[R] repeated execution of svm(e1071) gives different results, if weights are use and if probability = TRUE is set
Juergen Rose
rose at rz.uni-potsdam.de
Thu Feb 24 13:15:30 CET 2011
Am Mittwoch, den 23.02.2011, 18:12 +0100 schrieb Juergen Rose:
> class.weights=Wts,
I have just seen, that me last code was not complete. I try it once
more:
> library(e1071)> data(Glass, package = "mlbench")
> index <- 1:nrow(Glass)
> testindex <- sample(index, trunc(length(index)/5))
> testset <- Glass[testindex, ]
> trainset <- Glass[-testindex, ]
> datatrain <- subset(trainset,select=-Type)
> classestrain <- subset(trainset,select=Type)
If I now repeat:
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1)
> pred.test=predict(model,datatest); table(pred.test,t(classestest))
I allways get the same result:
pred.test 1 2 3 5 6 7
1 12 1 4 0 0 0
2 0 11 3 2 0 0
3 0 0 0 0 0 0
5 0 0 0 1 0 0
6 0 0 0 0 2 0
7 0 0 0 0 0 6
Also if I repeat:
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
I get the same result as above.
But if I set:
> Wts <- 1.0/table(Glass$Type)
and if I then repeat:
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
each attempt provides a different result:
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
pred.test 1 2 3 5 6 7
1 0 3 3 3 2 6
2 12 9 4 0 0 0
3 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
7 0 0 0 0 0 0
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
pred.test 1 2 3 5 6 7
1 12 12 7 3 2 6
2 0 0 0 0 0 0
3 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
7 0 0 0 0 0 0
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
pred.test 1 2 3 5 6 7
1 12 9 6 0 1 0
2 0 3 1 3 1 6
3 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
7 0 0 0 0 0 0
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
pred.test 1 2 3 5 6 7
1 12 12 7 3 2 6
2 0 0 0 0 0 0
3 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
7 0 0 0 0 0 0
> model <-
svm(datatrain,classestrain,type="C-classification",kernel="radial",cost=1,class.weights=Wts,probability=TRUE)
> pred.test=predict(model,datatest,probability=TRUE);
table(pred.test,t(classestest))
pred.test 1 2 3 5 6 7
1 10 11 3 3 0 3
2 2 1 4 0 2 3
3 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
7 0 0 0 0 0 0
What I am doing wrong?
More information about the R-help
mailing list