{ "cells": [ { "cell_type": "markdown", "id": "c9545a3d", "metadata": {}, "source": [ "# Ejercicio " ] }, { "cell_type": "markdown", "id": "c2b0a03f", "metadata": {}, "source": [ "Empezamos cargando las librerias necesarias" ] }, { "cell_type": "code", "execution_count": null, "id": "9974177a", "metadata": {}, "outputs": [], "source": [ "\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "from sklearn.linear_model import LinearRegression, Lasso\n", "from sklearn import datasets\n", "from sklearn.datasets import make_regression\n", "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "markdown", "id": "20e5d459", "metadata": {}, "source": [ "Creamos un dataset y lo retocamos, estamos forzando un ejemplo concreto" ] }, { "cell_type": "code", "execution_count": null, "id": "b7c7cb88", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0 1 2 3 4 5 7 \\\n", "0 0.991136 1.630796 -1.900090 -0.111391 -1.232109 0.932722 2.798165 \n", "1 -0.325548 -0.538166 -0.261746 -0.220028 0.109686 0.252768 0.758303 \n", "2 1.937571 0.338847 1.876973 0.217793 0.086090 0.813308 2.439924 \n", "3 -0.960129 0.511255 0.853085 -1.216964 -1.547833 -0.213646 -0.640938 \n", "4 -1.352448 -0.613847 -1.060842 -0.222442 0.307362 0.087174 0.261521 \n", "\n", " 8 \n", "0 -0.616054 \n", "1 0.054843 \n", "2 0.043045 \n", "3 -0.773917 \n", "4 0.153681 \n" ] } ], "source": [ "X, y = make_regression(n_samples=100,n_informative=6, n_features=6, coef=False,noise=100.0, random_state=33, bias=10.5)\n", "\n", "df = pd.DataFrame(X)\n", "df[7] = df[5] * 3\n", "df[4] = df[4] + df[3]\n", "df[8] = df[4] / 2\n", "\n", "X = df.to_numpy()\n", "print(df.head())" ] }, { "cell_type": "markdown", "id": "972a8ea8", "metadata": {}, "source": [ "Divide el conjunto en _entrenamiento_ y _test_ :" ] }, { "cell_type": "markdown", "id": "d900b247", "metadata": {}, "source": [ "Crea una regresión Lasso. Visualiza el valor de los coeficientes" ] }, { "cell_type": "code", "execution_count": null, "id": "343c068a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "76e5831a", "metadata": {}, "source": [ "Crea una regresión Lineal. Visualiza el valor de los coeficientes" ] }, { "cell_type": "code", "execution_count": null, "id": "ae1238e4", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "b8b4b1ae", "metadata": {}, "source": [ "¿Qué puedes observar?" ] }, { "cell_type": "code", "execution_count": null, "id": "e2828041", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "42214e8b", "metadata": {}, "source": [ "[![License: CC BY 4.0](https://img.shields.io/badge/License-CC_BY_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/)
\n", "Isaac Lera and Gabriel Moya
\n", "Universitat de les Illes Balears
\n", "isaac.lera@uib.edu, gabriel.moya@uib.edu" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.10" } }, "nbformat": 4, "nbformat_minor": 5 }