tisthemachinelearner: New Workflow with uv for R Integration of scikit-learn

R-bloggers 2025-12-06

[This article was first published on T. Moudiki's Webpage - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A quick reminder of the previous post: 👉 https://thierrymoudiki.github.io/blog/2025/02/17/python/r/tisthemllearner

tisthemachinelearner is an R (and Python) package that provides a lightweight interface (with approx. 2 classes, hence facilitating benchmarks e.g) to the popular Python machine learning library scikit-learn. The package allows R users to leverage the power of scikit-learn models directly from R, using both S3 and R6 object-oriented programming styles.

Since then, tisthemachinelearner has evolved with a cleaner and more predictable workflow for connecting R to Python scikit-learn, using both S3 and R6 interfaces. It’s now using a dedicated virtual environment manager called uv to handle Python dependencies seamlessly. Faster setup, less hassle!

uv is a lightweight and extremely fast tool to create and manage isolated Python environments. It simplifies the process of setting up the necessary Python environment for R packages that depend on Python libraries. Another advantage here, is that I know exactly what is installed in the environment, making it easier to debug potential issues.

1. Command line

# pip install uv # if necessaryuv venv venvsource venv/bin/activateuv pip install pip scikit-learn

This creates an isolated Python environment containing the correct dependencies for the R interface to use.


2. Use it from R

install.packages("devtools")devtools::install_github("Techtonique/tisthemachinelearner_r")library(tisthemachinelearner)# Load datadata(mtcars)head(mtcars)# Split features and targetX <- as.matrix(mtcars[, -1])  # all columns except mpgy <- mtcars[, 1]              # mpg column# Create train/test splitset.seed(42)train_idx <- sample(nrow(mtcars), size = floor(0.8 * nrow(mtcars)))X_train <- X[train_idx, ]X_test  <- X[-train_idx, ]y_train <- y[train_idx]y_test  <- y[-train_idx]# --- R6 interface ---model <- Regressor$new(model_name = "LinearRegression")model$fit(X_train, y_train)preds <- model$predict(X_test)print(preds)# --- S3 interface ---model <- regressor(X_train, y_train, model_name = "LinearRegression")preds <- predict(model, X_test)print(preds)

image-title-here

To leave a comment for the author, please follow the link and comment on their blog: T. Moudiki's Webpage - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Continue reading: tisthemachinelearner: New Workflow with uv for R Integration of scikit-learn