{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "UuhJeQeAakNd" }, "source": [ "# Tutorial: Basic ridge and LASSO models\n", "\n", "This lab dives deeper into ridge regression and LASSO and how to implement these tehcniques in R.\n", "\n", "## Goals:\n", "* Learn to use the `glmnet` function.\n", "* Understand that hyperparameter selection should also be validated.\n", "\n", "This lab draws from the practice sets at the end of Chapter 6 in James, G., Witten, D., Hastie, T., & Tibshirani, R. (2013). \"An introduction to statistical learning: with applications in r.\" " ] }, { "cell_type": "markdown", "metadata": { "id": "iGlxmzMHakNx" }, "source": [ "---\n", "# Ridge Regression\n", "\n", "For this tutorial we will load the [Hitters (baseball) dataset](https://vincentarelbundock.github.io/Rdatasets/doc/ISLR/Hitters.html) included in ISLR.\n", "\n", "Ridge regression is made easy with the [`glmnet` package](https://cran.r-project.org/web/packages/glmnet/glmnet.pdf), so we'll install that to start." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 85 }, "id": "FwHAN34kC4TA", "outputId": "3800ec7a-6b22-4237-c007-9d30087afb55" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Installing package into ‘/usr/local/lib/R/site-library’\n", "(as ‘lib’ is unspecified)\n", "\n" ] }, { "data": { "text/html": [ "\n", "