library(caret)

Загрузка требуемого пакета: ggplot2

Загрузка требуемого пакета: lattice

> set.seed(123)

> x <- matrix(rnorm(50 * 5), ncol = 5)

> y <- factor(rep(c("A", "B"), 25))

> df <- data.frame(x, Class = y)

>

> # Построение графиков

> featurePlot(x = df[, 1:5], y = df$Class, plot = "box")

> # Сохранение графика

> jpeg("feature_plot.jpeg")

> featurePlot(x = df[, 1:5], y = df$Class, plot = "box")

> dev.off()

windows

2

> library(FSelector)

> data(iris)

> weights <- information.gain(Species ~ ., iris)

> print(weights)

attr_importance

Sepal.Length 0.4521286

Sepal.Width 0.2672750

Petal.Length 0.9402853

Petal.Width 0.9554360

> barplot(weights$attr_importance, names.arg = rownames(weights), las = 2, col = "lightblue", main = "Важность признаков (Information Gain)")

> weights <- gain.ratio(Species ~ ., iris)

> barplot(weights$attr_importance, names.arg = rownames(weights), las = 2, col = "lightblue", main = "Важность признаков (Gain Ratio)")

> #Задание 3

> library(arules)

Загрузка требуемого пакета: Matrix

Присоединяю пакет: ‘arules’

Следующие объекты скрыты от ‘package:base’:

abbreviate, write

> # Преобразование данных

> iris$Sepal.Length_interval <- discretize(iris$Sepal.Length, method = "interval", breaks = 3)

> iris$Sepal.Length_frequency <- discretize(iris$Sepal.Length, method = "frequency", breaks = 3)

> iris$Sepal.Length_cluster <- discretize(iris$Sepal.Length, method = "cluster", breaks = 3)

>

> # Вывод таблиц

> print(table(iris$Sepal.Length_interval))

[4.3,5.5) [5.5,6.7) [6.7,7.9]

52 70 28

> print(table(iris$Sepal.Length_frequency))

[4.3,5.4) [5.4,6.3) [6.3,7.9]

46 53 51

> print(table(iris$Sepal.Length_cluster))

[4.3,5.45) [5.45,6.46) [6.46,7.9]

52 63 35

> #Задание 4

> library(Boruta)

> library(mlbench)

>

> # Загрузка данных

> data("Ozone")

> ozone_data <- Ozone[, 4:6]

> ozone_data_clean <- na.omit(ozone_data)

>

> # Применение метода Boruta для выбора признаков

> boruta_result <- Boruta(V4 ~ ., data = ozone_data_clean, doTrace = 2)

  1. run of importance source…

  2. run of importance source…

  3. run of importance source…

  4. run of importance source…

  5. run of importance source…

  6. run of importance source…

  7. run of importance source…

  8. run of importance source…

After 8 iterations, +0.83 secs:

confirmed 2 attributes: V5, V6;

no more attributes left.

> # Отображение результатов

> print(boruta_result)

Boruta performed 8 iterations in 0.8322871 secs.

2 attributes confirmed important: V5, V6;

No attributes deemed unimportant.

> # Построение boxplot

> boxplot(ozone_data_clean[, c("V4", "V5", "V6")],

+ main = "Boxplot для набора данных Ozone (столбцы 4, 5, 6)",

+ col = c("lightblue", "lightgreen", "lightcoral"))

> save.image("C:\\Users\\user\\Downloads\\12")