library(caret)
library(arules)
library(Boruta)
library(mlbench)
library(FSelectorRcpp)
model_list <- names(getModelInfo())
length(model_list)
## [1] 239
head(model_list, 10)
## [1] "ada" "AdaBag" "AdaBoost.M1" "adaboost" "amdai"
## [6] "ANFIS" "avNNet" "awnb" "awtan" "bag"
set.seed(123)
x <- matrix(rnorm(50*5), ncol = 5)
colnames(x) <- paste0("Var", 1:5)
y <- factor(rep(c("A", "B"), 25))
# сохранение в jpg
jpeg("plot_box.jpg", width = 800, height = 600)
print(featurePlot(x, y, plot = "box", main = "Box Plot Features"))
dev.off()
## png
## 2
jpeg("plot_density.jpg", width = 800, height = 600)
print(featurePlot(x, y, plot = "density", main = "Density Plot Features"))
dev.off()
## png
## 2
jpeg("plot_pairs.jpg", width = 800, height = 600)
print(featurePlot(x, y, plot = "pairs", main = "Pairs Plot Features"))
dev.off()
## png
## 2
# вывод графиков в отчёт
featurePlot(x, y, plot = "box", main = "Box Plot Features")

featurePlot(x, y, plot = "density", main = "Density Plot Features")

featurePlot(x, y, plot = "pairs", main = "Pairs Plot Features")

data(iris)
weights <- information_gain(Species ~ ., data = iris)
weights_sorted <- weights[order(-weights$importance), , drop = FALSE]
print(weights_sorted)
## attributes importance
## 4 Petal.Width 0.9554360
## 3 Petal.Length 0.9402853
## 1 Sepal.Length 0.4521286
## 2 Sepal.Width 0.2672750
barplot(weights_sorted$importance, names.arg = weights_sorted$attributes,
main = "Information Gain", col = "steelblue")

sl <- iris$Sepal.Length
d_interval <- arules::discretize(sl, method = "interval", breaks = 3)
cat("Метод Interval:\n"); print(table(d_interval))
## Метод Interval:
## d_interval
## [4.3,5.5) [5.5,6.7) [6.7,7.9]
## 52 70 28
d_freq <- arules::discretize(sl, method = "frequency", breaks = 3)
cat("\nМетод Frequency:\n"); print(table(d_freq))
##
## Метод Frequency:
## d_freq
## [4.3,5.4) [5.4,6.3) [6.3,7.9]
## 46 53 51
d_cluster <- arules::discretize(sl, method = "cluster", breaks = 3)
cat("\nМетод Cluster:\n"); print(table(d_cluster))
##
## Метод Cluster:
## d_cluster
## [4.3,5.33) [5.33,6.27) [6.27,7.9]
## 46 53 51
d_fixed <- arules::discretize(sl, method = "fixed", breaks = c(0, 5, 6, 8))
cat("\nМетод Fixed:\n"); print(table(d_fixed))
##
## Метод Fixed:
## d_fixed
## [0,5) [5,6) [6,8]
## 22 61 67
data("Ozone")
ozone_clean <- na.omit(Ozone)
set.seed(123)
boruta_output <- Boruta(V4 ~ ., data = ozone_clean, doTrace = 0)
print(boruta_output)
## Boruta performed 18 iterations in 0.2640769 secs.
## 9 attributes confirmed important: V1, V10, V11, V12, V13 and 4 more;
## 3 attributes confirmed unimportant: V2, V3, V6;
getSelectedAttributes(boruta_output, withTentative = FALSE)
## [1] "V1" "V5" "V7" "V8" "V9" "V10" "V11" "V12" "V13"
attStats(boruta_output)
## meanImp medianImp minImp maxImp normHits decision
## V1 0.40660229 0.39874710 0.37208192 0.50361585 1.00000000 Confirmed
## V2 0.04391890 0.03169822 -0.02604472 0.13137821 0.11111111 Rejected
## V3 -0.03235907 -0.04528594 -0.08039941 0.03178173 0.00000000 Rejected
## V5 0.37961385 0.37663333 0.33809868 0.42147363 1.00000000 Confirmed
## V6 0.04740489 0.05979747 -0.01572443 0.12718160 0.05555556 Rejected
## V7 0.51883205 0.50588169 0.46725744 0.59114026 1.00000000 Confirmed
## V8 0.77086858 0.76889989 0.73251688 0.81327051 1.00000000 Confirmed
## V9 0.86915268 0.86432645 0.84273725 0.92413075 1.00000000 Confirmed
## V10 0.42389058 0.41739463 0.38164901 0.49245967 1.00000000 Confirmed
## V11 0.55143690 0.54721914 0.49482770 0.61161304 1.00000000 Confirmed
## V12 0.66051279 0.65832222 0.60234621 0.73958611 1.00000000 Confirmed
## V13 0.42761454 0.42057856 0.38618408 0.46920282 1.00000000 Confirmed
plot(boruta_output, cex.axis = 0.7, las = 2, xlab = "",
main = "Важность признаков (Boruta)")
