{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "Hin-2xH6bNex" }, "source": [ "# MAE\n", "[](https://rehline-python.readthedocs.io/en/latest/)\n", "\n", "The regularized MAE regression solves the following optimization problem:\n", "\n", "$$\n", "\\min_{\\mathbf{\\beta} \\in \\mathbb{R}^d}\n", "C \\sum_{i=1}^n |y_i - \\mathbf{x}_i^\\top \\mathbf{\\beta}|\n", "+ \\frac{1}{2}\\|\\mathbf{\\beta}\\|_2^2,\n", "$$\n", "\n", "where $\\mathbf{x}_i \\in \\mathbb{R}^d$ is a feature vector, and $y_i \\in \\mathbb{R}$ is the response variable." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> **Note.** Since the absolute loss is a plq function, we can optimize it using `rehline.plq_Ridge_Regressor`. \n", "> Moreover, this wrapper adapts the `plqERM_Ridge` into a regressor, compatible with the scikit-learn API." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "D62H7LVT-hpG" }, "outputs": [], "source": [ "## install rehline\n", "%pip install rehline -q" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "id": "tHPsW2Eq6lN9" }, "outputs": [], "source": [ "import warnings\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sns\n", "from sklearn.datasets import make_regression\n", "from sklearn.preprocessing import StandardScaler" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "M8dZ_mRK9YDK" }, "outputs": [], "source": [ "# Simulate data\n", "np.random.seed(42)\n", "scaler_mae = StandardScaler()\n", "\n", "n, d = 10000, 5\n", "X, y = make_regression(n_samples=n, n_features=d, noise=1.0)\n", "X = scaler_mae.fit_transform(X)\n", "y = y / y.std()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 80 }, "id": "9JP5VwfV9aCY", "outputId": "be0e31b9-a9f4-42db-e409-7794fc50bbe9" }, "outputs": [ { "data": { "text/html": [ "
plq_Ridge_Regressor(loss={'name': 'mae'})In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. plq_Ridge_Regressor(loss={'name': 'mae'})Pipeline(steps=[('scaler', StandardScaler()),\n",
" ('reg', plq_Ridge_Regressor(loss={'name': 'mae'}))])In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. Pipeline(steps=[('scaler', StandardScaler()),\n",
" ('reg', plq_Ridge_Regressor(loss={'name': 'mae'}))])StandardScaler()
plq_Ridge_Regressor(loss={'name': 'mae'})