statslibx 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
statslibx/descriptive.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import numpy as np
2
2
  import pandas as pd
3
+ import polars as pl
3
4
  from typing import Optional, Union, Literal, List
4
5
  from datetime import datetime
5
6
  import flet as ft
@@ -13,24 +14,42 @@ import plotly.express as px
13
14
  class DescriptiveStats:
14
15
  """
15
16
  Clase para estadística descriptiva univariada y multivariada
17
+ Class for univariate and multivariate descriptive statistics
16
18
  """
17
19
 
18
- def __init__(self, data: Union[pd.DataFrame, np.ndarray],
19
- backend: Literal['pandas', 'polars'] = 'pandas'):
20
+ def __init__(self, data: Union[pd.DataFrame, np.ndarray],
21
+ sep: str = None,
22
+ decimal: str = None,
23
+ thousand: str = None,
24
+ backend: Literal['pandas', 'polars'] = 'pandas'):
20
25
  """
21
- Inicializar con DataFrame o array numpy
26
+ # Inicialize DataFrame
22
27
 
23
- Parameters:
24
- -----------
25
- data : DataFrame o ndarray
26
- Datos a analizar
27
- backend : str
28
- 'pandas' o 'polars' para procesamiento
28
+ ## **Parameters:**
29
+
30
+ - **data** : Data to analyze
31
+ - **sep** : Column separator
32
+ - **decimal** : Decimal separator
33
+ - **thousand** : Thousand separator
34
+ - **backend** : 'pandas' or 'polars' for processing
35
+ (Proximamente estara habilitado polars para big data)
36
+
37
+ **Examples:**
38
+
39
+ ``Example 1:
40
+ stats = DescriptiveStats(data)
41
+ ``
29
42
  """
30
43
 
31
44
  if isinstance(data, str) and os.path.exists(data):
32
45
  data = DescriptiveStats.from_file(data).data
33
46
 
47
+ if isinstance(data, pl.DataFrame):
48
+ raise TypeError(
49
+ "Polars aún no soportado. Use pandas.DataFrame."
50
+ )
51
+
52
+
34
53
  if isinstance(data, np.ndarray):
35
54
  if data.ndim == 1:
36
55
  data = pd.DataFrame({'var': data})
@@ -40,26 +59,37 @@ class DescriptiveStats:
40
59
  self.data = data
41
60
  self.backend = backend
42
61
  self._numeric_cols = data.select_dtypes(include=[np.number]).columns.tolist()
62
+ self.sep = sep
63
+ self.decimal = decimal
64
+ self.thousand = thousand
43
65
 
44
- @staticmethod
45
- def from_file(path: str):
66
+ @classmethod
67
+ def from_file(self, path: str):
46
68
  """
47
69
  Carga automática de archivos y devuelve instancia de Intelligence.
48
70
  Soporta CSV, Excel, TXT, JSON, Parquet, Feather, TSV.
71
+ Automatic file upload and returns Intelligence instance.
72
+ Supports CSV, Excel, TXT, JSON, Parquet, Feather, TSV.
73
+
74
+ Parametros / Parameters:
75
+ ------------------------
76
+ path : str
77
+ Ruta del archivo
78
+ File path
49
79
  """
50
80
  if not os.path.exists(path):
51
- raise FileNotFoundError(f"Archivo no encontrado: {path}")
81
+ raise FileNotFoundError(f"Archivo no encontrado / File not found: {path}")
52
82
 
53
83
  ext = os.path.splitext(path)[1].lower()
54
84
 
55
85
  if ext == ".csv":
56
- df = pd.read_csv(path)
86
+ df = pd.read_csv(path, sep=self.sep, decimal=self.decimal, thousand=self.thousand)
57
87
 
58
88
  elif ext in [".xlsx", ".xls"]:
59
- df = pd.read_excel(path)
89
+ df = pd.read_excel(path, decimal=self.decimal, thousand=self.thousand)
60
90
 
61
91
  elif ext in [".txt", ".tsv"]:
62
- df = pd.read_table(path)
92
+ df = pd.read_table(path, sep=self.sep, decimal=self.decimal, thousand=self.thousand)
63
93
 
64
94
  elif ext == ".json":
65
95
  df = pd.read_json(path)
@@ -71,56 +101,124 @@ class DescriptiveStats:
71
101
  df = pd.read_feather(path)
72
102
 
73
103
  else:
74
- raise ValueError(f"Formato no soportado: {ext}")
104
+ raise ValueError(f"Formato no soportado / Unsupported format: {ext}")
75
105
 
