---
title: "Quickstart: from data to prediction in ~10 lines"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{01. Quickstart: from data to prediction in ~10 lines}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
# Vignette code is executed locally (NOT_CRAN=true) but not on CRAN, where
# the CPU fallback would multi-thread and trip the "CPU time > elapsed" NOTE.
knitr::opts_chunk$set(eval = identical(Sys.getenv("NOT_CRAN"), "true"))
```

The shortest possible path with ggmlR: take a built-in dataset, train a neural
network, and predict — using only the core Keras-like API, no tidymodels or
mlr3. (For those ecosystems see the *tidymodels* and *mlr3* vignettes.)

```{r}
library(ggmlR)

x <- scale(as.matrix(iris[, 1:4]))            # 4 numeric features
y <- model.matrix(~ Species - 1, iris)        # one-hot, 3 classes

model <- ggml_model_sequential() |>
  ggml_layer_dense(16L, activation = "relu", input_shape = 4L) |>
  ggml_layer_dense(3L,  activation = "softmax") |>
  ggml_compile(optimizer = "adam", loss = "categorical_crossentropy")

model <- ggml_fit(model, x, y, epochs = 100L, verbose = 0L)

pred  <- ggml_predict(model, x)               # [150 x 3] class probabilities
acc   <- mean(max.col(pred) == as.integer(iris$Species))
cat(sprintf("accuracy: %.3f\n", acc))
```

That's it — load data, stack layers, `ggml_compile()`, `ggml_fit()`,
`ggml_predict()`. ggmlR runs on the GPU via Vulkan automatically when available
and falls back to the CPU otherwise; call `ggml_model_backend(model)` to see
which backend was actually used.

## Next steps

- **Keras-like API** vignette — full sequential & functional models, layers,
  callbacks, save/load.
- **Autograd engine** vignette — PyTorch-style dynamic graphs (`ag_*`).
- **tidymodels** / **mlr3** vignettes — use ggmlR as an engine/learner inside
  those ecosystems.
- **GPU / Vulkan** vignette — device selection and performance.
