Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projet SY19
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Heloise Chevalier
projet SY19
Commits
ed8875e5
Commit
ed8875e5
authored
6 years ago
by
dolfinsbizou
Browse files
Options
Downloads
Patches
Plain Diff
Clustering
parent
53cd4b3a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
classification.R
+92
-0
92 additions, 0 deletions
classification.R
rapport.Rmd
+2
-1
2 additions, 1 deletion
rapport.Rmd
with
94 additions
and
1 deletion
classification.R
0 → 100644
+
92
−
0
View file @
ed8875e5
library
(
MASS
)
library
(
caret
)
library
(
e1071
)
# Chargement du jeu de données
clus.data
<-
read.table
(
"tp3_a18_clas_app.txt"
)
clus.data
$
y
<-
clus.data
$
y
-
1
# On nomme les classes 0 et 1 plutôt que 1 et 2 (plus pratique pour la régression logistique)
clus.data.X
<-
clus.data
[
-37
]
clus.data.y
<-
clus.data
$
y
n
<-
dim
(
clus.data
)[
1
]
p
<-
dim
(
clus.data
)[
2
]
# TODO Questions à régler
# ACP ? pas ACP
# Régularisation des modèles ? Quand ? Sélection de valeurs ?
# Variables diverses
models.list
<-
c
(
"qda"
,
"lda"
,
"nbc"
,
"logreg"
)
# Liste des modèles à tester
models.error
<-
c
()
trials
<-
10
# Nombre d'essais de cross-validation à faire par modèle
n_folds
<-
5
# Nombre de blocs pour la cross-validation
# Test pour chaque modèle
for
(
model
in
models.list
)
# Pour chaque modèle
{
models.error
[
model
]
<-
0
for
(
i
in
c
(
1
:
trials
))
# On fait plusieurs essais
{
folds
<-
sample
(
rep
(
1
:
n_folds
,
length.out
=
n
))
for
(
k
in
1
:
n_folds
)
# Sur chaque segment de la cross-validation
{
clus.train
<-
clus.data
[
folds
!=
k
,]
clus.train.X
<-
clus.train
[,
-
p
]
clus.train.y
<-
clus.train
$
y
clus.test
<-
clus.data
[
folds
==
k
,]
clus.test.X
<-
clus.test
[,
-
p
]
clus.test.y
<-
clus.test
$
y
# Apprentissage du modèle
if
(
model
==
"qda"
)
{
clus.model
<-
qda
(
clus.train.X
,
clus.train.y
)
}
else
if
(
model
==
"lda"
)
{
clus.model
<-
lda
(
clus.train.X
,
clus.train.y
)
}
else
if
(
model
==
"nbc"
)
{
# FIXME naiveBayes ne fonctionne pas, predict sort un truc vide
#clus.model <- naiveBayes(y~., data=clus.train)
clus.model
<-
NULL
}
else
if
(
model
==
"logreg"
)
{
clus.model
<-
glm
(
y
~
.
,
data
=
clus.train
,
family
=
binomial
)
}
else
{
clus.model
<-
NULL
}
if
(
!
is.null
(
clus.model
))
{
if
(
model
==
"logreg"
)
{
clus.predict
<-
round
(
predict
(
clus.model
,
clus.test.X
,
type
=
"response"
))
models.error
[
model
]
<-
models.error
[
model
]
+
confusionMatrix
(
as.factor
(
as.integer
(
clus.predict
)),
as.factor
(
clus.test.y
))
$
overall
[
"Accuracy"
]
}
else
if
(
model
==
"nbc"
)
{
clus.predict
<-
predict
(
clus.model
,
clus.test.X
)
models.error
[
model
]
<-
models.error
[
model
]
+
confusionMatrix
(
clus.predict
,
as.factor
(
clus.test.y
))
$
overall
[
"Accuracy"
]
}
else
{
clus.predict
<-
predict
(
clus.model
,
clus.test.X
)
models.error
[
model
]
<-
models.error
[
model
]
+
confusionMatrix
(
clus.predict
$
class
,
as.factor
(
clus.test.y
))
$
overall
[
"Accuracy"
]
}
}
}
}
models.error
[
model
]
<-
models.error
[
model
]
/
(
n_folds
*
trials
)
}
print
(
models.error
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rapport.Rmd
+
2
−
1
View file @
ed8875e5
---
title: "R Notebook"
title: "Projet 1 SY19"
subtitle: "CHEVALIER Héloïse, JORANDON Guillaume"
output: html_notebook
---
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment