--- title: "ЛР_2" author: "Ivan_233_331" date: "2026-10-19" output: html_document --- Задание 1.1 CARET и featurePlot() ```{r} library(caret) models <- names(getModelInfo()) length(models) head(models, 10) ``` ```{r} set.seed(123) x <- matrix(rnorm(50 * 5), ncol = 5) y <- factor(rep(c("A", "B"), 25)) colnames(x) <- paste0("X", 1:5) jpeg("featurePlot_pairs.jpg", width = 800, height = 800) featurePlot(x = x, y = y, plot = "pairs") dev.off() featurePlot(x = x, y = y, plot = "density") jpeg("featurePlot_pairs.jpg", width = 800, height = 800) # Сохраняем в файл featurePlot(x = x, y = y, plot = "pairs") dev.off() # Закрываем файл featurePlot(x = x, y = y, plot = "pairs") jpeg("featurePlot_box.jpg", width = 800, height = 800) featurePlot(x = x, y = y, plot = "box") dev.off() featurePlot(x = x, y = y, plot = "box") ``` Задание 2. Определение важности признаков с помощью FSelector ```{r} library(FSelector) data(iris) str(iris) ``` ```{r} weights <- information.gain(Species ~ ., data = iris) print(weights) ``` ```{r} best_features <- cutoff.k(weights, 2) print(best_features) formula <- as.simple.formula(best_features, "Species") print(formula) ``` Задание 3. Дискретизация непрерывной переменной с помощью arules ```{r} library(arules) ``` ```{r} x <- iris$Sepal.Length ``` ```{r} # 1) Метод "interval" (равная ширина интервала) # Разобьем на 3 интервала d_interval <- discretize(x, method = "interval", breaks = 3) print("Метод: interval (равная ширина)") table(d_interval) ``` ```{r} # 2) Метод "frequency" (равная частота) # Постарается сделать по ~50 наблюдений в каждой группе d_frequency <- discretize(x, method = "frequency", breaks = 3) print("Метод: frequency (равная частота)") table(d_frequency) ``` ```{r} # 3) Метод "cluster" (кластеризация k-means) d_cluster <- discretize(x, method = "cluster", breaks = 3) print("Метод: cluster (кластеризация)") table(d_cluster) ``` ```{r} # 4) Метод "fixed" (фиксированные границы) # Вручную зададим границы: до 5.5, от 5.5 до 6.5, и больше 6.5 d_fixed <- discretize(x, method = "fixed", breaks = c(-Inf, 5.5, 6.5, Inf)) print("Метод: fixed (фиксированные границы)") table(d_fixed) ``` Задание 4. Отбор признаков с помощью пакета Boruta ```{r} library(Boruta) library(mlbench) data(Ozone) ozone_clean <- na.omit(Ozone) set.seed(1) # Вот эта строка создает объект (ждите завершения!) boruta_output <- Boruta(V4 ~ ., data = ozone_clean, doTrace = 0) # А вот теперь печать сработает print(attStats(boruta_output)) plot(boruta_output, cex.axis = 0.7, las = 2, main = "Отбор признаков Boruta для набора Ozone") jpeg("boruta_ozone_boxplot.jpg", width = 1000, height = 600) plot(boruta_output, cex.axis = 0.7, las = 2, main = "Отбор признаков Boruta для набора Ozone") dev.off() ```