76
106
  return DescriptiveStats(df)
77
107
 
78
108
  # ============= MÉTODOS UNIVARIADOS =============
79
109
 
80
110
  def mean(self, column: Optional[str] = None) -> Union[float, pd.Series]:
81
- """Media aritmética"""
111
+ """
112
+ Media aritmética / Arithmetic mean
113
+
114
+ Parametros / Parameters:
115
+ ------------------------
116
+ **column** : str
117
+ Nombre de la columna
118
+ Name of the column
119
+ """
82
120
  if column:
83
121
  return self.data[column].mean()
84
122
  return self.data[self._numeric_cols].mean()
85
123
 
86
124
  def median(self, column: Optional[str] = None) -> Union[float, pd.Series]:
87
- """Mediana"""
125
+ """
126
+ Mediana / Median
127
+
128
+ Parametros / Parameters:
129
+ ------------------------
130
+ **column** : str
131
+ Nombre de la columna
132
+ Name of the column
133
+ """
88
134
  if column:
89
135
  return self.data[column].median()
90
136
  return self.data[self._numeric_cols].median()
91
137
 
92
138
  def mode(self, column: Optional[str] = None):
93
- """Moda"""
139
+ """
140
+ Moda / Mode
141
+
142
+ Parametros / Parameters:
143
+ ------------------------
144
+ column : str
145
+ Nombre de la columna
146
+ Name of the column
147
+ """
94
148
  if column:
95
149
  return self.data[column].mode()[0]
96
150
  return self.data[self._numeric_cols].mode().iloc[0]
97
151
 
98
152
  def variance(self, column: Optional[str] = None) -> Union[float, pd.Series]:
99
- """Varianza"""
153
+ """
154
+ Varianza / Variance
155
+
156
+ Parametros / Parameters:
157
+ ------------------------
158
+ column : str
159
+ Nombre de la columna
160
+ Name of the column
161
+ """
100
162
  if column:
101
163
  return self.data[column].var()
102
164
  return self.data[self._numeric_cols].var()
103
165
 
104
166
  def std(self, column: Optional[str] = None) -> Union[float, pd.Series]:
105
- """Desviación estándar"""
167
+ """
168
+ Desviación estándar / Standard deviation
169
+
170
+ Parametros / Parameters:
171
+ ------------------------
172
+ column : str
173
+ Nombre de la columna
174
+ Name of the column
175
+
176
+ """
106
177
  if column:
107
178
  return self.data[column].std()
108
179
  return self.data[self._numeric_cols].std()
109
180
 
110
181
  def skewness(self, column: Optional[str] = None) -> Union[float, pd.Series]:
111
- """Asimetría"""
182
+ """
183
+ Asimetría / Asymmetry
184
+
185
+ Parametros / Parameters:
186
+ ------------------------
187
+ column : str
188
+ Nombre de la columna
189
+ Name of the column
190
+ """
112
191
  if column:
113
192
  return self.data[column].skew()
114
193
  return self.data[self._numeric_cols].skew()
115
194
 
116
195
  def kurtosis(self, column: Optional[str] = None) -> Union[float, pd.Series]:
117
- """Curtosis"""
196
+ """
197
+ Curtosis / Kurtosis
198
+
199
+ Parametros / Parameters:
200
+ ------------------------
201
+ column : str
202
+ Nombre de la columna
203
+ Name of the column
204
+ """
118
205
  if column:
119
206
  return self.data[column].kurtosis()
120
207
  return self.data[self._numeric_cols].kurtosis()
121
208
 
122
209
  def quantile(self, q: Union[float, List[float]], column: Optional[str] = None):
123
- """Cuantiles/Percentiles"""
210
+ """
211
+ Cuantiles - Percentiles / Quantiles - Percentiles
212
+
213
+ Parametros / Parameters:
214
+ ------------------------
215
+ q : float / List[float]
216
+ Cuantiles a calcular
217
+ Quantiles to calculate
218
+ column : str
219
+ Nombre de la columna
220
+ Name of the column
221
+ """
124
222
  if column:
125
223
  return self.data[column].quantile(q)
126
224
  return self.data[self._numeric_cols].quantile(q)
@@ -128,16 +226,19 @@ class DescriptiveStats:
128
226
  def outliers(self, column: str, method: Literal['iqr', 'zscore'] = 'iqr',
129
227
  threshold: float = 1.5) -> pd.Series:
