Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/6907fa8a-e344-8008-8a25-8d456370c8d6
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: ¡Genial! === ¡Genial! Te voy a generar un notebook completo en Python que puedes abrir en Jupyter o Google Colab. Este notebook: * Carga el dataset Wine Quality desde UCI. * Divide los datos en entrenamiento y prueba. * Normaliza las características. * Entrena un MLPRegressor (red neuronal multicapa). * Entrena un RandomForestRegressor como segunda técnica de ML. * Evalúa ambos modelos con MSE y R². * Muestra una gráfica de caja-bigote comparando los errores. Aquí tienes el código listo para notebook: <syntaxhighlight lang="python"># Wine_Quality_Regresion.ipynb === ========================== === === 1️⃣ Librerías === === ========================== === import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.neural_network import MLPRegressor from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_squared_error, r2_score import matplotlib.pyplot as plt import seaborn as sns === ========================== === === 2️⃣ Cargar dataset === === ========================== === === URL del dataset Wine Quality (vino tinto) === url = "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv" df = pd.read_csv(url, sep=';') === Verificar datos === print("Primeras filas del dataset:") print(df.head()) print("\nInformación del dataset:") print(df.info()) print("\nEstadísticas descriptivas:") print(df.describe()) === ========================== === === 3️⃣ Separar features y target === === ========================== === X = df.drop("quality", axis=1) y = df["quality"] === ========================== === === 4️⃣ Dividir en entrenamiento y prueba === === ========================== === X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) === ========================== === === 5️⃣ Normalización / estandarización === === ========================== === scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) === ========================== === === 6️⃣ Entrenar MLPRegressor === === ========================== === mlp = MLPRegressor(hidden_layer_sizes=(50, 30), activation='relu', solver='adam', max_iter=1000, random_state=42) mlp.fit(X_train_scaled, y_train) === Predicciones === y_pred_mlp = mlp.predict(X_test_scaled) === Evaluación === mse_mlp = mean_squared_error(y_test, y_pred_mlp) r2_mlp = r2_score(y_test, y_pred_mlp) print("\n--- MLPRegressor ---") print(f"MSE: {mse_mlp:.4f}") print(f"R²: {r2_mlp:.4f}") === ========================== === === 7️⃣ Entrenar RandomForestRegressor === === ========================== === rf = RandomForestRegressor(n_estimators=100, random_state=42) rf.fit(X_train, y_train) === Predicciones === y_pred_rf = rf.predict(X_test) === Evaluación === mse_rf = mean_squared_error(y_test, y_pred_rf) r2_rf = r2_score(y_test, y_pred_rf) print("\n--- RandomForestRegressor ---") print(f"MSE: {mse_rf:.4f}") print(f"R²: {r2_rf:.4f}") === ========================== === === 8️⃣ Gráfica comparativa de errores === === ========================== === errors = pd.DataFrame({ "MLPRegressor": np.abs(y_test - y_pred_mlp), "RandomForest": np.abs(y_test - y_pred_rf) }) plt.figure(figsize=(8,6)) sns.boxplot(data=errors) plt.title("Comparación de errores absolutos entre modelos") plt.ylabel("Error absoluto") plt.show() </syntaxhighlight> ✅ Detalles importantes: * La columna quality es la variable continua que queremos predecir. * Para la red neuronal usamos MLPRegressor con 2 capas ocultas (50 y 30 neuronas). * Como segunda técnica elegí RandomForestRegressor porque funciona bien para regresión y es fácil de interpretar. * La gráfica boxplot compara el error absoluto de cada modelo sobre el conjunto de prueba. Si quieres, puedo hacer otra versión optimizando los hiperparámetros del MLP para que la red neuronal tenga mejor desempeño y luego actualizar la gráfica comparativa. ¿Quieres que haga eso?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)