---
title: "optbinningR Tutorial: Continuous Target (Python-style workflow)"
output: rmarkdown::html_document
---

This tutorial mirrors the official continuous tutorial flow (`LSTAT` / `MEDV` style) using native R.

```r
library(optbinningR)
```

## 1) Load data

```r
# MASS::Boston is the R counterpart commonly used in continuous-target examples.
data("Boston", package = "MASS")
x <- Boston$lstat
y <- Boston$medv
```

## 2) Instantiate and fit

```r
optb <- ContinuousOptimalBinning(name = "LSTAT", dtype = "numerical")
optb <- fit(
  optb,
  x = x,
  y = y,
  algorithm = "optimal",
  solver = "native",
  prebinning_method = "cart",
  max_n_prebins = 20,
  max_n_bins = 10,
  min_bin_size = 0.05,
  monotonic_trend = "auto"
)

optb$status
optb$splits
```

## 3) Build binning table

```r
binning_table <- binning_table(optb)
bt <- build(binning_table)
bt
```

## 4) Plot default style

```r
plot(optb, metric = "mean", style = "bin")
```

## 5) Plot with actual bin widths

```r
plot(optb, metric = "mean", style = "actual")
```

## 6) Plot with bin labels

```r
plot(optb, metric = "mean", style = "bin", show_bin_labels = TRUE)
```

## 7) Transform values

```r
x_mean <- transform(optb, x, metric = "event_rate")
x_bins <- transform(optb, x, metric = "bins")
head(data.frame(x = x, bin = x_bins, mean_proxy = x_mean))
```