130
228
  """
131
- Detectar outliers en una columna
229
+ Detectar outliers en una columna / Detecting outliers in a column
230
+
132
231
 
133
- Parameters:
134
- -----------
232
+ Parametros / Parameters:
233
+ ------------------------
135
234
  column : str
136
235
  Nombre de la columna
236
+ Name of the column
137
237
  method : str
138
238
  'iqr' o 'zscore'
139
239
  threshold : float
140
240
  1.5 para IQR, 3 para zscore típicamente
241
+ 1.5 for IQR, 3 for zscore typically
141
242
  """
142
243
  col_data = self.data[column]
143
244
 
@@ -157,22 +258,31 @@ class DescriptiveStats:
157
258
  # ============= MÉTODOS MULTIVARIADOS =============
158
259
 
159
260
  def correlation(self, method: Literal['pearson', 'spearman', 'kendall'] = 'pearson',
160
- columns: Optional[List[str]] = None) -> pd.DataFrame:
261
+ columns: Optional[List[str]] = None) -> pd.DataFrame:
161
262
  """
162
- Matriz de correlación
263
+ Matriz de correlación / Correlation matrix
163
264
 
164
- Parameters:
165
- -----------
265
+ Parametros / Parameters:
266
+ ------------------------
166
267
  method : str
167
268
  'pearson', 'spearman' o 'kendall'
168
269
  columns : list, optional
169
270
  Lista de columnas a incluir
271
+ List of columns to include
170
272
  """
171
273
  data_subset = self.data[columns] if columns else self.data[self._numeric_cols]
172
274
  return data_subset.corr(method=method)
173
275
 
174
276
  def covariance(self, columns: Optional[List[str]] = None) -> pd.DataFrame:
175
- """Matriz de covarianza"""
277
+ """
278
+ Matriz de covarianza
279
+
280
+ Parametros / Parameters:
281
+ ------------------------
282
+ columns: list, optional
283
+ Lista de columnas a incluir
284
+ List of columns to include
285
+ """
176
286
  data_subset = self.data[columns] if columns else self.data[self._numeric_cols]
177
287
  return data_subset.cov()
178
288
 
@@ -182,14 +292,16 @@ class DescriptiveStats:
182
292
  show_plot: bool = False,
183
293
  plot_backend: str = 'seaborn') -> 'DescriptiveSummary':
184
294
  """
185
- Resumen completo de estadísticas descriptivas
295
+ Resumen completo de estadísticas descriptivas / Complete descriptive statistics summary
186
296
 
187
- Parameters:
188
- -----------
297
+ Parametros / Parameters:
298
+ ------------------------
189
299
  columns : list, optional
190
300
  Columnas específicas a resumir
301
+ Specific columns to summarize
191
302
  show_plot : bool
192
303
  Si mostrar gráficos
304
+ If to show graphics
193
305
  plot_backend : str
194
306
  'seaborn', 'plotly' o 'matplotlib'
195
307
  """
@@ -227,8 +339,28 @@ class DescriptiveStats:
227
339
  plot_backend: str = 'seaborn',
228
340
  handle_missing: Literal['drop', 'error', 'warn'] = 'drop') -> tuple:
229
341
  """
230
- Regresión lineal simple o múltiple con opción de mostrar gráfico.
231
- Siempre devuelve un tuple: (LinearRegressionResult, figura o None)
342
+ Regresión lineal simple o múltiple con opción de mostrar gráfico / Simple or multiple \
343
+ linear regression with option to show graph
344
+
345
+ Parametros / Parameters:
346
+ ------------------------
347
+ X: str, list, optional
348
+ Nombre de la variable independiente
349
+
350
+ y: str
351
+ Nombre de la variable dependiente
352
+
353
+ engine: str
354
+ Motor de la regresion
355
+
356
+ fit_intercept: bool
357
+ Intercepto de la regresion
358
+
359
+ show_plot: bool
360
+ Visualizar la regresion (recomendable, solo [X,y])
361
+
362
+ handle_missing:
363
+ 'drop', 'error' o 'warn'
232
364
  """
233
365
  if isinstance(X, str):
234
366
  X = [X]
@@ -258,25 +390,28 @@ class DescriptiveStats:
258
390
  result.fit()
259
391
  result.show_plot = show_plot
260
392
  result.plot_backend = plot_backend
261
-
262
- figura = None
263
- # Graficar si es regresión simple
264
- if show_plot and len(X) == 1 and plot_backend.lower() == 'seaborn':
265
- import matplotlib.pyplot as plt
266
- g = sns.lmplot(x=X[0], y=y, data=regression_data, ci=None)
267
- g.figure.suptitle(f"Regresión lineal: {y} ~ {X[0]}", y=1.02)
268
- plt.tight_layout()
269
- figura = g.figure
270
-
271
- return result, figura
393
+ return result
272
394
 
