This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generar_respuesta(prompt, max_length=200, num_beams=4): | |
| """Genera respuesta del modelo""" | |
| inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_length=max_length, | |
| min_length=20, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from sklearn.pipeline import Pipeline | |
| from sklearn.preprocessing import PolynomialFeatures | |
| from sklearn.linear_model import LinearRegression | |
| from sklearn.metrics import mean_squared_error | |
| from sklearn.model_selection import train_test_split | |
| # Configuración de estilo para publicaciones académicas | |
| plt.style.use('seaborn-v0_8-whitegrid') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import copy | |
| import time | |
| import signal | |
| import matplotlib.pyplot as plt | |
| from graphviz import Digraph | |
| from pandas import DataFrame | |
| from sklearn.metrics import r2_score, mean_absolute_error, mean_squared_error, log_loss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from collections import Counter | |
| import matplotlib.pyplot as plt | |
| from sklearn.decomposition import PCA | |
| class Word2VecSimple: | |
| """ | |
| Implementación simplificada de Word2Vec (Skip-gram) para fines educativos. | |
| """ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy import stats | |
| import matplotlib.pyplot as plt | |
| from typing import Tuple, Callable | |
| class PowerFunctionOneSampleT: | |
| """ | |
| Calcula y visualiza la función de poder para prueba t de una muestra. | |
| Conexión con Sesión 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def temporal_train_test_split(df, predictors, target, test_size=0.2): | |
| """ | |
| División temporal que respeta: | |
| 1. Orden cronológico (no leakage) | |
| 2. Integridad de series por país (no partir series arbitrariamente) | |
| 3. Balance de países entre train/test | |
| """ | |
| # Ordenar por año | |
| df_sorted = df.sort_values('Year').reset_index(drop=True) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import miceforest as mf | |
| def impute_life_expectancy_data_robust(df): | |
| """ | |
| Pipeline de imputación diferenciada con manejo explícito de tipos de datos. | |
| Soluciona el error de columnas 'object' en miceforest mediante: | |
| 1. Conversión de categóricas a tipo 'category' | |
| 2. Exclusión de identificadores del kernel MICE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| cpython = pd.read_csv("https://github.com/robintux/Datasets4StackOverFlowQuestions/raw/refs/heads/master/cpython_commit_history_pre.csv") | |
| # Creacion de columnas para obtener informacion temporal | |
| cpython["date"] = pd.to_datetime(cpython["date"], utc=True) | |
| cpython["year"] = cpython["date"].dt.year | |
| cpython["month"] = cpython["date"].dt.to_period("M") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Modulos y datos | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| import numpy as np | |
| uber = pd.read_csv("https://raw.githubusercontent.com/robintux/Datasets4StackOverFlowQuestions/refs/heads/master/Datos_Uber_2024.csv") | |
| # Preprocesamiento | |
| uber['Date'] = pd.to_datetime(uber['Date'], format='%Y-%m-%d') | |
| uber['Year'] = uber['Date'].dt.year |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def classical_decomposition(Y, m, model='additive'): | |
| """ | |
| Y: array de valores de la serie temporal | |
| m: periodicidad estacional (ej: 12 para mensual) | |
| model: 'additive' o 'multiplicative' | |
| """ | |
| n = len(Y) | |
| T = np.zeros(n) * np.nan # Tendencia | |
| # PASO 1: Estimación de Tendencia-Ciclo via MA centrada |
NewerOlder