MulaiMulai sekarang secara gratis

Building a simple decision tree

The loans dataset contains 11,312 randomly-selected people who applied for and later received loans from Lending Club, a US-based peer-to-peer lending company.

You will use a decision tree to try to learn patterns in the outcome of these loans (either repaid or default) based on the requested loan amount and credit score at the time of application.

Then, see how the tree's predictions differ for an applicant with good credit versus one with bad credit.

The dataset loans has been loaded for you.

Latihan ini adalah bagian dari kursus

Supervised Learning in R: Classification

Lihat Kursus

Petunjuk latihan

  • Load the rpart package.
  • Fit a decision tree model with the function rpart().
    • Supply the R formula that specifies outcome as a function of loan_amount and credit_score as the first argument.
    • Leave the control argument alone for now. (You'll learn more about that later!)
  • Use predict() with the resulting loan model to predict the outcome for the good_credit applicant. Use the type argument to predict the "class" of the outcome.
  • Do the same for the bad_credit applicant.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Load the rpart package


# Build a lending model predicting loan outcome versus loan amount and credit score
loan_model <- rpart(___, data = ___, method = "___", control = rpart.control(cp = 0))

# Make a prediction for someone with good credit
predict(___, ___, type = "___")

# Make a prediction for someone with bad credit
Edit dan Jalankan Kode