273
395
 
274
396
 
275
- def help(self):
397
+ def help(self, lang="es-Es"):
276
398
  """
277
399
  Muestra ayuda completa de la clase DescriptiveStats
400
+
401
+ Parametros / Parameters:
402
+ ------------------------
403
+ lang: str
404
+ Idioma Usuario: Codigo de Idioma (es-Es) o "Español"
405
+ User Language: Languaje Code (en-Us) or "English"
278
406
  """
279
- help_text = """
407
+ if lang in ["en-US", "English", "english"]:
408
+ lang = "en-US"
409
+ else:
410
+ lang = ""
411
+
412
+ match lang:
413
+ case "es-ES":
414
+ help_text = """
280
415
  ╔════════════════════════════════════════════════════════════════════════════╗
281
416
  ║ 📊 CLASE DescriptiveStats - AYUDA COMPLETA ║
282
417
  ╚════════════════════════════════════════════════════════════════════════════╝
@@ -364,121 +499,329 @@ class DescriptiveStats:
364
499
 
365
500
  💡 EJEMPLOS DE USO:
366
501
 
367
- ┌─ Ejemplo 1: Inicialización ─────────────────────────────────────────────┐
368
- │ import pandas as pd
369
- │ from descriptive import DescriptiveStats │
370
-
371
- │ # Con DataFrame
372
- │ df = pd.read_csv('datos.csv') │
373
- │ stats = DescriptiveStats(df) │
374
-
375
- │ # Con array numpy
376
- │ import numpy as np
377
- │ datos = np.random.normal(0, 1, 1000) │
378
- │ stats = DescriptiveStats(datos) │
379
- └──────────────────────────────────────────────────────────────────────────┘
380
-
381
- ┌─ Ejemplo 2: Análisis Univariado ────────────────────────────────────────┐
382
- │ # Estadísticas de una columna │
383
- │ media = stats.mean('edad') │
384
- │ mediana = stats.median('edad') │
385
- │ desv_est = stats.std('edad') │
386
-
387
- │ # Cuartiles
388
- │ q25 = stats.quantile(0.25, 'edad') │
389
- │ q75 = stats.quantile(0.75, 'edad') │
390
-
391
- │ # Detectar outliers
392
- │ outliers_mask = stats.outliers('edad', method='iqr', threshold=1.5)
393
- │ print(f"Outliers detectados: {outliers_mask.sum()}") │
394
- └──────────────────────────────────────────────────────────────────────────┘
395
-
396
- ┌─ Ejemplo 3: Resumen Completo ───────────────────────────────────────────┐
397
- │ # Resumen de todas las variables numéricas │
398
- │ resumen = stats.summary() │
399
- │ print(resumen)
400
-
401
- │ # Resumen de columnas específicas con visualización │
402
- │ resumen = stats.summary( │
403
- │ columns=['edad', 'salario', 'experiencia'], │
404
- │ show_plot=True, │
405
- │ plot_backend='seaborn' │
406
- │ )
407
- └──────────────────────────────────────────────────────────────────────────┘
408
-
409
- ┌─ Ejemplo 4: Análisis Multivariado ──────────────────────────────────────┐
410
- │ # Matriz de correlación
411
- │ corr_pearson = stats.correlation(method='pearson') │
412
- │ corr_spearman = stats.correlation(method='spearman') │
413
-
414
- │ # Matriz de covarianza
415
- │ cov_matrix = stats.covariance() │
416
-
417
- │ # Correlación entre variables específicas │
418
- │ corr_subset = stats.correlation( │
419
- │ method='pearson', │
420
- │ columns=['edad', 'salario', 'experiencia'] │
421
- │ )
422
- └──────────────────────────────────────────────────────────────────────────┘
423
-
424
- ┌─ Ejemplo 5: Regresión Lineal Simple ────────────────────────────────────┐
425
- │ # Regresión simple: salario ~ experiencia │
426
- │ modelo = stats.linear_regression( │
427
- │ y='salario', │
428
- │ X='experiencia', │
429
- │ engine='statsmodels', │
430
- │ show_plot=True │
431
- │ )
432
-
433
- │ # Ver resultados
434
- │ print(modelo.summary())
435
-
436
- │ # Acceder a coeficientes
437
- │ print(f"Intercepto: {modelo.intercept_}") │
438
- │ print(f"Pendiente: {modelo.coef_[0]}") │
439
- │ print(f"R²: {modelo.r_squared}") │
440
- └──────────────────────────────────────────────────────────────────────────┘
441
-
442
- ┌─ Ejemplo 6: Regresión Lineal Múltiple ──────────────────────────────────┐
443
- │ # Regresión múltiple: salario ~ experiencia + edad + educacion │
444
- │ modelo = stats.linear_regression( │
445
- │ y='salario', │
446
- │ X=['experiencia', 'edad', 'educacion'], │
447
- │ engine='statsmodels', │
448
- │ fit_intercept=True, │
449
- │ handle_missing='drop' │
450
- │ )
451
-
452
- │ print(modelo.summary())
453
-
454
- │ # Hacer predicciones
455
- │ import numpy as np
456
- │ X_nuevo = np.array([[5, 30, 16], [10, 35, 18]]) # experiencia, edad
457
- │ predicciones = modelo.predict(X_nuevo) │
458
- └──────────────────────────────────────────────────────────────────────────┘
502
+ ┌─ Ejemplo 1: Inicialización ─────────────────────────────────────────────┐
503
+ │ import pandas as pd
504
+ │ from descriptive import DescriptiveStats │
505
+
506
+ │ # Con DataFrame
507
+ │ df = pd.read_csv('datos.csv') │
508
+ │ stats = DescriptiveStats(df) │
509
+
510
+ │ # Con array numpy
511
+ │ import numpy as np
512
+ │ datos = np.random.normal(0, 1, 1000) │
513
+ │ stats = DescriptiveStats(datos) │
514
+ └─────────────────────────────────────────────────────────────────────────┘
515
+
516
+ ┌─ Ejemplo 2: Análisis Univariado ────────────────────────────────────────┐
517
+ │ # Estadísticas de una columna │
518
+ │ media = stats.mean('edad') │
519
+ │ mediana = stats.median('edad') │
520
+ │ desv_est = stats.std('edad') │
521
+
522
+ │ # Cuartiles
523
+ │ q25 = stats.quantile(0.25, 'edad') │
524
+ │ q75 = stats.quantile(0.75, 'edad') │
525
+
526
+ │ # Detectar outliers
527
+ │ outliers_mask = stats.outliers('edad', method='iqr', threshold=1.5)
528
+ │ print(f"Outliers detectados: {outliers_mask.sum()}") │
529
+ └─────────────────────────────────────────────────────────────────────────┘
530
+
531
+ ┌─ Ejemplo 3: Resumen Completo ───────────────────────────────────────────┐
532
+ │ # Resumen de todas las variables numéricas │
533
+ │ resumen = stats.summary() │
534
+ │ print(resumen)
535
+
536
+ │ # Resumen de columnas específicas con visualización │
537
+ │ resumen = stats.summary( │
538
+ │ columns=['edad', 'salario', 'experiencia'], │
539
+ │ show_plot=True, │
540
+ │ plot_backend='seaborn' │
541
+ │ )
542
+ └─────────────────────────────────────────────────────────────────────────┘
543
+
544
+ ┌─ Ejemplo 4: Análisis Multivariado ──────────────────────────────────────┐
545
+ │ # Matriz de correlación
546
+ │ corr_pearson = stats.correlation(method='pearson') │
547
+ │ corr_spearman = stats.correlation(method='spearman') │
548
+
549
+ │ # Matriz de covarianza
550
+ │ cov_matrix = stats.covariance() │
551
+
552
+ │ # Correlación entre variables específicas │
553
+ │ corr_subset = stats.correlation( │
554
+ │ method='pearson', │
555
+ │ columns=['edad', 'salario', 'experiencia'] │
556
+ │ )
557
+ └─────────────────────────────────────────────────────────────────────────┘
558
+
559
+ ┌─ Ejemplo 5: Regresión Lineal Simple ────────────────────────────────────┐
560
+ │ # Regresión simple: salario ~ experiencia │
561
+ │ modelo = stats.linear_regression( │
562
+ │ y='salario', │
563
+ │ X='experiencia', │
564
+ │ engine='statsmodels', │
565
+ │ show_plot=True │
566
+ │ )
567
+
568
+ │ # Ver resultados
569
+ │ print(modelo.summary())
570
+
571
+ │ # Acceder a coeficientes
572
+ │ print(f"Intercepto: {modelo.intercept_}") │
573
+ │ print(f"Pendiente: {modelo.coef_[0]}") │
574
+ │ print(f"R²: {modelo.r_squared}") │
575
+ └─────────────────────────────────────────────────────────────────────────┘
576
+
577
+ ┌─ Ejemplo 6: Regresión Lineal Múltiple ──────────────────────────────────┐
578
+ │ # Regresión múltiple: salario ~ experiencia + edad + educacion │
579
+ │ modelo = stats.linear_regression( │
580
+ │ y='salario', │
581
+ │ X=['experiencia', 'edad', 'educacion'], │
582
+ │ engine='statsmodels', │
583
+ │ fit_intercept=True, │
584
+ │ handle_missing='drop' │
585
+ │ )
586
+
587
+ │ print(modelo.summary())
588
+
589
+ │ # Hacer predicciones
590
+ │ import numpy as np
591
+ │ X_nuevo = np.array([[5, 30, 16], [10, 35, 18]]) # experiencia, edad
592
+ │ predicciones = modelo.predict(X_nuevo) │
593
+ └─────────────────────────────────────────────────────────────────────────┘
594
+
595
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
596
+
597
+ 🎯 CARACTERÍSTICAS CLAVE:
598
+
599
+ ✓ Análisis univariado completo
600
+ ✓ Análisis multivariado (correlación, covarianza)
601
+ ✓ Detección de outliers con múltiples métodos
602
+ ✓ Regresión lineal con statsmodels o scikit-learn
603
+ ✓ Manejo automático de valores faltantes
604
+ ✓ Soporte para pandas DataFrame y numpy arrays
605
+ ✓ Salidas formateadas profesionales
606
+ ✓ Visualizaciones opcionales
607
+
608
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
609
+
610
+ 📚 DOCUMENTACIÓN ADICIONAL:
611
+ Para más información sobre métodos específicos, use:
612
+ help(DescriptiveStats.nombre_metodo)
613
+
614
+ ╚════════════════════════════════════════════════════════════════════════════╝
615
+ """
616
+ case "en-US":
617
+ # --- Falta por traducir
618
+ help_text = """
619
+ ╔════════════════════════════════════════════════════════════════════════════╗
620
+ ║ 📊 DescriptiveStats CLASS - COMPLETE HELP ║
621
+ ╚════════════════════════════════════════════════════════════════════════════╝
622
+
623
+ 📝 DESCRIPTION:
624
+ Class for univariate and multivariate descriptive statistical analysis.
625
+ Provides tools for exploratory data analysis, measures of
626
+ central tendency, dispersion, shape of distribution and linear regression.
627
+
628
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
629
+
630
+ 📋 MAIN METHODS:
631
+
632
+ ┌────────────────────────────────────────────────────────────────────────────┐
633
+ │ 1. 📊 UNIVARIATE STATISTICS │
634
+ └────────────────────────────────────────────────────────────────────────────┘
635
+
636
+ 🔹 Measures of Central Tendency:
637
+ • .mean(column=None) → Arithmetic mean
638
+ • .median(column=None) → Median (center value)
639
+ • .mode(column=None) → Mode (most frequent value)
640
+
641
+ 🔹 Dispersion Measurements:
642
+ • .std(column=None) → Standard deviation
643
+ • .variance(column=None) → Variance
644
+ • .quantile(q, column=None) → Quantiles/Percentiles
645
+
646
+ 🔹 Shape Measurements:
647
+ • .skewness(column=None) → Asymmetry (bias)
648
+ • .kurtosis(column=None) → Kurtosis (pointing)
649
+
650
+ 🔹 Outlier Detection:
651
+ • .outliers(column, method='iqr', threshold=1.5)
652
+ Methods: 'iqr' (interquartile range) or 'zscore' (z-score)
653
+
654
+ ┌────────────────────────────────────────────────────────────────────────────┐
655
+ │ 2. 🔗 MULTIVARIATE STATISTICS │
656
+ └────────────────────────────────────────────────────────────────────────────┘
657
+
658
+ 🔹 .correlation(method='pearson', columns=None)
659
+ Correlation matrix between variables
660
+ Methods: 'pearson', 'spearman', 'kendall'
661
+
662
+ 🔹 .covariance(columns=None)
663
+ Covariance matrix between variables
664
+
665
+ ┌────────────────────────────────────────────────────────────────────────────┐
666
+ │ 3. 📋 COMPLETE SUMMARY │
667
+ └────────────────────────────────────────────────────────────────────────────┘
668
+
669
+ 🔹 .summary(columns=None, show_plot=False, plot_backend='seaborn')
670
+ Complete descriptive summary with all statistics
671
+
672
+ Includes: count, mean, median, mode, dev. est., variance,
673
+ minimum, Q1, Q3, maximum, IQR, skewness, kurtosis
674
+
675
+ 🔹 .summary().to_dataframe(format)
676
+ Format:
677
+ - Wide
678
+ - Long
679
+ - Compact
680
+ 🔹 .summary().to_categorical_summary()
681
+ 🔹 .summary().to_styled_df()
682
+
683
+
684
+ ┌────────────────────────────────────────────────────────────────────────────┐
685
+ │ 4. 📈 LINEAR REGRESSION │
686
+ └────────────────────────────────────────────────────────────────────────────┘
687
+
688
+ 🔹 .linear_regression(y, X, engine='statsmodels',
689
+ fit_intercept=True, show_plot=False,
690
+ plot_backend='seaborn', handle_missing='drop')
691
+
692
+ Simple or multiple linear regression with full analysis
693
+
694
+ Parameters:
695
+ X : Independent variable(s) (str or list)
696
+ y: Dependent variable (str)
697
+ engine: 'statsmodels' or 'scikit-learn'
698
+ fit_intercept : Include intercept (bool)
699
+ show_plot : Show diagnostic plots (bool)
700
+ handle_missing : 'drop', 'error', 'warn'
701
+
702
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
703
+
704
+ 💡 EXAMPLES OF USE:
705
+
706
+ ┌─ Example 1: Initialization ─────────────────────────────────────────────┐
707
+ │ import pandas as pd │
708
+ │ from statslibx.descriptive import DescriptiveStats │
709
+ │ from statslibx.datasets import load_dataset │
710
+ │ │
711
+ │ # With DataFrame │
712
+ │ df = load_dataset('datos.csv') │
713
+ │ stats = DescriptiveStats(df) │
714
+ │ │
715
+ │ # With array numpy │
716
+ │ import numpy as np │
717
+ │ datos = np.random.normal(0, 1, 1000) │
718
+ │ stats = DescriptiveStats(datos) │
719
+ └─────────────────────────────────────────────────────────────────────────┘
720
+
721
+ ┌─ Example 2: Univariate Analysis ────────────────────────────────────────┐
722
+ │ # Statistics of a column │
723
+ │ mean = stats.mean('edad') │
724
+ │ median = stats.median('edad') │
725
+ │ desv_est = stats.std('edad') │
726
+ │ │
727
+ │ # Quartiles │
728
+ │ q25 = stats.quantile(0.25, 'edad') │
729
+ │ q75 = stats.quantile(0.75, 'edad') │
730
+ │ │
731
+ │ # To detect outsolves │
732
+ │ outliers_mask = stats.outliers('edad', method='iqr', threshold=1.5) │
733
+ │ print(f"Outliers detected: {outliers_mask.sum()}") │
734
+ └─────────────────────────────────────────────────────────────────────────┘
735
+
736
+ ┌─ Example 3: Complete Summary ───────────────────────────────────────────┐
737
+ │ # Summary of all numerical variables │
738
+ │ summary = stats.summary() │
739
+ │ print(summary) │
740
+ │ │
741
+ │ # Resumen de columnas específicas con visualización │
742
+ │ resumen = stats.summary( │
743
+ │ columns=['edad', 'salario', 'experiencia'], │
744
+ │ show_plot=True, │
745
+ │ plot_backend='seaborn' │
746
+ │ ) │
747
+ └─────────────────────────────────────────────────────────────────────────┘
748
+
749
+ ┌─ Ejemplo 4: Análisis Multivariado ──────────────────────────────────────┐
750
+ │ # Matriz de correlación │
751
+ │ corr_pearson = stats.correlation(method='pearson') │
752
+ │ corr_spearman = stats.correlation(method='spearman') │
753
+ │ │
754
+ │ # Matriz de covarianza │
755
+ │ cov_matrix = stats.covariance() │
756
+ │ │
757
+ │ # Correlación entre variables específicas │
758
+ │ corr_subset = stats.correlation( │
759
+ │ method='pearson', │
760
+ │ columns=['edad', 'salario', 'experiencia'] │
761
+ │ ) │
762
+ └──────────────────────────────────────────────────────────────────────────┘
763
+
764
+ ┌─ Ejemplo 5: Regresión Lineal Simple ────────────────────────────────────┐
765
+ │ # Regresión simple: salario ~ experiencia │
766
+ │ modelo = stats.linear_regression( │
767
+ │ y='salario', │
768
+ │ X='experiencia', │
769
+ │ engine='statsmodels', │
770
+ │ show_plot=True │
771
+ │ ) │
772
+ │ │
773
+ │ # Ver resultados │
774
+ │ print(modelo.summary()) │
775
+ │ │
776
+ │ # Acceder a coeficientes │
777
+ │ print(f"Intercepto: {modelo.intercept_}") │
778
+ │ print(f"Pendiente: {modelo.coef_[0]}") │
779
+ │ print(f"R²: {modelo.r_squared}") │
780
+ └──────────────────────────────────────────────────────────────────────────┘
781
+
782
+ ┌─ Ejemplo 6: Regresión Lineal Múltiple ──────────────────────────────────┐
783
+ │ # Regresión múltiple: salario ~ experiencia + edad + educacion │
784
+ │ modelo = stats.linear_regression( │
785
+ │ y='salario', │
786
+ │ X=['experiencia', 'edad', 'educacion'], │
787
+ │ engine='statsmodels', │
788
+ │ fit_intercept=True, │
789
+ │ handle_missing='drop' │
790
+ │ ) │
791
+ │ │
792
+ │ print(modelo.summary()) │
793
+ │ │
794
+ │ # Hacer predicciones │
795
+ │ import numpy as np │
796
+ │ X_nuevo = np.array([[5, 30, 16], [10, 35, 18]]) # experiencia, edad │
797
+ │ predicciones = modelo.predict(X_nuevo) │
798
+ └──────────────────────────────────────────────────────────────────────────┘
459
799
 
