简体   繁体   中英

Create dataset for svm in R (e1071)

I'm going through this svm tutorial and trying to apply it to my data.

I've read my data from SQLite in a matrix ept

though, for me the structures look similar

> print (cats)
    Sex Bwt  Hwt
1     F 2.0  7.0
2     F 2.0  7.4
...
48    M 2.0  6.5
49    M 2.0  6.5

> print(ept)
       EPT       DIL          BRT       EX
1     T640 -0.968750 -0.372549020  0.32400
2     T640 -0.968750 -0.325490196  0.32400
...
30   T1280 -0.984375  0.082352941 -0.04675
31   T1280 -0.984375  0.145098039 -0.04675
...

the summary for cats produces different output-structure in the 1st column:

> summary(cats)
 Sex         Bwt             Hwt       
 F:47   Min.   :2.000   Min.   : 6.30  
 M:97   1st Qu.:2.300   1st Qu.: 8.95  
        Median :2.700   Median :10.10  
        Mean   :2.724   Mean   :10.63  
        3rd Qu.:3.025   3rd Qu.:12.12  
        Max.   :3.900   Max.   :20.50  
> summary(ept)
     EPT                 DIL               BRT                 EX         
 Length:119         Min.   :-0.9844   Min.   :-0.71765   Min.   :-0.5587  
 Class :character   1st Qu.:-0.9688   1st Qu.:-0.42353   1st Qu.:-0.0235  
 Mode  :character   Median :-0.9375   Median :-0.16078   Median : 0.1555  
                    Mean   :-0.8887   Mean   :-0.16981   Mean   : 0.1635  
                    3rd Qu.:-0.8750   3rd Qu.: 0.04706   3rd Qu.: 0.5000  
                    Max.   : 0.0000   Max.   : 0.59216   Max.   : 0.5000  

Then calling data on ept also fails:

> data(cats)
> data(ept)
Warning:
In data(ept) : data-set ‘ept’ not found # my translation here
>

What am I missing here? How could I create my own data-set for svm (e1071)?

OK, I've found it out. Seems like the column defining classes should be of type factor.

Converting helped:

ept$EPT <- factor(ept$EPT)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM