forked from olabudzyn/mow_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.r
150 lines (102 loc) · 6.5 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
install.packages("utiml")
library("ParamHelpers")
library("mlr")
library("utiml")
#library("BBmisc")
library("mldr")
library(datarobot)
source("multilabelChain.R")
yeast_train <- read.arff("yeast-train",use_xml=TRUE,auto_extension = TRUE, "yeast.xml")
yeast_test <- read.arff("yeast-test",use_xml=TRUE,auto_extension = TRUE, "yeast.xml")
scene_train <- read.arff("scene-train",use_xml=TRUE,auto_extension = TRUE, "scene.xml")
scene_test <- read.arff("scene-test",use_xml=TRUE,auto_extension = TRUE, "scene.xml")
set.seed(1729)
yeast.data.train = yeast_train[["dataframe"]]
yeast.data.test = yeast_test[["dataframe"]]
scene.data.train = scene_train[["dataframe"]]
scene.data.test = scene_test[["dataframe"]]
########## YEAST
yeast.target = labels(yeast_train[["attributes"]])
yeast.labels = yeast.target[yeast_train[["labelIndices"]]]
yeast.feats = setdiff(yeast.target, yeast.labels)
yeast.new_data.train = yeast.data.train[yeast.feats]
yeast.new_data.test = yeast.data.test[yeast.feats]
yeast.logic_data <- lapply(yeast.data.train[yeast.labels], as.logical)
yeast.logic_data.test <- lapply(yeast.data.test[yeast.labels], as.logical)
yeast.data_with_logic = cbind(yeast.new_data.train, yeast.logic_data)
yeast.data_with_logic.test = cbind(yeast.new_data.test, yeast.logic_data.test)
########## SCENE
scene.target = labels(scene_train[["attributes"]])
scene.labels = scene.target[scene_train[["labelIndices"]]]
scene.feats = setdiff(scene.target, scene.labels)
scene.new_data.train = scene.data.train[scene.feats]
scene.new_data.test = scene.data.test[scene.feats]
scene.logic_data <- lapply(scene.data.train[scene.labels], as.logical)
scene.logic_data.test <- lapply(scene.data.test[scene.labels], as.logical)
scene.data_with_logic = cbind(scene.new_data.train, scene.logic_data)
scene.data_with_logic.test = cbind(scene.new_data.test, scene.logic_data.test)
#stworzenie klasyfikatorów binarnych
# drzewo decyzyjne
binary.tree = makeLearner("classif.rpart")
# Naiwny Bayes
binary.naiveBayes = makeLearner("classif.naiveBayes")
# Maszyna wektorów nosnych
binary.svm = makeLearner("classif.svm")
########################### PRZEWIDYWANIA DLA YEAST ##############################
yeast.labels_data <- do.call(cbind, yeast.data.test[yeast.labels])
yeast.logic_data <- lapply(yeast.data.train[yeast.labels], as.logical)
yeast.logic_data.test <- lapply(yeast.data.test[yeast.labels], as.logical)
s <- sample(1:14)
yeast.labels_data <- yeast.labels_data[,s]
yeast.logic_data <- yeast.logic_data[s]
yeast.logic_data.test <- yeast.logic_data.test[s]
##### results dla klasyfikatora naiveBayes
yeast.model.naiveBayes = multilabelChain(binary.naiveBayes, yeast.new_data.train, yeast.logic_data)
yeast.prediction.naiveBayes = predict.myChainClassier(yeast.model.naiveBayes, yeast.new_data.test, yeast.logic_data.test)
yeast.hammloss.naiveBayes <- measureMultilabelHamloss(yeast.labels_data, yeast.prediction.naiveBayes)
yeast.subset01.naiveBayes <- measureMultilabelSubset01(yeast.labels_data, yeast.prediction.naiveBayes)
yeast.f1.naiveBayes <- measureMultilabelF1(yeast.labels_data, yeast.prediction.naiveBayes)
yeast.acc.naiveBayes <- measureMultilabelACC(yeast.labels_data, yeast.prediction.naiveBayes)
##### results dla klasyfikatora tree
yeast.model.tree = multilabelChain(binary.tree, yeast.new_data.train, yeast.logic_data)
yeast.prediction.tree = predict.myChainClassier(yeast.model.tree, yeast.new_data.test, yeast.logic_data.test)
yeast.hammloss.tree <- measureMultilabelHamloss(yeast.labels_data, yeast.prediction.tree)
yeast.subset01.tree <- measureMultilabelSubset01(yeast.labels_data, yeast.prediction.tree)
yeast.f1.tree <- measureMultilabelF1(yeast.labels_data, yeast.prediction.tree)
yeast.acc.tree <- measureMultilabelACC(yeast.labels_data, yeast.prediction.tree)
##### results dla klasyfikatora svm
yeast.model.svm = multilabelChain(binary.svm, yeast.new_data.train, yeast.logic_data)
yeast.prediction.svm = predict.myChainClassier(yeast.model.svm, yeast.new_data.test, yeast.logic_data.test)
yeast.hammloss.svm <- measureMultilabelHamloss(yeast.labels_data, yeast.prediction.svm)
yeast.subset01.svm <- measureMultilabelSubset01(yeast.labels_data, yeast.prediction.svm)
yeast.f1.svm <- measureMultilabelF1(yeast.labels_data, yeast.prediction.svm)
yeast.acc.svm <- measureMultilabelACC(yeast.labels_data, yeast.prediction.svm)
########################### PRZEWIDYWANIA DLA SCENE ##############################
scene.labels_data <- do.call(cbind, scene.data.test[scene.labels])
scene.logic_data <- lapply(scene.data.train[scene.labels], as.logical)
scene.logic_data.test <- lapply(scene.data.test[scene.labels], as.logical)
sScene <- sample(1:6)
scene.labels_data <- scene.labels_data[,sScene]
scene.logic_data <- scene.logic_data[sScene]
scene.logic_data.test <- scene.logic_data.test[sScene]
##### results dla klasyfikatora naiveBayes
scene.model.naiveBayes = multilabelChain(binary.naiveBayes, scene.new_data.train, scene.logic_data)
scene.prediction.naiveBayes = predict.myChainClassier(scene.model.naiveBayes, scene.new_data.test, scene.logic_data.test)
scene.hammloss.naiveBayes <- measureMultilabelHamloss(scene.labels_data, scene.prediction.naiveBayes)
scene.subset01.naiveBayes <- measureMultilabelSubset01(scene.labels_data, scene.prediction.naiveBayes)
scene.f1.naiveBayes <- measureMultilabelF1(scene.labels_data, scene.prediction.naiveBayes)
scene.acc.naiveBayes <- measureMultilabelACC(scene.labels_data, scene.prediction.naiveBayes)
##### results dla klasyfikatora tree
scene.model.tree = multilabelChain(binary.tree, scene.new_data.train, scene.logic_data)
scene.prediction.tree = predict.myChainClassier(scene.model.tree, scene.new_data.test, scene.logic_data.test)
scene.hammloss.tree <- measureMultilabelHamloss(scene.labels_data, scene.prediction.tree)
scene.subset01.tree <- measureMultilabelSubset01(scene.labels_data, scene.prediction.tree)
scene.f1.tree <- measureMultilabelF1(scene.labels_data, scene.prediction.tree)
scene.acc.tree <- measureMultilabelACC(scene.labels_data, scene.prediction.tree)
##### results dla klasyfikatora svm
scene.model.svm = multilabelChain(binary.svm, scene.new_data.train, scene.logic_data)
scene.prediction.svm = predict.myChainClassier(scene.model.svm, scene.new_data.test, scene.logic_data.test)
scene.hammloss.svm <- measureMultilabelHamloss(scene.labels_data, scene.prediction.svm)
scene.subset01.svm <- measureMultilabelSubset01(scene.labels_data, scene.prediction.svm)
scene.f1.svm <- measureMultilabelF1(scene.labels_data, scene.prediction.svm)
scene.acc.svm <- measureMultilabelACC(scene.labels_data, scene.prediction.svm)