460
800
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
461
801
 
462
802
  🎯 CARACTERÍSTICAS CLAVE:
463
803
 
464
- ✓ Análisis univariado completo
465
- ✓ Análisis multivariado (correlación, covarianza)
466
- ✓ Detección de outliers con múltiples métodos
467
- ✓ Regresión lineal con statsmodels o scikit-learn
468
- ✓ Manejo automático de valores faltantes
469
- ✓ Soporte para pandas DataFrame y numpy arrays
470
- ✓ Salidas formateadas profesionales
471
- ✓ Visualizaciones opcionales
804
+ ✓ Análisis univariado completo
805
+ ✓ Análisis multivariado (correlación, covarianza)
806
+ ✓ Detección de outliers con múltiples métodos
807
+ ✓ Regresión lineal con statsmodels o scikit-learn
808
+ ✓ Manejo automático de valores faltantes
809
+ ✓ Soporte para pandas DataFrame y numpy arrays
810
+ ✓ Salidas formateadas profesionales
811
+ ✓ Visualizaciones opcionales
472
812
 
473
813
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
474
814
 
475
815
  📚 DOCUMENTACIÓN ADICIONAL:
476
- Para más información sobre métodos específicos, use:
477
- help(DescriptiveStats.nombre_metodo)
816
+ Para más información sobre métodos específicos, use:
817
+ help(DescriptiveStats.nombre_metodo)
478
818
 
