Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GMTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
margarr
GMTool
Commits
0be63053
Commit
0be63053
authored
Jun 20, 2022
by
Mario Garrido Tapias
Browse files
Options
Downloads
Patches
Plain Diff
3D PCA and Var Biplot
parent
30cbf0b7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MultivariateAnalysis.R
+33
-13
33 additions, 13 deletions
MultivariateAnalysis.R
with
33 additions
and
13 deletions
MultivariateAnalysis.R
+
33
−
13
View file @
0be63053
...
...
@@ -6,7 +6,8 @@
# LIBRERIAS #
#############
library
(
stats
)
# Calculos
library
(
factoextra
)
# Representaciones
library
(
factoextra
)
# PCAs representations
library
(
plotly
)
# 3D PCA representations
############################# ####################
# CONJUNTO de ENTRENAMIENTO # # CONJUNTO de TEST #
...
...
@@ -17,16 +18,18 @@ library(rsample)
jugadoresRepes
<-
laLigaPlayersStudy
[
rowsPIn2C
[,
1
],
]
jugadoresRepes
<-
rbind
(
jugadoresRepes
,
laLigaPlayersStudy
[
rowsPIn2C
[,
2
],
])
rowsQuit
<-
c
(
rowsPIn2C
[,
1
],
rowsPIn2C
[,
2
])
laLigaPlayersSplit
<-
laLigaPlayersStudy
[
-
rowsQuit
,
]
laLigaPlayersSplit
$
position
.1920
<-
laLigaPlayers
[
-
rowsQuit
,]
$
position.1920
laLigaPlayersSplit
$
position
<-
laLigaPlayers
[
-
rowsQuit
,]
$
position.1920
laLiga_split
<-
initial_split
(
laLigaPlayersSplit
,
prop
=
8
/
10
,
strata
=
"position
.1920
"
)
laLiga_split
<-
initial_split
(
laLigaPlayersSplit
,
prop
=
8
/
10
,
strata
=
"position"
)
train
<-
training
(
laLiga_split
)
train
<-
train
[,
-39
]
train
<-
rbind
(
train
,
jugadoresRepes
)
test
<-
testing
(
laLiga_split
)
test
<-
test
[,
-39
]
# ToDo
plotFor3SeasonsForPos
(
laLigaPlayers
,
"position"
)
plotFor3SeasonsForPos
(
train
,
"position"
)
plotFor3SeasonsForPos
(
test
,
"position"
)
...
...
@@ -54,12 +57,25 @@ rownames(pca_laLiga$x) <- train$player
# Con 48 PC -> Suma de los 2 primeros = 57.44, Suma de los 3 primeros = 33.925
# Con 35 PC -> Suma de los 2 primeros = 19.96, Suma de los 3 primeros = 24.15
# REPRESENTACIONES
repeatedPlayers
<-
which
(
duplicated
(
train
$
player
)
==
TRUE
)
for
(
player
in
repeatedPlayers
){
train
$
player
[
player
]
<-
paste
(
train
$
player
[
player
],
2
,
sep
=
""
)
}
rownames
(
pca_laLiga
$
x
)
<-
train
$
player
# REPRESENTATIONS
# 2D
fviz_pca_ind
(
pca_laLiga
,
geom.ind
=
"point"
,
col.ind
=
"
#FC4E07
"
,
col.ind
=
"
aquamarine3
"
,
axes
=
c
(
1
,
2
),
pointsize
=
1.5
)
# 3D
data
<-
data.frame
(
pca_laLiga
$
x
)
fig
<-
plot_ly
(
data
,
x
=
~
PC1
,
y
=
~
PC2
,
z
=
~
PC3
,
colors
=
c
(
'aquamarine3'
)
)
%>%
add_markers
(
size
=
12
)
fig
# CREACION del vector POSICIONES
colores
<-
function
(
vec
){
# la función rainbow() devuelve un vector que contiene el número de colores distintos
...
...
@@ -82,13 +98,17 @@ plot(pca_laLiga$x[,1:2], col = colores(unique(laLigaPlayers$position.1718)),
legend
(
"topright"
,
legend
=
unique
(
laLigaPlayers
$
position.1718
),
col
=
colores
(
unique
(
laLigaPlayers
$
position.1718
)),
pch
=
19
,
cex
=
0.8
)
table
(
laLigaPlayers
$
position.1718
)
fviz_pca_var
(
pca_laLiga
,
col.var
=
"cos2"
,
geom.var
=
"arrow"
,
labelsize
=
2
,
repel
=
FALSE
)
# BIPLOT
biplot
(
pca_laLiga
,
scale
=
0
,
cex
=
0.5
,
col
=
c
(
"dodgerblue3"
,
"deeppink3"
))
# SELECCIÓN DEL NUMERO DE PC
fviz_screeplot
(
pca_laLiga
,
addlabels
=
TRUE
,
ylim
=
c
(
0
,
40
))
# BIPLOT (toSave)
biplot
(
pca_laLiga
,
scale
=
0
,
cex
=
0.5
,
col
=
c
(
"khaki4"
,
"darkorchid3"
))
fviz_pca_biplot
(
pca_laLiga
)
fviz_pca_var
(
pca_laLiga
,
col.var
=
"contrib"
,
gradient.cols
=
c
(
"#FC4E07"
,
"#E7B800"
,
"#006600"
),
labelsize
=
3
,
repel
=
TRUE
)
# SELECCIÓN DEL NUMERO DE PC (700x550)
fviz_screeplot
(
pca_laLiga
,
addlabels
=
TRUE
,
ylim
=
c
(
0
,
40
),
xlab
=
"Dimensiones"
,
ylab
=
"Porcentaje de variabilidad explicada"
)
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