1
我使用R代碼來實現SVM-RFE
算法從這個源http://www.uccor.edu.ar/paginas/seminarios/Software/SVM_RFE_R_implementation.pdf但我做了一個小的修改,使r代碼使用gnum
庫。該代碼是下面的:R中的SVM-RFE算法的實現
svmrfeFeatureRanking = function(x,y){
n = ncol(x)
survivingFeaturesIndexes = seq(1:n)
featureRankedList = vector(length=n)
rankedFeatureIndex = n
while(length(survivingFeaturesIndexes)>0){
#train the support vector machine
svmModel = SVM(x[, survivingFeaturesIndexes], y, C = 10, cache_size=500,kernel="linear")
#compute ranking criteria
rankingCriteria = svmModel$w * svmModel$w
#rank the features
ranking = sort(rankingCriteria, index.return = TRUE)$ix
#update feature ranked list
featureRankedList[rankedFeatureIndex] = survivingFeaturesIndexes[ranking[1]]
rankedFeatureIndex = rankedFeatureIndex - 1
#eliminate the feature with smallest ranking criterion
(survivingFeaturesIndexes = survivingFeaturesIndexes[-ranking[1]])
}
return (featureRankedList)
}
該功能接收matrix
作爲input
用於x
和factor
作爲input
爲y
。我使用的功能對於一些數據,我收到的最後一個迭代以下錯誤信息:
Error in if (nrow(x) != length(y)) { : argument is of length zero
調試代碼,我得到這個:
3 SVM.default(x[, survivingFeaturesIndexes], y, C = 10, cache_size = 500,
kernel = "linear")
2 SVM(x[, survivingFeaturesIndexes], y, C = 10, cache_size = 500,
kernel = "linear")
1 svmrfeFeatureRanking(sdatx, ym)
那麼,有什麼功能的錯誤?