An open API service indexing awesome lists of open source software.

https://github.com/coatless-rpkg/ucimlrepo

An unofficial R port of the Python package to download data off of the UCI ML repository
https://github.com/coatless-rpkg/ucimlrepo

data data-science machine-learning rstats statistics uci-machine-learning uci-machine-learning-repository web-api

Last synced: 6 months ago
JSON representation

An unofficial R port of the Python package to download data off of the UCI ML repository

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# ucimlrepo A hexagonal logo of the ucimlrepo R package that shows data being downloaded from a repository

[![R-CMD-check](https://github.com/coatless-rpkg/ucimlrepo/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/ucimlrepo/actions/workflows/R-CMD-check.yaml)

The goal of `ucimlrepo` is to download and import data sets directly into R
from the [UCI Machine Learning Repository](https://archive.ics.uci.edu/).

> [!IMPORTANT]
>
> This package is an unoffical port of the [Python `ucimlrepo` package](https://github.com/uci-ml-repo/ucimlrepo).

> [!NOTE]
>
> Want to have datasets alongside a help documentation entry?
>
> Check out the [`{ucidata}`](https://github.com/coatless-rpkg/ucidata) R package!
> The package provides a small selection of data sets from the
> UC Irvine Machine Learning Repository alongside of help entries.

## Installation

You can install the development version of ucimlrepo from [GitHub](https://github.com/) with:

``` r
# install.packages("remotes")
remotes::install_github("coatless-rpkg/ucimlrepo")
```

## Usage

To use `ucimlrepo`, load the package using:

```{r}
#| label: load-pkg
library(ucimlrepo)
```

With the package now loaded, we can download a dataset using the `fetch_ucirepo()` function
or use the `list_available_datasets()` function to view a list of available datasets.

### Download data

For example, to download the `iris` dataset, we can use:

```{r}
#| label: download dataset
# Fetch a dataset by name
iris_by_name <- fetch_ucirepo(name = "iris")
names(iris_by_name)
```

There are many levels to the data returned. For example, we can extract the
original data frame containing the `iris` dataset using:

```{r}
iris_uci <- iris_by_name$data$original
head(iris_uci)
```

Alternatively, we could retrieve two data frames, one for the features and one for the targets:

```{r}
iris_features <- iris_by_name$data$features
iris_targets <- iris_by_name$data$targets
```

We can then view the first few rows of each data frame:

```{r}
head(iris_features)
head(iris_targets)
```

Alternatively, you can also directly query by using an ID found by using
`list_available_datasets()` or by looking up the dataset on the UCI ML Repo website:

```{r}
#| label: download dataset by id
#| eval: false
# Fetch a dataset by id
iris_by_id <- fetch_ucirepo(id = 53)
```

### View list of data sets

We can also view a list of data sets available for download
using the `list_available_datasets()` function:

```{r}
#| label: list-packages
#| eval: false
# List available datasets
list_available_datasets()
```

> [!NOTE]
>
> Not all 600+ datasets on UCI ML Repo are available for download using the package.
> The current list of available datasets can be viewed [here](https://archive.ics.uci.edu/datasets?Python=true&skip=0&take=25&sort=desc&orderBy=NumHits).
>
> If you would like to see a specific dataset added, please submit a comment
> on an [issue ticket in the upstream repository](https://github.com/uci-ml-repo/ucimlrepo/issues/9).