1. Пакет caret и featurePlot()

library(caret)
length(names(getModelInfo()))
## [1] 239
head(names(getModelInfo()), 30)
##  [1] "ada"            "AdaBag"         "AdaBoost.M1"    "adaboost"       "amdai"          "ANFIS"          "avNNet"        
##  [8] "awnb"           "awtan"          "bag"            "bagEarth"       "bagEarthGCV"    "bagFDA"         "bagFDAGCV"     
## [15] "bam"            "bartMachine"    "bayesglm"       "binda"          "blackboost"     "blasso"         "blassoAveraged"
## [22] "bridge"         "brnn"           "BstLm"          "bstSm"          "bstTree"        "C5.0"           "C5.0Cost"      
## [29] "C5.0Rules"      "C5.0Tree"

Сгенерируем 50 наблюдений с 5 случайными признаками и фактором из двух классов.

set.seed(233)
x <- matrix(rnorm(50 * 5), ncol = 5)
colnames(x) <- paste0("X", 1:5)
y <- factor(rep(c("A", "B"), 25))
featurePlot(x, y, plot = "pairs", auto.key = list(columns = 2))

featurePlot(x, y, plot = "ellipse", auto.key = list(columns = 2))

featurePlot(x, y, plot = "box", layout = c(5, 1))

featurePlot(x, y, plot = "density", layout = c(5, 1), auto.key = list(columns = 2))

Вывод: признаки случайные и не связаны с классом, поэтому распределения классов A и B почти совпадают на всех графиках.

2. Важность признаков (FSelector)

library(FSelector)
information.gain(Species ~ ., iris)
##              attr_importance
## Sepal.Length       0.4521286
## Sepal.Width        0.2672750
## Petal.Length       0.9402853
## Petal.Width        0.9554360
gain.ratio(Species ~ ., iris)
##              attr_importance
## Sepal.Length       0.4196464
## Sepal.Width        0.2472972
## Petal.Length       0.8584937
## Petal.Width        0.8713692
symmetrical.uncertainty(Species ~ ., iris)
##              attr_importance
## Sepal.Length       0.4155563
## Sepal.Width        0.2452743
## Petal.Length       0.8571872
## Petal.Width        0.8705214
chi.squared(Species ~ ., iris)
##              attr_importance
## Sepal.Length       0.6288067
## Sepal.Width        0.4922162
## Petal.Length       0.9346311
## Petal.Width        0.9432359
set.seed(233)
random.forest.importance(Species ~ ., iris)
##              attr_importance
## Sepal.Length       16.269000
## Sepal.Width         6.769082
## Petal.Length       47.656478
## Petal.Width        47.111234
ig <- information.gain(Species ~ ., iris)
cutoff.k(ig, 2)
## [1] "Petal.Width"  "Petal.Length"

Вывод: наиболее важны признаки лепестка Petal.Width и Petal.Length, наименее информативен Sepal.Width.

3. Дискретизация (arules)

library(arules)
pl <- iris$Petal.Length
table(discretize(pl, method = "interval",  breaks = 3))
## 
##    [1,2.97) [2.97,4.93)  [4.93,6.9] 
##          50          54          46
table(discretize(pl, method = "frequency", breaks = 3))
## 
##   [1,2.63) [2.63,4.9)  [4.9,6.9] 
##         50         49         51
set.seed(233)
table(discretize(pl, method = "cluster",   breaks = 3))
## 
##    [1,2.95) [2.95,5.13)  [5.13,6.9] 
##          50          66          34
table(discretize(pl, method = "fixed", breaks = c(-Inf, 2, 5, Inf),
                 labels = c("short", "medium", "long")))
## 
##  short medium   long 
##     50     54     46

Вывод: все методы отделяют setosa (короткие лепестки), а граница между versicolor и virginica проводится по-разному.

4. Отбор признаков (Boruta)

library(Boruta)
library(mlbench)
data("Ozone")
oz <- na.omit(Ozone)
set.seed(233)
bor <- Boruta(V4 ~ ., data = oz)
print(bor)
## Boruta performed 15 iterations in 0.1719091 secs.
##  9 attributes confirmed important: V1, V10, V11, V12, V13 and 4 more;
##  3 attributes confirmed unimportant: V2, V3, V6;
plot(bor, las = 2, xlab = "", main = "Boruta: важность признаков Ozone")

Вывод: зелёным отмечены важные признаки, красным — отклонённые, синим — теневые (случайный шум). Уровень озона определяется погодными показателями и месяцем.