-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.mlpbis.R
59 lines (44 loc) · 1.57 KB
/
bot.mlpbis.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
####################################
# mlpbis ( MLP)
###################################
####################
### Initialisation
####################
# Chargement de la bibliothèque
library (e1071)
library("fdm2id")
source("addData.r")
# Chargement des données
awele.data = read.table ("awele.data", sep = ",", header = T)
# On crée la liste des objets dataSupp
listMLP = list(sum1ou2);
#####################
### Création du modèle
#####################
mlpbis.create.model = function(dataset)
{
#On ajoute les données
dataset = addData.completeData(dataset, listMLP)
# On calcule le décalage
decal = addData.getDecalage(listMLP)
selection = dataset [dataset [, 14+decal] == "G", ]
tunecontrole = tune.control(sampling="bootstrap",nboot=20,boot.size=1)
model = tune.nnet(C~., data = cbind.data.frame(Classe = selection[13+decal], selection[1:(12+decal)] ),size = 2:(6+decal),decay= c(.1,.01,.001),tunecontrol = tunecontrole)$best.model
return (model)
}
mlpbis.model =mlpbis.create.model (awele.data)
#####################
### Execution
#####################
mlpbis.exec = function (awele, model)
{
g = graines.matrix (awele)
g = addData.completeData(g, listMLP)
colnames(g)[1:12] = c (paste ("J", 1:6, sep = ""), paste ("A", 1:6, sep = ""))
prediction = factor(predict (model, as.data.frame(g), type = "class"))
ret = data.frame(matrix(data=0, ncol=6, nrow=1))
colnames(ret) = c (paste ("C", 1:6, sep = ""))
resultat = ret[c(prediction[1])] = 1
return (ret)
}
mlpbis = function (awele) return (mlpbis.exec (awele, mlpbis.model))