Home > OS >  Unable to access the cars data set in caret
Unable to access the cars data set in caret

Time:04-26

I'm working through the book [Applied Predictive Modeling] http://appliedpredictivemodeling.com

Starting on page 56, the instructions say,

To illustrate the code, we will take a subset of the cars data set in the caret package. For 2005, Kelly Blue Book resale data for 804 GM cars were collected (Kuiper 2008). The object of the model was to predict the price of the car based on known characteristics. This demonstration will focus on the price, mileage, and car type (e.g., sedan) for a subset of vehicles:

However, I'm not able to access the data set. It appears there is no 2005 cars data set in the caret package. Here is the code I'm using:

library(AppliedPredictiveModeling)
library(caret)
cars

This returns a cars data set from the R datasets package, not the Applied Predictive Modeling data set of cars from 2005.

Next I tried:

AppliedPredictiveModeling::cars

This returns an error: "Error: 'cars' is not an exported object from 'namespace:AppliedPredictiveModeling'"

In a similar manner, the code:

caret::cars

returns the error: "Error: 'cars' is not an exported object from 'namespace:caret'"

The Github solutions page by the authors does not have anything for this chapter: Github solutions for Applied Predictive Modeling

The same dataset appears to be in the modeldata package, but this appears not to work, either:

library(modeldata)
modeldata::car_prices

returns an error: "Error: 'car_prices' is not an exported object from 'namespace:modeldata'"

In a similar manner:

car_prices

return an error: object 'car_prices' not found

I'm using the following, with the following up to date (MacOS, R, RStudio, packages):

R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: aarch64-apple-darwin20 (64-bit)

How is the data set of 2005 Kelly Blue Book resale data for 804 GM cars accessed?

CodePudding user response:

There is a default cars dataset. You need to over-shadow it. The data function should load the dataset into the workspace:

 data(cars, package='caret')
str(cars)
#-----------------
'data.frame':   804 obs. of  18 variables:
 $ Price      : num  22661 21725 29143 30732 33359 ...
 $ Mileage    : int  20105 13457 31655 22479 17590 23635 17381 27558 25049 17319 ...
 $ Cylinder   : int  6 6 4 4 4 4 4 4 4 4 ...
 $ Doors      : int  4 2 2 2 2 2 2 2 2 4 ...
 $ Cruise     : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Sound      : int  0 1 1 0 1 0 1 0 0 0 ...
 $ Leather    : int  0 0 1 0 1 0 1 1 0 1 ...
 $ Buick      : int  1 0 0 0 0 0 0 0 0 0 ...
 $ Cadillac   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Chevy      : int  0 1 0 0 0 0 0 0 0 0 ...
 $ Pontiac    : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Saab       : int  0 0 1 1 1 1 1 1 1 1 ...
 $ Saturn     : int  0 0 0 0 0 0 0 0 0 0 ...
 $ convertible: int  0 0 1 1 1 1 1 1 1 0 ...
 $ coupe      : int  0 1 0 0 0 0 0 0 0 0 ...
 $ hatchback  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ sedan      : int  1 0 0 0 0 0 0 0 0 1 ...
 $ wagon      : int  0 0 0 0 0 0 0 0 0 0 ...
  • Related