簡體   English   中英

使用SVM在R中集成

[英]Ensemble in R using SVM

我正在嘗試使用R中的SVM對一些數據進行分類。

數據集:

D1 | D2 | D3 | word1 | word2 |...
1  | 2  | 3  | 0     | 1     |
3  | 2  | 1  | 1     | 0     |

D1,D2,D3取值為0到9,每個字取值為0/1。

首先,我想構建一個基於word1,word2等預測D1的分類器。然后,我想構建一個基於D1和單詞預測的D2預測的分類器。 D1,D2和D3曾經是3位數字的整數,並且在數字和前一位之間存在關系。

到目前為止,我有:

trainD1 <- train[,-1]
trainD1$D2 <- NULL
trainD1$D3 <- NULL

modelD1 <- svm( train$D1~., trainD1, type="C-classification")

但是我完全迷路了,歡迎任何幫助。

謝謝

我確定您已經知道了這一點,但是我只是想確保我涵蓋了基礎知識-如果D1和D2可以預測D3,那么最好使用D1和D3的實際值而不是它們的預測。

出於這個問題的目的,我將假設D1和D2可能不存在於您的預測數據集中,因此這就是為什么您必須預測它們的原因。 從“單詞”變量直接預測D3可能仍然更加准確,但這不在此問題的范圍內。

train <- read.csv("trainingSmallExtra.csv")

require(e1071)
d1 <- svm(  x = train[,5:100], # arbitrary subset of words
            y = train$D1,
            gamma = 0.1)

d1.predict <- predict(d1)
train      <- cbind(d1.predict, train)
x_names    <- c("d1.predict", train[,6:101])

d2 <- svm(  x = x_names,  # d1 prediction + arbitrary subset of words
            y = train$D2,
            gamma = 0.1)

d2.predict <- predict(d2)
train      <- cbind(d2.predict, train)

x_names <- c("d1.predict", "d2.predict", colnames(train)[25:150]) 

final <- svm(  x = train[,x_names], 
               y = train$D3,
               gamma = 0.1)

summary(final)

呼叫:svm.default(x = train [,x_names],y = train $ D3,gamma = 0.1)

參數:SVM類型:eps回歸SVM內核:徑向

  cost: 1 gamma: 0.1 epsilon: 0.1 

支持向量數:932

這只是向您顯示過程。 在代碼中,您將需要使用更多的單詞並設置您認為最合適的任何選項。

我建議使用保留樣本或交叉驗證來進行基准測試。 將集成模型與單個模型進行比較,該模型試圖通過檢查單詞的性能基准直接從單詞中預測D3。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM