Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Summary DSCI Tutorial 9 - tutorial_regression2_solution (2022)

Puntuación
5.0
(1)
Vendido
1
Páginas
11
Subido en
11-04-2022
Escrito en
2021/2022

Solutions to tutorial 9 Regression 2

Institución
Grado

Vista previa del contenido

Tutorial 9: Regression Continued
Regression learning objectives:

Recognize situations where a simple regression analysis would be appropriate for making predictions.
Explain the k-nearest neighbour (k-nn) regression algorithm and describe how it differs from k-nn classification.
Interpret the output of a k-nn regression.
In a dataset with two variables, perform k-nearest neighbour regression in R using tidymodels to predict the values for a test dataset.
Using R, execute cross-validation in R to choose the number of neighbours.
Using R, evaluate k-nn regression prediction accuracy using a test data set and an appropriate metric (e.g., root means square prediction error).
In a dataset with > 2 variables, perform k-nn regression in R using tidymodels to predict the values for a test dataset.
In the context of k-nn regression, compare and contrast goodness of fit and prediction properties (namely RMSE vs RMSPE).
Describe advantages and disadvantages of the k-nearest neighbour regression approach.
Perform ordinary least squares regression in R using tidymodels to predict the values for a test dataset.
Compare and contrast predictions obtained from k-nearest neighbour regression to those obtained using simple ordinary least squares regression
from the same dataset.
In R, overlay the ordinary least squares regression lines from geom_smooth on a single plot.


In [ ]:

### Run this cell before continuing.
library(tidyverse)
library(testthat)
library(digest)
library(repr)
library(tidymodels)
library(GGally)
library(ISLR)
options(repr.matrix.max.rows = 6)
source("tests.R")
source("cleanup.R")



Predicting credit card balance




Source: https://media.giphy.com/media/LCdPNT81vlv3y/giphy-downsized-large.gif (https://media.giphy.com/media/LCdPNT81vlv3y/giphy-downsized-
large.gif)

Here in this worksheet we will work with a simulated data set that contains information that we can use to create a model to predict customer credit card
balance. A bank might use such information to predict which customers might be the most profitable to lend to (customers who carry a balance, but do not
default, for example).

Specifically, we wish to build a model to predict credit card balance ( Balance column) based on income ( Income column) and credit rating ( Rating
column).


We access this data set by accessing it from an R data package that we loaded at the beginning of the worksheet, ISLR . Loading that package gives
access to a variety of data sets, including the Credit data set that we will be working with.


In [ ]:

Credit

, Question 1.1
{points: 1}

Select only the columns of data we are interested in using for our prediction (both the predictors and the response variable) and use the as_tibble
function to convert it to a tibble (it is currently a base R data frame). Name the modified data frame credit (using a lowercase c).

Note: We could alternatively just leave these variables in and use our recipe formula below to specify our predictors and response. But for this worksheet,
let's select the relevant columns first.


In [ ]:

### BEGIN SOLUTION
credit <- Credit %>%
select(Balance, Income, Rating) %>%
as_tibble()
### END SOLUTION
credit


In [ ]:

test_1.1()


Question 1.2
{points: 1}

Before we perform exploratory data analysis, we should create our training and testing data sets. First, split the credit data set. Use 60% of the data
and set the variables we want to predict as the strata argument. Assign your answer to an object called credit_split .

Assign your training data set to an object called credit_training and your testing data set to an object called credit_testing .


In [ ]:

set.seed(2000)
### BEGIN SOLUTION
credit_split <- initial_split(credit, prop = 0.6, strata = Balance)
credit_training <- training(credit_split)
credit_testing <- testing(credit_split)
### END SOLUTION


In [ ]:

test_1.2()


Question 1.3
{points: 1}

Using only the observations in the training data set, create a ggpairs scatterplot of all the columns we are interested in including in our model. Name
the plot object credit_eda .


In [ ]:

### BEGIN SOLUTION
options(repr.plot.height = 10, repr.plot.width = 15)
credit_eda <- credit_training %>%
ggpairs(mapping = aes(alpha = 0.4)) +
theme(text = element_text(size = 20))
### END SOLUTION
credit_eda


In [ ]:

test_1.3()

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
11 de abril de 2022
Número de páginas
11
Escrito en
2021/2022
Tipo
RESUMEN

Temas

$7.99
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF


Documento también disponible en un lote

Reseñas de compradores verificados

Se muestran los comentarios
2 año hace

5.0

1 reseñas

5
1
4
0
3
0
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
travissmith1 UBC
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
97
Miembro desde
4 año
Número de seguidores
61
Documentos
36
Última venta
5 meses hace

3.6

16 reseñas

5
6
4
6
3
0
2
0
1
4

Documentos populares

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes