Skip to content

Commit

Permalink
add example with parsnip interface to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Jul 30, 2024
1 parent 709b788 commit a5c459c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 11 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ parsnip_models <- get_from_env("models") %>%
```

```{r}
x <- matrix(rnorm(3e7), ncol = 3)
x <- matrix(rnorm(3e7), ncol = 3, dimnames = list(NULL, paste0("X", 1:3)))
y <- rnorm(1e7)
dat <- cbind(as.data.frame(x), y)
Expand All @@ -68,6 +68,16 @@ system.time({
})
```

To use rinfa with tidymodels, set the modeling engine to `"linfa"`:

```{r}
# using the formula interface:
linfa_fit <- fit(linear_reg(engine = "linfa"), y ~ ., dat)
# using the (more performant, in this case) XY interface:
linfa_fit_xy <- fit_xy(linear_reg(engine = "linfa"), x = x, y = y)
```

## Available implementations

The rinfa package provides an additional engine `"linfa"` for the models in the following table:
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ devtools::install_github("simonpcouch/rinfa")
## Example

``` r
x <- matrix(rnorm(3e7), ncol = 3)
x <- matrix(rnorm(3e7), ncol = 3, dimnames = list(NULL, paste0("X", 1:3)))
y <- rnorm(1e7)

dat <- cbind(as.data.frame(x), y)
Expand All @@ -37,22 +37,32 @@ system.time(
lm(y ~ ., dat)
)
#> user system elapsed
#> 1.093 0.244 1.372
#> 1.344 0.286 1.663

system.time(
# lm()'s speedy friend
lm.fit(x, y)
)
#> user system elapsed
#> 0.386 0.032 0.424
#> 0.469 0.033 0.503

library(rinfa)

system.time({
.linfa_linear_reg(x, y)
})
#> user system elapsed
#> 0.161 0.076 0.239
#> 0.218 0.086 0.307
```

To use rinfa with tidymodels, set the modeling engine to `"linfa"`:

``` r
# using the formula interface:
linfa_fit <- fit(linear_reg(engine = "linfa"), y ~ ., dat)

# using the (more performant, in this case) XY interface:
linfa_fit_xy <- fit_xy(linear_reg(engine = "linfa"), x = x, y = y)
```

## Available implementations
Expand Down

0 comments on commit a5c459c

Please sign in to comment.