Examen

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

R version 3.6.

2 (2019-12-12) -- "Dark and Stormy Night"


Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.


You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.


Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or


'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:


1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_MONETARY failed, using "C"
[R.app GUI 1.70 (7735) x86_64-apple-darwin15.6.0]

WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work.
Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system
preferences accordingly.
[Workspace restored from /Users/oscardavidlopez/.RData]
[History restored from /Users/oscardavidlopez/.Rapp.history]

> datosh <- read_csv(file.choose())


Error in read_csv(file.choose()) : could not find function "read_csv"
> datosh <- read.csv(file.choose())
> datosh
vendedor Indice_ventas Creatividad Razonamiento_mec.nico
1 1 93.0 9 12
2 2 88.8 7 10
3 3 95.0 8 12
4 4 101.3 13 14
5 5 102.0 10 15
6 6 95.8 10 14
7 7 95.5 9 12
8 8 110.8 18 20
9 9 102.8 10 17
10 10 106.8 14 18
11 11 103.3 12 17
12 12 99.5 10 18
13 13 103.5 16 17
14 14 99.5 8 10
15 15 100.0 13 10
16 16 81.5 7 9
17 17 101.3 11 12
18 18 103.3 11 14
19 19 95.3 5 14
20 20 99.5 17 17
21 21 88.5 10 12
22 22 99.3 5 11
23 23 87.5 9 9
24 24 105.3 12 15
25 25 107.0 16 19
26 26 93.3 10 15
27 27 106.8 14 16
28 28 106.8 10 16
29 29 92.3 8 10
30 30 106.3 9 17
31 31 106.0 18 15
32 32 88.3 13 11
33 33 96.0 7 15
34 34 94.3 10 12
35 35 106.5 18 17
36 36 106.5 8 13
37 37 92.0 18 16
38 38 102.0 13 12
39 39 108.3 15 19
40 40 106.8 14 20
41 41 102.5 9 17
42 42 92.5 13 15
43 43 102.8 17 20
44 44 83.3 1 5
45 45 94.8 7 16
46 46 103.5 18 13
47 47 89.5 7 15
48 48 84.3 8 8
49 49 104.3 14 12
50 50 106.0 12 16
Razonamiento_abstracto Habilidad_matem.tica
1 9 20
2 10 15
3 9 26
4 12 29
5 12 32
6 11 21
7 9 25
8 15 51
9 13 31
10 11 39
11 12 32
12 8 31
13 11 34
14 11 34
15 8 34
16 5 16
17 11 32
18 11 35
19 13 30
20 11 27
21 7 15
22 11 42
23 7 16
24 12 37
25 12 39
26 7 23
27 12 39
28 11 49
29 13 17
30 11 44
31 10 43
32 8 10
33 11 27
34 11 19
35 10 42
36 14 47
37 8 18
38 14 28
39 12 41
40 12 37
41 13 32
42 6 23
43 10 32
44 9 15
45 11 24
46 12 37
47 11 14
48 8 9
49 12 36
50 11 39
> summary(datosh)
vendedor Indice_ventas Creatividad Razonamiento_mec.nico
Min. : 1.00 Min. : 81.50 Min. : 1.00 Min. : 5.00
1st Qu.:13.25 1st Qu.: 93.55 1st Qu.: 8.25 1st Qu.:12.00
Median :25.50 Median :100.65 Median :10.00 Median :15.00
Mean :25.50 Mean : 98.84 Mean :11.22 Mean :14.18
3rd Qu.:37.75 3rd Qu.:105.05 3rd Qu.:14.00 3rd Qu.:17.00
Max. :50.00 Max. :110.80 Max. :18.00 Max. :20.00
Razonamiento_abstracto Habilidad_matem.tica
Min. : 5.00 Min. : 9.00
1st Qu.: 9.00 1st Qu.:21.50
Median :11.00 Median :31.50
Mean :10.56 Mean :29.76
3rd Qu.:12.00 3rd Qu.:37.00
Max. :15.00 Max. :51.00
> cor(datosh)
vendedor Indice_ventas Creatividad
vendedor 1.00000000 -0.01091394 0.09728668
Indice_ventas -0.01091394 1.00000000 0.57203630
Creatividad 0.09728668 0.57203630 1.00000000
Razonamiento_mec.nico 0.03329583 0.70807381 0.59073605
Razonamiento_abstracto 0.02748133 0.67440731 0.14690742
Habilidad_matem.tica -0.01368408 0.92731157 0.41263945
Razonamiento_mec.nico Razonamiento_abstracto
vendedor 0.03329583 0.02748133
Indice_ventas 0.70807381 0.67440731
Creatividad 0.59073605 0.14690742
Razonamiento_mec.nico 1.00000000 0.38595021
Razonamiento_abstracto 0.38595021 1.00000000
Habilidad_matem.tica 0.57455327 0.56637215
Habilidad_matem.tica
vendedor -0.01368408
Indice_ventas 0.92731157
Creatividad 0.41263945
Razonamiento_mec.nico 0.57455327
Razonamiento_abstracto 0.56637215
Habilidad_matem.tica 1.00000000
> cor(datosh)
vendedor Indice_ventas Creatividad Razonamiento_mec.nico
Razonamiento_abstracto Habilidad_matem.tica
vendedor 1.00000000 -0.01091394 0.09728668 0.03329583
0.02748133 -0.01368408
Indice_ventas -0.01091394 1.00000000 0.57203630 0.70807381
0.67440731 0.92731157
Creatividad 0.09728668 0.57203630 1.00000000 0.59073605
0.14690742 0.41263945
Razonamiento_mec.nico 0.03329583 0.70807381 0.59073605 1.00000000
0.38595021 0.57455327
Razonamiento_abstracto 0.02748133 0.67440731 0.14690742 0.38595021
1.00000000 0.56637215
Habilidad_matem.tica -0.01368408 0.92731157 0.41263945 0.57455327
0.56637215 1.00000000
> n <- nrow(datos)
Error in nrow(datos) : object 'datos' not found
> n <- nrow(datosh)
> muestra <- sample(n, n * .70)
> train <- datosh[muestra, ]
> test <- datosh[-muestra, ]
> train
vendedor Indice_ventas Creatividad Razonamiento_mec.nico Razonamiento_abstracto
Habilidad_matem.tica
12 12 99.5 10 18 8
31
18 18 103.3 11 14 11
35
43 43 102.8 17 20 10
32
16 16 81.5 7 9 5
16
29 29 92.3 8 10 13
17
50 50 106.0 12 16 11
39
38 38 102.0 13 12 14
28
22 22 99.3 5 11 11
42
20 20 99.5 17 17 11
27
4 4 101.3 13 14 12
29
32 32 88.3 13 11 8
10
28 28 106.8 10 16 11
49
44 44 83.3 1 5 9
15
1 1 93.0 9 12 9
20
21 21 88.5 10 12 7
15
31 31 106.0 18 15 10
43
48 48 84.3 8 8 8
9
45 45 94.8 7 16 11
24
34 34 94.3 10 12 11
19
46 46 103.5 18 13 12
37
26 26 93.3 10 15 7
23
13 13 103.5 16 17 11
34
40 40 106.8 14 20 12
37
15 15 100.0 13 10 8
34
19 19 95.3 5 14 13
30
35 35 106.5 18 17 10
42
8 8 110.8 18 20 15
51
39 39 108.3 15 19 12
41
7 7 95.5 9 12 9
25
23 23 87.5 9 9 7
16
24 24 105.3 12 15 12
37
27 27 106.8 14 16 12
39
41 41 102.5 9 17 13
32
36 36 106.5 8 13 14
47
42 42 92.5 13 15 6
23
> test
vendedor Indice_ventas Creatividad Razonamiento_mec.nico Razonamiento_abstracto
Habilidad_matem.tica
2 2 88.8 7 10 10
15
3 3 95.0 8 12 9
26
5 5 102.0 10 15 12
32
6 6 95.8 10 14 11
21
9 9 102.8 10 17 13
31
10 10 106.8 14 18 11
39
11 11 103.3 12 17 12
32
14 14 99.5 8 10 11
34
17 17 101.3 11 12 11
32
25 25 107.0 16 19 12
39
30 30 106.3 9 17 11
44
33 33 96.0 7 15 11
27
37 37 92.0 18 16 8
18
47 47 89.5 7 15 11
14
49 49 104.3 14 12 12
36
> set.seed(42)
> datosh <- read.csv(file.choose())
> n <- nrow(datos)
Error in nrow(datos) : object 'datos' not found
> n <- nrow(datosh)
> muestra <- sample(n, n * .70)
> train <- datosh[muestra, ]
> test <- datosh[-muestra, ]
> train
vendedor Indice_ventas Creatividad Razonamiento_mec.nico Razonamiento_abstracto
Habilidad_matem.tica
49 49 104.3 14 12 12
36
37 37 92.0 18 16 8
18
1 1 93.0 9 12 9
20
25 25 107.0 16 19 12
39
10 10 106.8 14 18 11
39
36 36 106.5 8 13 14
47
18 18 103.3 11 14 11
35
24 24 105.3 12 15 12
37
7 7 95.5 9 12 9
25
45 45 94.8 7 16 11
24
47 47 89.5 7 15 11
14
50 50 106.0 12 16 11
39
20 20 99.5 17 17 11
27
26 26 93.3 10 15 7
23
3 3 95.0 8 12 9
26
40 40 106.8 14 20 12
37
27 27 106.8 14 16 12
39
31 31 106.0 18 15 10
43
13 13 103.5 16 17 11
34
5 5 102.0 10 15 12
32
38 38 102.0 13 12 14
28
2 2 88.8 7 10 10
15
28 28 106.8 10 16 11
49
8 8 110.8 18 20 15
51
41 41 102.5 9 17 13
32
48 48 84.3 8 8 8
9
46 46 103.5 18 13 12
37
11 11 103.3 12 17 12
32
15 15 100.0 13 10 8
34
34 34 94.3 10 12 11
19
4 4 101.3 13 14 12
29
30 30 106.3 9 17 11
44
44 44 83.3 1 5 9
15
32 32 88.3 13 11 8
10
12 12 99.5 10 18 8
31
> test
vendedor Indice_ventas Creatividad Razonamiento_mec.nico Razonamiento_abstracto
Habilidad_matem.tica
6 6 95.8 10 14 11
21
9 9 102.8 10 17 13
31
14 14 99.5 8 10 11
34
16 16 81.5 7 9 5
16
17 17 101.3 11 12 11
32
19 19 95.3 5 14 13
30
21 21 88.5 10 12 7
15
22 22 99.3 5 11 11
42
23 23 87.5 9 9 7
16
29 29 92.3 8 10 13
17
33 33 96.0 7 15 11
27
35 35 106.5 18 17 10
42
39 39 108.3 15 19 12
41
42 42 92.5 13 15 6
23
43 43 102.8 17 20 10
32
> test_nor <- scale(test[-1])
> train_nor <- scale(train[-1])
> library(neuralnet)
> red1 <-
neuralnet(Indice_ventas~Creatividad+Razonamiento_mec.nico+Razonamiento_abstracto+Ha
bilidad_matem.tica, train_nor, hidden=10, threshold=0.01)
> red2 <-
neuralnet(Indice_ventas~Razonamiento_mec.nico+Razonamiento_abstracto+Habilidad_mate
m.tica, train_nor, hidden=20, threshold=0.01)
> red1$result.matrix[1]
[1] 0.007296295
> red2$result.matrix[1]
[1] 0.01473328
> pronostico <- (compute(red1, test_nor))$net.result
> pronostico
[,1]
6 -0.381628586
9 0.642912066
14 0.371907728
16 -1.635834362
17 0.547347319
19 0.180065017
21 -1.201364725
22 0.342886416
23 -1.238023656
29 -0.690127292
33 0.004080174
35 1.139859072
39 1.382349186
42 -0.426317636
43 0.542120878
> indice.predict <- pronostico$net.result
Error in pronostico$net.result : $ operator is invalid for atomic vectors
> indice.predict <- pronostico$net.result*(max(datosh$Indice_ventas)-
min(datosh$Indice_ventas))+min(datosh$Indice_ventas)
Error in pronostico$net.result : $ operator is invalid for atomic vectors
> pronostico <- (compute(red1, within(test_nor,rm(Indice_ventas)))
+
+
+
+
>
> pronostico <- (compute(red1, within(test_nor,rm(Indice_ventas)))
+
+
> pronostico
[,1]
6 -0.381628586
9 0.642912066
14 0.371907728
16 -1.635834362
17 0.547347319
19 0.180065017
21 -1.201364725
22 0.342886416
23 -1.238023656
29 -0.690127292
33 0.004080174
35 1.139859072
39 1.382349186
42 -0.426317636
43 0.542120878
> datos_nor <- scale(datosh[-1])
> diferencias <- datos_nor[,2]-pronostico
Error: dims [product 15] do not match the length of object [50]
In addition: Warning message:
In datos_nor[, 2] - pronostico :
longer object length is not a multiple of shorter object length
> i.predict <- pronostico$net.result
Error in pronostico$net.result : $ operator is invalid for atomic vectors
> i.predict <- pronostico
> i.real <- (test_nor$Indice_ventas)
Error in test_nor$Indice_ventas :
$ operator is invalid for atomic vectors
> i.real <- (test_nor[,2])
> i.real
6 9 14 16 17 19 21
22 23 29 33
-0.04995542 -0.04995542 -0.54950959 -0.79928667 0.19982167 -1.29884084 -0.04995542
-1.29884084 -0.29973250 -0.54950959 -0.79928667
35 39 42 43
1.94826126 1.19893000 0.69937584 1.69848417
> suma <- sum((i.real-i.predict)^2/nrow(test_nor))
> suma
[1] 0.8869949
> eficiencia <- 100-suma
> eficiencia
[1] 99.11301
> pronostico <- (compute(red1, within(test_nor,rm(Indice_ventas)))
+ i.predict <- pronostico
Error: unexpected symbol in:
"pronostico <- (compute(red1, within(test_nor,rm(Indice_ventas)))
i.predict"
> pronostico <- (compute(red1, test_nor))$net.result
> i.predict <- pronostico
> i.real <- (test_nor[,2])
> suma <- sum((i.real-i.predict)^2/nrow(test_nor))
> eficiencia <- 100-suma
> eficiencia
[1] 99.11301
>

You might also like