[R-es] FUZZY

Jose Betancourt Bethencourt bet@n@ter @end|ng |rom gm@||@com
Lun Feb 14 14:18:18 CET 2022


Estimado Carlos
GRACIAS POR SU RESPUESTA

Quisiera su ayuda en esto

En al artículo siguiente vimos este script que quisimos reproducir,
pero al tratar de hacerlo con nuestros datos  no nos funcionó, no me
percato de cuál es el error.
An example of fuzzy logic in R
Juan De Dios Santos, @jdiossantos


library(sets)
sets_options("universe", seq(1, 100, 0.5))

variables <- set(
  temperature = fuzzy_partition(varnames = c(cold = 30, good = 70, hot = 90),
                                sd = 5.0),
  humidity = fuzzy_partition(varnames = c(dry = 30, good = 60, wet = 80),
                             sd = 3.0),
  precipitation = fuzzy_partition(varnames = c(no.rain = 30, little.rain = 60,
                                               rain = 90), sd = 7.5),
  weather = fuzzy_partition(varnames = c(bad = 40, ok = 65, perfect = 80),
                            FUN = fuzzy_cone, radius = 10)
)


rules <- set(
  fuzzy_rule(temperature %is% good && humidity %is% dry &&
               precipitation %is% no.rain, weather %is% perfect),
  fuzzy_rule(temperature %is% hot && humidity %is% wet &&
               precipitation %is% rain, weather %is% bad),
  fuzzy_rule(temperature %is% cold, weather %is% bad),
  fuzzy_rule(temperature %is% good || humidity %is% good ||
               precipitation %is% little.rain, weather %is% ok),
  fuzzy_rule(temperature %is% hot && precipitation %is% little.rain,
             weather %is% ok),
  fuzzy_rule(temperature %is% hot && humidity %is% dry &&
               precipitation %is% little.rain, weather %is% ok)
) model <- fuzzy_system(variables, rules)


print(model)


plot(model)


#============================================

Lo que quiero hacer y no me funciona, pero no veo el error

library(sets)
# Set up the universe
sets_options("universe", seq(-2, 2, 0.01))