479
819
  ╚════════════════════════════════════════════════════════════════════════════╝
480
820
  """
821
+
481
822
  print(help_text)
823
+
824
+
482
825
 
483
826
  class DescriptiveSummary:
484
827
  """Clase para formatear salida de estadística descriptiva"""
@@ -586,10 +929,10 @@ class DescriptiveSummary:
586
929
  Formato compacto: Variables en filas, estadísticas en columnas.
587
930
 
588
931
  Ejemplo:
589
- count mean median mode std variance ...
590
- Var1 150.0 5.8 5.8 5.0 0.8 0.68 ...
591
- Var2 150.0 3.1 3.0 3.0 0.4 0.19 ...
592
- Var3 150.0 3.8 4.0 1.0 1.8 3.11 ...
932
+ count mean median mode std variance ...
933
+ Var1 150.0 5.8 5.8 5.0 0.8 0.68 ...
934
+ Var2 150.0 3.1 3.0 3.0 0.4 0.19 ...
935
+ Var3 150.0 3.8 4.0 1.0 1.8 3.11 ...
593
936
  """
594
937
  df_data = []
595
938
 
@@ -618,7 +961,7 @@ class DescriptiveSummary:
618
961
  Formato largo: Una fila por cada combinación variable-estadística.
619
962
 
620
963
  Ejemplo:
621
- Variable Estadistica Valor
964
+ Variable Estadistica Valor
622
965
  0 Var1 count 150.00
623
966
  1 Var1 mean 5.84
624
967
  2 Var1 median 5.80