-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_script.r
44 lines (32 loc) · 1.35 KB
/
model_script.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 1. Install required packages
#install.packages("mlr")
#install.packages("e1071")
#install.packages("randomForest")
#install.packages("corrplot")
library(mlr)
library(corrplot)
# 2. Make sure you set the right path to the data csv file
path<-"<YOUR PATH>/model_data_no_labels.csv"
# 3. Importing data from csv.file
model_data <- read.csv(path,encoding="UTF-8")
model_data$X=NULL
# 4. Displaying matrix of correlations
arrayOfCorrelations <- cor(model_data)
corrplot(arrayOfCorrelations, order = "hclust")
# 5. Adding target columnt to dataset (You can label the data by yourself)
isOk <- c("OK", "OK", "NOTOK", "OK", "NOTOK", "OK", "OK", "OK", "NOTOK", "OK",
"OK", "OK", "NOTOK", "NOTOK", "NOTOK", "OK", "NOTOK", "OK", "OK", "OK",
"OK", "NOTOK","OK", "NOTOK", "NOTOK", "OK")
model_data['isOk'] = isOk
# 6. Defining task
classif_task = makeClassifTask(id = "testowy", data = model_data, target = "isOk")
# 7. Defining repetitive cross validation
rdesc = makeResampleDesc("RepCV", folds=4, reps = 10)
# 8. Learinig and validating model
rf = resample("classif.randomForest", classif_task, rdesc, measures = list(mmce,mcc,f1,acc,kappa))
svm = resample("classif.svm", classif_task, rdesc, measures = list(mmce,mcc,f1,acc,kappa))
knn = resample("classif.knn", classif_task, rdesc, measures = list(mmce,mcc,f1,acc,kappa))
# 9. Displaying results
rf
svm
knn