variables <- set(
  EDAD = fuzzy_partition(varnames = c(jóven = -1.166, maduro = 0.3305,
                                      viejo= 1.827),

IMC = fuzzy_partition(varnames = c(bajo = -1.376, ideal = 0,302, alto = 1.678),

TAS = fuzzy_partition(varnames = c(baja = -1.117, normal = 0,134,
                            alta = 1.385),
CV = fuzzy_partition(varnames = c(inadecuada = -1, adecuada= 0,
perfecta = 1),FUN = fuzzy_cone, radius = 0.1)
 )

DATOS ESTANDARIZADOS

    EDAD                       TAS        IMC
 [1,]  0.65872123  1.3850278  1.4429268
 [2,]  1.02371188  1.3850278  1.6778218
 [3,]  0.80471749  1.3850278  0.9731367
 [4,]  1.68069506  1.3850278  0.7382416
 [5,]  0.80471749  1.3850278  1.4429268
 [6,]  1.82669133  1.3850278  1.6778218
 [7,]  0.65872123  0.7595314  0.9731367
 [8,]  1.02371188  0.7595314  0.7382416
 [9,]  0.80471749  0.7595314 -0.4362337
[10,]  1.68069506  0.7595314 -0.9060238
[11,]  0.80471749  0.7595314 -0.2013386
[12,]  1.82669133  0.7595314  0.7382416
[13,]  0.14773431  0.1340350  0.7382416
[14,] -1.16623205 -0.4914615 -0.4362337
[15,] -0.94723765 -0.4914615 -0.9060238
[16,] -0.87423952 -0.4914615 -0.2013386
[17,] -0.80124139 -0.4914615  0.7382416
[18,] -1.16623205 -0.4914615 -0.6711287
[19,]  0.51272497 -0.4914615 -0.9060238
[20,] -0.87423952 -1.1169579 -0.9060238
[21,] -0.80124139 -1.1169579 -0.6711287
[22,] -0.58224700 -1.1169579 -1.1409189
[23,] -0.43625074 -1.1169579 -1.3758139
[24,] -1.16623205 -1.1169579 -0.9060238
[25,] -0.94723765 -1.1169579 -0.6711287
[26,] -0.87423952 -1.1169579 -1.1409189
[27,] -0.80124139 -1.1169579 -1.3758139
[28,] -1.16623205 -1.1169579  0.9731367
[29,]  0.51272497  1.3850278  1.4429268
[30,] -0.87423952  1.3850278  1.6778218
[31,] -0.80124139  1.3850278  0.9731367
[32,] -0.07126008  1.3850278  0.7382416
[33,]  0.80471749  1.3850278  1.4429268
[34,]  1.82669133  1.3850278  1.6778218
[35,]  0.65872123  0.7595314  0.9731367
[36,]  1.02371188  0.7595314  0.7382416
[37,]  0.80471749  0.7595314 -0.4362337
[38,]  1.68069506  0.7595314 -0.9060238
[39,]  0.80471749  0.7595314 -0.2013386
[40,]  0.87771562  0.7595314  0.7382416
[41,]  0.29373057  0.1340350  0.7382416
[42,] -1.16623205 -0.4914615 -0.4362337
[43,] -0.94723765 -0.4914615 -0.9060238
[44,] -0.87423952 -0.4914615 -0.2013386
[45,] -0.80124139 -0.4914615  0.7382416
[46,] -1.16623205 -0.4914615 -0.6711287
[47,]  0.51272497 -0.4914615 -0.9060238
[48,] -0.87423952 -1.1169579 -0.9060238
[49,] -0.80124139 -1.1169579 -0.6711287
[50,] -0.58224700 -1.1169579 -1.1409189
[51,] -0.43625074 -1.1169579 -1.3758139
[52,] -1.16623205 -1.1169579 -0.9060238
[53,] -1.16623205 -1.1169579 -0.6711287
[54,] -0.94723765 -1.1169579 -1.1409189
[55,] -0.87423952 -1.1169579 -1.3758139
[56,] -0.80124139 -1.1169579  0.9731367
[57,]  1.75369319  1.3850278  1.4429268
[58,]  1.60769693  1.3850278  1.6778218
[59,]  1.68069506  1.3850278  0.9731367
[60,]  0.87771562  1.3850278  0.7382416
[61,]  0.95071375  1.3850278  1.4429268
[62,] -0.43625074  1.3850278  1.6778218
[63,]  0.58572310  0.7595314  0.9731367
[64,]  1.60769693  0.7595314  0.7382416
[65,]  1.68069506  0.7595314 -0.4362337
[66,]  0.87771562  0.7595314 -0.9060238
[67,]  0.95071375  0.7595314 -0.2013386
[68,] -0.43625074  0.7595314  0.7382416
[69,]  0.58572310  0.1340350  0.7382416
[70,]  0.14773431 -0.4914615 -0.4362337
[71,] -1.16623205 -0.4914615 -0.9060238
[72,] -0.94723765 -0.4914615 -0.2013386
[73,] -0.87423952 -0.4914615  0.7382416
[74,] -0.80124139 -0.4914615 -0.6711287
[75,] -1.16623205 -0.4914615 -0.9060238
[76,]  0.14773431 -1.1169579 -0.9060238
[77,] -1.16623205 -1.1169579 -0.6711287
[78,] -0.94723765 -1.1169579 -1.1409189
[79,] -0.87423952 -1.1169579 -1.3758139
[80,] -0.80124139 -1.1169579 -0.9060238
[81,] -1.16623205 -1.1169579 -0.6711287
[82,] -0.14425821 -1.1169579 -1.1409189
[83,]  0.22073244 -1.1169579 -1.3758139
[84,]  0.14773431 -1.1169579  0.973136

















El 13/2/22, Carlos Ortega <cof using qualityexcellence.es> escribió:
> Hola José,
>
> Para salvar un data.frame en formato Excel,  puedes usar el paquete
> "writexl", desarrollado por los mismos que han desarrollado el que has
> usado para leer: "readxl".
>
>    - https://cloud.r-project.org/web/packages/writexl/index.html
>
> Y sobre la estandarización de variables, puedes ver aquí otras formas de
> hacer:
>
>    -
>
> https://stackoverflow.com/questions/15215457/standardize-data-columns-in-r
>    - Verás al final que el paquete "clusterSim" ofrece otras alternativas:
>       - https://cloud.r-project.org/web/packages/clusterSim/index.html
>
> Gracias,
> Carlos.
>
> El sáb, 12 feb 2022 a las 22:30, Jose Betancourt Bethencourt (<
> betanster using gmail.com>) escribió:
>
>> Estandaricé estas tres variables que adjunto en excel, quisiera salvar
>> la salida como archivo excel en un  lugar de la PC
>> Ademas apreciaria tener otros métodos para estandarizar
>>
>>
>> library(readxl)
>>
>>
>> df <- read_excel("C:/Users/betan/Desktop/Libro1.xlsx")
>> df
>> library (dplyr)
>> library(dummies)
>> library(kableExtra)
>>
>> scale(df[,c(1:3)])#salvar como excel en un lugar
>> _______________________________________________
>> R-help-es mailing list
>> R-help-es using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>


-- 
Dr. Jose A. Betancourt Bethencourt
Universidad de Ciencias Medicas Carlos j. Finlay



Más información sobre la lista de distribución R-help-es