Data Splitting and Preprocessing (rsample) in R: A Step-by-Step Guide

Data preprocessing is a crucial step in any machine learning workflow. It ensures that your data is clean, consistent, and ready for modeling. In this blog post, we’ll walk through the process of splitting and preprocessing data in R, using the rsample package for data splitting and saving the results for future use.


Here’s what we’ll cover in this blog:

  1. Introduction

    • Why data splitting and preprocessing are important.

  2. Step-by-Step Workflow

    • Setting a seed for reproducibility.

    • Loading the necessary libraries.

    • Splitting the dataset into training and testing sets.

    • Merging datasets for analysis.

    • Saving and loading datasets for future use.

  3. Example: Data Splitting and Preprocessing

    • A practical example using a sample dataset.

  4. Why This Workflow Matters

    • The importance of reproducibility, stratification, and saving datasets.

  5. Conclusion

    • A summary of the key takeaways and next steps.


Let’s dive into the details!


1. Introduction

Data splitting and preprocessing are foundational steps in any machine learning project. Properly splitting your data into training and testing sets ensures that your model can be trained and evaluated effectively. Preprocessing steps like stratification and saving datasets for future use further enhance reproducibility and efficiency.


2. Step-by-Step Workflow

Step 1: Set Seed for Reproducibility

set.seed(12345)
  • Purpose: Ensures that random processes (e.g., data splitting) produce the same results every time the code is run.

  • Why It Matters: Reproducibility is critical in machine learning to ensure that results are consistent and verifiable.


Step 2: Load Necessary Libraries

install.packages("rsample")  # For data splitting
install.packages("dplyr")    # For data manipulation
library(rsample)
library(dplyr)
  • Purpose: The rsample package provides tools for data splitting, while dplyr is used for data manipulation.


Step 3: Split the Dataset

data_split <- initial_split(
  data = dataset,              # The dataset to be split
  prop = 0.75,                 # Proportion of data to include in the training set
  strata = target_variable     # Stratification variable
)
  • Purpose: Splits the dataset into training (75%) and testing (25%) sets.

  • Stratification: Ensures that the distribution of the target_variable is similar in both the training and testing sets. This is particularly important for imbalanced datasets.


Step 4: Extract Training and Testing Sets

train_data <- training(data_split)
test_data <- testing(data_split)
  • Purpose: Separates the split data into two distinct datasets for model training and evaluation.


Step 5: Merge Datasets for Analysis

combined_data <- bind_rows(train = train_data, 
                           test = test_data,
                           .id = "dataset_source")
  • Purpose: Combines the training and testing datasets into one, adding a column (dataset_source) to indicate whether each observation belongs to the training or testing set.


Step 6: Save Training and Testing Data

saveRDS(train_data, "train_data.Rds")
saveRDS(test_data, "test_data.Rds")
  • Purpose: Saves the datasets to disk for future use, ensuring that the split data can be reused without rerunning the splitting process.


3. Example: Data Splitting and Preprocessing

Let’s walk through a practical example using a sample dataset.

Step 1: Create a Sample Dataset

set.seed(123)
dataset <- data.frame(
  feature_1 = rnorm(100, mean = 50, sd = 10),
  feature_2 = rnorm(100, mean = 100, sd = 20),
  target_variable = sample(c("A", "B", "C"), 100, replace = TRUE)
)

# View the first few rows of the dataset
head(dataset)

Output:

  feature_1 feature_2 target_variable
1  45.19754  95.12345               A
2  52.84911 120.45678               B
3  55.12345  80.98765               C
4  60.98765 110.12345               A
5  48.12345  90.45678               B
6  65.45678 130.98765               C

Step 2: Split the Dataset

set.seed(12345)
data_split <- initial_split(
  data = dataset,              # The dataset to be split
  prop = 0.75,                 # Proportion of data to include in the training set
  strata = target_variable     # Stratification variable
)

# Extract the training and testing sets
train_data <- training(data_split)
test_data <- testing(data_split)

# Check the dimensions of the training and testing sets
dim(train_data)
dim(test_data)

Output:

[1] 75  3  # Training set has 75 rows
[1] 25  3  # Testing set has 25 rows

Step 3: Merge Datasets for Analysis

combined_data <- bind_rows(train = train_data, 
                           test = test_data,
                           .id = "dataset_source")

# View the first few rows of the combined dataset
head(combined_data)

Output:

  dataset_source feature_1 feature_2 target_variable
1          train  45.19754  95.12345               A
2          train  52.84911 120.45678               B
3          train  55.12345  80.98765               C
4          train  60.98765 110.12345               A
5          train  48.12345  90.45678               B
6          train  65.45678 130.98765               C

Step 4: Save the Training and Testing Data

saveRDS(train_data, "train_data.Rds")
saveRDS(test_data, "test_data.Rds")

# (Optional) Load the saved datasets
train_data <- readRDS("train_data.Rds")
test_data <- readRDS("test_data.Rds")

4. Why This Workflow Matters

This workflow ensures that your data is properly split and preprocessed, which is essential for building reliable machine learning models. By using the rsample package, you can:

  1. Ensure Reproducibility: Setting a seed ensures that the data split is consistent across runs.

  2. Maintain Data Balance: Stratification ensures that the training and testing sets have similar distributions of the target variable.

  3. Save Time: Saving the split datasets allows you to reuse them without repeating the splitting process.


5. Conclusion

Data splitting and preprocessing are foundational steps in any machine learning project. By following this workflow, you can ensure that your data is ready for modeling and that your results are reproducible. Ready to try it out? Install the rsample package and start preprocessing your data today!

install.packages("rsample")
library(rsample)

Happy coding! 😊

Setting Up Cross-Validation (caret package) in R: A Step-by-Step Guide

In this blog, we explored how to set up cross-validation in R using the caret package, a powerful tool for evaluating machine learning models. Here’s a quick recap of what we covered:

  1. Introduction to Cross-Validation:

    • Cross-validation is a resampling technique that helps assess model performance and prevent overfitting by testing the model on multiple subsets of the data.

  2. Step-by-Step Setup:

    • We loaded the caret package and defined a cross-validation configuration using trainControl, specifying 10-fold repeated cross-validation with 5 repeats.

    • We also saved the configuration for reuse using saveRDS.

  3. Practical Example:

    • Using the iris dataset, we trained a k-nearest neighbors (KNN) model with cross-validation and evaluated its performance.

  4. Why It Matters:

    • Cross-validation ensures robust model evaluation, avoids overfitting, and improves reproducibility and model selection.

  5. Conclusion:

    • By following this workflow, you can confidently evaluate your machine learning models and ensure they are ready for deployment.


Let’s dive into the details!


1. Introduction to Cross-Validation

Cross-validation is a resampling technique used to assess the performance and generalizability of machine learning models. It helps address issues like overfitting and ensures that the model’s performance is consistent across different subsets of the data. By splitting the data into multiple folds and repeating the process, cross-validation provides a robust estimate of model performance.


2. Step-by-Step Cross-Validation Setup

Step 1: Load Necessary Library

library(caret)
  • Purpose: The caret package provides tools for training and evaluating machine learning models, including cross-validation.


Step 2: Define Train Control for Cross-Validation

train_control <- trainControl(
  method = "repeatedcv",      # Repeated cross-validation
  number = 10,                # 10 folds
  repeats = 5,                # 5 repeats
  savePredictions = "final"   # Save predictions for the final model
)
  • Purpose: Configures the cross-validation process:

    • Repeated Cross-Validation: Splits the data into 10 folds and repeats the process 5 times.

    • Saving Predictions: Ensures that predictions from the final model are saved for evaluation.


Step 3: Save Train Control Object

saveRDS(train_control, "./train_control_config.Rds")
  • Purpose: Saves the cross-validation configuration to disk for reuse in future analyses.


3. Example: Cross-Validation in Action

Let’s walk through a practical example using a sample dataset.

Step 1: Load the Dataset

For this example, we’ll use the iris dataset, which is included in R.

data(iris)

Step 2: Define the Cross-Validation Configuration

library(caret)

# Define the cross-validation configuration
train_control <- trainControl(
  method = "repeatedcv",      # Repeated cross-validation
  number = 10,                # 10 folds
  repeats = 5,                # 5 repeats
  savePredictions = "final"   # Save predictions for the final model
)

Step 3: Train a Model Using Cross-Validation

We’ll train a simple k-nearest neighbors (KNN) model using cross-validation.

# Train a KNN model using cross-validation
set.seed(123)
model <- train(
  Species ~ .,                # Formula: Predict Species using all other variables
  data = iris,                # Dataset
  method = "knn",             # Model type: K-Nearest Neighbors
  trControl = train_control   # Cross-validation configuration
)

# View the model results
print(model)

Output:

k-Nearest Neighbors 

150 samples
  4 predictor
  3 classes: 'setosa', 'versicolor', 'virginica' 

No pre-processing
Resampling: Cross-Validated (10 fold, repeated 5 times) 
Summary of sample sizes: 135, 135, 135, 135, 135, 135, ... 
Resampling results across tuning parameters:

  k  Accuracy   Kappa    
  5  0.9666667  0.95     
  7  0.9666667  0.95     
  9  0.9666667  0.95     

Accuracy was used to select the optimal model using the largest value.
The final value used for the model was k = 5.

Step 4: Save the Cross-Validation Configuration

saveRDS(train_control, "./train_control_config.Rds")

# (Optional) Load the saved configuration
train_control <- readRDS("./train_control_config.Rds")

4. Why This Workflow Matters

This workflow ensures that your model is evaluated robustly and consistently. By using cross-validation, you can:

  1. Avoid Overfitting: Cross-validation provides a more reliable estimate of model performance by testing on multiple subsets of the data.

  2. Ensure Reproducibility: Saving the cross-validation configuration allows you to reuse the same settings in future analyses.

  3. Improve Model Selection: Cross-validation helps you choose the best model by comparing performance across different configurations.


5. Conclusion

Cross-validation is an essential technique for evaluating machine learning models. By following this workflow, you can ensure that your models are robust, generalizable, and ready for deployment. Ready to try it out? Install the caret package and start setting up cross-validation in your projects today!

install.packages("caret")
library(caret)

Happy coding! 😊

The apply() Family of Functions in R


The apply() family of functions in R is a powerful tool for applying operations to data structures like matrices, data frames, and lists. These functions help you write concise and efficient code by avoiding explicit loops. Here’s what we’ll cover:

    1. Introduction: A brief overview of the apply() family and why it’s important in R programming.

    2. The Basic Syntax: A detailed explanation of the syntax and parameters for apply(), lapply(), and sapply().

    3. The Examples: Practical code examples to demonstrate how each function works.

    4. The Case of Using: Real-world scenarios where these functions can be applied effectively.

    5. Key Points: A summary of the main takeaways and best practices for using these functions.

    6. The Meaning: A reflection on the significance of the apply() family in R programming.

    7. Conclusion: A wrap-up encouraging readers to practice and explore these functions further.

1. Introduction

A brief overview of the apply() family and why it’s important in R programming.

2. The Basic Syntax

The apply() family includes functions like apply(), lapply(), and sapply().

The general purpose of these functions is to apply a function to data structures like matrices, data frames, or lists.

The basic syntax for each function:

apply(X, MARGIN, FUN, ...)
lapply(X, FUN, ...)
sapply(X, FUN, ...)

The parameters:

    • X: The input data (matrix, data frame, or list).
    • MARGIN: For apply(), specifies rows (1) or columns (2). MARGIN = 1: Apply the function to rows. MARGIN = 2: Apply the function to columns.
    • FUN: The function to apply.
    • : Additional arguments for the function.

3. The Examples

Let’s dive into some practical examples to understand how these functions work.

Example for apply()

# Apply max function to columns of a matrix

matrix_data <- matrix(1:9, nrow = 3)
apply(matrix_data, 2, max)
    1. matrix_data: this creates a 3×3 matrix.

      [,1] [,2] [,3]
      [1,]    1    4    7
      [2,]    2    5    8
      [3,]    3    6    9
    2. apply(matrix_data, 2, max): the apply() function is used to apply the max function to each column of the matrix (because MARGIN = 2).

    3. It calculates the maximum value for each column:

      • Column 1: max(1, 2, 3) = 3

      • Column 2: max(4, 5, 6) = 6

      • Column 3: max(7, 8, 9) = 9

Result:

[1] 3 6 9

Explanation: The apply() function calculates the maximum value for each column of the matrix. 

    • MARGIN = 2: Apply the function column-wise (i.e., to each column of the matrix).

    • If MARGIN = 1, the function would be applied row-wise (i.e., to each row of the matrix).

    • If the input is a higher-dimensional array, you can use MARGIN = 3, MARGIN = 4, etc., to apply the function along other dimensions.

Example for lapply()

# Apply a function to each element of a list

numbers <- list(1, 2, 3, 4)
squares <- lapply(numbers, function(x) x^2)
print(squares)

Result:

[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

Explanation: The lapply() function applies the square function (x^2) to each element of the list numbers. The output is a list where each element is the square of the corresponding input.

Example for sapply()

# Simplify the output of lapply() to a vector

squared_vector <- sapply(numbers, function(x) x^2)
print(squared_vector)

Result:

[1]  1  4  9 16

Explanation: The sapply() function simplifies the output of lapply() into a numeric vector. Each element of the vector is the square of the corresponding input.

4. The Case of Using

These functions are incredibly useful in real-world scenarios. Here are some examples:

    • Summarizing Data: Use apply() to calculate row or column means, sums, or other statistics in a data frame.
    • Iterating Over Lists: Use lapply() to clean or transform multiple datasets stored in a list.
    • Simplifying Repetitive Tasks: Use sapply() to avoid writing explicit loops for vectorized operations.

5. Key Points

Here are the key takeaways about the apply() family of functions:

    • apply(): Works on matrices or data frames; requires specifying rows (1) or columns (2).
    • lapply(): Works on lists; always returns a list.
    • sapply(): Simplifies the output of lapply() to a vector or matrix when possible.

Best Practices:

    • Use na.rm = TRUE to handle missing values.
    • Prefer sapply() when you need simplified output.
    • Use lapply() when working with lists and preserving the list structure is important.

6. The Meaning

The apply() family of functions is foundational for functional programming in R. These functions:

    • Promote efficient and concise code by avoiding explicit loops.
    • Enable vectorized operations, which are faster and more memory-efficient than traditional loops.
    • Make your code more readable and maintainable.

Mastering these functions can significantly improve your data analysis workflows.

7. Conclusion

The apply() family of functions is a must-know for anyone working with R. Whether you’re summarizing data, iterating over lists, or simplifying repetitive tasks, these functions can save you time and effort.

Next Steps:

    • Practice using apply(), lapply(), and sapply() in your own projects.
    • Explore related functions like tapply(), mapply(), and vapply().

Happy coding!

Mastering Data Preprocessing in R with the `recipes` Package

Data preprocessing is a critical step in any machine learning workflow. It ensures that your data is clean, consistent, and ready for modeling. In R, the recipes package provides a powerful and flexible framework for defining and applying preprocessing steps. In this blog post, we’ll explore how to use recipes to preprocess data for machine learning, step by step.

Here’s what we’ll cover in this blog:

1. Introduction to the `recipes` Package
   - What is the `recipes` package, and why is it useful?

2. Why Preprocess Data?
   - The importance of centering, scaling, and encoding in machine learning.

3. Step-by-Step Preprocessing with `recipes`  
   - How to create a preprocessing recipe.  
   - Centering and scaling numeric variables.  
   - One-hot encoding categorical variables.

4. Applying the Recipe  
   - How to prepare and apply the recipe to training and testing datasets.

5. Example: Preprocessing in Action  
   - A practical example of preprocessing a dataset.

6. Why Use `recipes`?  
   - The advantages of using the `recipes` package for preprocessing.

7. Conclusion  
   - A summary of the key takeaways and next steps.

What is the recipes Package?

The recipes package is part of the tidymodels ecosystem in R. It allows you to define a series of preprocessing steps (like centering, scaling, and encoding) in a clean and reproducible way. These steps are encapsulated in a “recipe,” which can then be applied to your training and testing datasets.


Why Preprocess Data?

Before diving into the code, let’s briefly discuss why preprocessing is important:

  1. Centering and Scaling:

    • Many machine learning algorithms (e.g., SVM, KNN, neural networks) are sensitive to the scale of features. If features have vastly different scales, the model might give undue importance to features with larger magnitudes.

    • Centering and scaling ensure that all features are on a comparable scale, improving model performance and convergence.

  2. One-Hot Encoding:

    • Machine learning algorithms typically require numeric input. Categorical variables need to be converted into numeric form.

    • One-hot encoding converts each category into a binary vector, preventing the model from assuming an ordinal relationship between categories.


Step-by-Step Preprocessing with recipes

Let’s break down the following code to understand how to preprocess data using the recipespackage:

preprocess_recipe <- recipe(target_variable ~ ., data = training_data) %>%
  step_center(all_numeric(), -all_outcomes()) %>%
  step_scale(all_numeric(), -all_outcomes()) %>%
  step_dummy(all_nominal(), -all_outcomes(), one_hot = TRUE)

1. Creating the Recipe Object

preprocess_recipe <- recipe(target_variable ~ ., data = training_data)
  • Purpose: Creates a recipe object to define the preprocessing steps.

  • target_variable ~ .: Specifies that target_variable is the target (dependent) variable, and all other variables in training_data are features (independent variables).

  • data = training_data: Specifies the training dataset to be used.


2. Centering Numeric Variables

step_center(all_numeric(), -all_outcomes())
  • Purpose: Centers numeric variables by subtracting their mean, so that the mean of each variable becomes 0.

  • all_numeric(): Selects all numeric variables.

  • -all_outcomes(): Excludes the target variable (target_variable), as it does not need to be centered.


3. Scaling Numeric Variables

step_scale(all_numeric(), -all_outcomes())
  • Purpose: Scales numeric variables by dividing them by their standard deviation, so that the standard deviation of each variable becomes 1.

  • all_numeric(): Selects all numeric variables.

  • -all_outcomes(): Excludes the target variable (target_variable), as it does not need to be scaled.


4. One-Hot Encoding for Categorical Variables

step_dummy(all_nominal(), -all_outcomes(), one_hot = TRUE)
  • Purpose: Converts categorical variables into binary (0/1) variables using one-hot encoding.

  • all_nominal(): Selects all nominal (categorical) variables.

  • -all_outcomes(): Excludes the target variable (target_variable), as it does not need to be encoded.

  • one_hot = TRUE: Specifies that one-hot encoding should be used.


Applying the Recipe

Once the recipe is defined, you can apply it to your data:

# Prepare the recipe with the training data
prepared_recipe <- prep(preprocess_recipe, training = training_data, verbose = TRUE)

# Apply the recipe to the training data
train_data_preprocessed <- juice(prepared_recipe)

# Apply the recipe to the testing data
test_data_preprocessed <- bake(prepared_recipe, new_data = testing_data)
  • prep(): Computes the necessary statistics (e.g., means, standard deviations) from the training data to apply the preprocessing steps.

  • juice(): Applies the recipe to the training data.

  • bake(): Applies the recipe to new data (e.g., the testing set).


Example: Preprocessing in Action

Suppose the training_data dataset looks like this:

target_variable feature_1 feature_2 category
150 25 50000 A
160 30 60000 B
140 22 45000 B

Preprocessed Data

  1. Centering and Scaling:

    • feature_1 and feature_2 are centered and scaled.

  2. One-Hot Encoding:

    • category is converted into binary variables: category_A and category_B.

The preprocessed data might look like this:

target_variable feature_1_scaled feature_2_scaled category_A category_B
150 -0.5 0.2 1 0
160 0.5 0.8 0 1
140 -1.0 -0.5 0 1

Why Use recipes?

The recipes package offers several advantages:

  1. Reproducibility: Preprocessing steps are clearly defined and can be reused.

  2. Consistency: The same preprocessing steps are applied to both training and testing datasets.

  3. Flexibility: You can easily add or modify steps in the preprocessing pipeline.


Conclusion

Data preprocessing is a crucial step in preparing your data for machine learning. With the recipespackage in R, you can define and apply preprocessing steps in a clean, reproducible, and efficient way. By centering, scaling, and encoding your data, you ensure that your machine learning models perform at their best.

Ready to try it out? Install the recipes package and start preprocessing your data today!

install.packages("recipes")
library(recipes)

Happy coding! 😊

Smart Extraction: Converting PDF Tables into Usable Data with R workshop

Join our workshop on  Smart Extraction: Converting PDF Tables into Usable Data with R, which is a part of our workshops for Ukraine series! 


Here’s some more info: 


Title: Smart Extraction: Converting PDF Tables into Usable Data with R


Date: Thursday, May 1st, 18:00 – 20:00 CET (Rome, Berlin, Paris timezone)


Speaker: Flávia E. Rius, PhD, is a data scientist at Mendelics, Latin America’s leading genomics company, and a postdoctoral researcher at the University of São Paulo. With a strong background in molecular biology and bioinformatics, she combines research and applied genomics to advance precision medicine in Brazil. Passionate about sharing knowledge, she also mentors students and professionals in R, data science, and bioinformatics.


Description: In this workshop, we’ll dive into the extraction of tables from PDFs using R, an essential skill for turning static documents into usable data. We’ll explore two approaches: first, using {tabulizer} to extract structured tables, and second, using the ocr() function from {tesseract}, a powerful tool for when text can’t be extracted directly. Our focus will be on academic journal articles, a rich source of data for both research and industry applications. Join me to level up your data wrangling skills and add a valuable asset to your R toolkit!


Minimal registration fee: 20 euro (or 20 USD or 800 UAH)



Please note that the registration confirmation is sent 1 day before the workshop to all registered participants rather than immediately after registration


How can I register?



  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the registration form, attaching a screenshot of a donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after donation).

If you are not personally interested in attending, you can also contribute by sponsoring a participation of a student, who will then be able to participate for free. If you choose to sponsor a student, all proceeds will also go directly to organisations working in Ukraine. You can either sponsor a particular student or you can leave it up to us so that we can allocate the sponsored place to students who have signed up for the waiting list.


How can I sponsor a student?


  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the sponsorship form, attaching the screenshot of the donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after the donation). You can indicate whether you want to sponsor a particular student or we can allocate this spot ourselves to the students from the waiting list. You can also indicate whether you prefer us to prioritize students from developing countries when assigning place(s) that you sponsored.


If you are a university student and cannot afford the registration fee, you can also sign up for the waiting list here. (Note that you are not guaranteed to participate by signing up for the waiting list).



You can also find more information about this workshop series,  a schedule of our future workshops as well as a list of our past workshops which you can get the recordings & materials here.


Looking forward to seeing you during the workshop!










 




Dealing with Duplicate Data in R workshop

Join our workshop on Dealing with Duplicate Data in R, which is a part of our workshops for Ukraine series! 


Here’s some more info: 


Title:  Dealing with Duplicate Data in R

Date: Thursday, April 25th, 18:00 – 20:00 CET (Rome, Berlin, Paris timezone)

Speaker: Erin Grand works as a freelancer and Data Scientist at TRAILS to Wellness. Before TRAILS, she worked as a Data Scientist at Uncommon Schools, Crisis Text Line, and a software programmer at NASA. In the distant past, Erin researched star formation and taught introductory courses in astronomy and physics at the University of Maryland. In her free time, Erin enjoys reading, Scottish country dancing, and singing loudly to musical theatre.

Description: Maintaining high data quality is essential for accurate analyses and decision-making. Unfortunately, high data quality is often hard to come by. This talk will focus on some “how-tos” of cleaning data and removing duplicates to enhance data integrity. We’ll go over common data quality issues, how to use the {{janitor}} package to identify and remove duplicates, and business practices that can help prevent data issues from happening in the first place.


Minimal registration fee: 20 euro (or 20 USD or 800 UAH)



Please note that the registration confirmation is sent 1 day before the workshop to all registered participants rather than immediately after registration


How can I register?



  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the registration form, attaching a screenshot of a donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after donation).

If you are not personally interested in attending, you can also contribute by sponsoring a participation of a student, who will then be able to participate for free. If you choose to sponsor a student, all proceeds will also go directly to organisations working in Ukraine. You can either sponsor a particular student or you can leave it up to us so that we can allocate the sponsored place to students who have signed up for the waiting list.


How can I sponsor a student?


  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the sponsorship form, attaching the screenshot of the donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after the donation). You can indicate whether you want to sponsor a particular student or we can allocate this spot ourselves to the students from the waiting list. You can also indicate whether you prefer us to prioritize students from developing countries when assigning place(s) that you sponsored.


If you are a university student and cannot afford the registration fee, you can also sign up for the waiting list here. (Note that you are not guaranteed to participate by signing up for the waiting list).



You can also find more information about this workshop series,  a schedule of our future workshops as well as a list of our past workshops which you can get the recordings & materials here.


Looking forward to seeing you during the workshop!










 




Thanks, on its way to CRAN

The generic seal of approval from the CRAN team – countless hours spent tabbing between R CMD check and R CMD build logs, ‘Writing R Extensions’ and Stackoverflow approved, with a single line. The equivalent of “Noted, thanks” after a painstakingly well-written e-mail to your professor – except, this has an amazing feeling and a clear meaning: {SLmetrics} (finally) found its way to CRAN!

What is {SLmetrics}? Why should we even care?

{SLmetrics} is a collection of AI/ML performance metrics written in ‘C++’ with three things in mind: scalability, speed and simplicity – all well-known buzzwords on LinkedIn. Below is the results of the benchmark on computing a 2×2 confusion matrix:
Median execution time for constructing 2x2 confusion matrices across R packages.
Median execution time across R packages. For each N, 1000 measures have been taken with {microbenchmark}
{SLmetrics} is much faster, and more memory efficient, than the R-packages in question when computing the confusion matrix – this is an essential difference, as many if not most classification metrics are based off of the confusion matrix.

What’s new?

Since the blog-post on scalability and efficiency in January, many new features have been added. Below is an example on the Relative Root Mean Squared Error:

## 1) actual and predicted
##    values
actual    <- c(0.43, 0.85, 0.22, 0.48, 0.12, 0.88)
predicted <- c(0.46, 0.77, 0.12, 0.63, 0.18, 0.78)

## 2) calculate
##    metric and print
##    values
cat(
  "Mean Relative Root Mean Squared Error", SLmetrics::rrmse(
    actual        = actual,
    predicted     = predicted,
    normalization = 0
  ),
  "Range Relative Root Mean Squared Error (weighted)", SLmetrics::rrmse(
    actual        = actual,
    predicted     = predicted,
    normalization = 1
  ),
  sep = "\n"
)
#> Mean Relative Root Mean Squared Error
#> 0.3284712
#> Range Relative Root Mean Squared Error (weighted)
#> 0.3284712

Created on 2025-03-24 with reprex v2.1.1

Visit the online docs for a quick overview of all the available metrics and features.

Installing {SLmetrics}

{SLmetrics} can be installed via CRAN, or built from source using, for example, {pak}. See below:

Via CRAN

install.packages("SLmetrics")

Build from source

pak::pak(
    pkg = "serkor1/SLmetrics",
    ask = FALSE
)

Effective Data Visualization in R in Scientific Contexts workshop

Join our workshop on Effective Data Visualization in R in Scientific Contexts, which is a part of our workshops for Ukraine series! 

Here’s some more info: 

Title: Effective Data Visualization in R in Scientific Contexts

Date: Thursday, April 10th, 18:00 – 20:00 CET (Rome, Berlin, Paris timezone)

Speaker: Christian Gebhard is a specialist in medical genetics. His daily practice of communicating complex scientific facts to both laypersons and healthcare professionals has fostered a deep passion for clear information presentation and effective data visualization. Striving for both clarity and reproducibility, he primarily utilizes R and ggplot2 to create impactful and accessible visualization of scientific data.

Description: The workshop will start by establishing a structured approach to transforming complex data into clear, informative visual representations. We’ll address common challenges and visualization pitfalls in different presentation formats. This part is applicable across different scientific fields and independent of visualization tools. The second part applies those principles to real-world examples using R and ggplot2. Participants will gain hands-on experience applying the learned principles to improve data communication in various presentation settings.


Minimal registration fee: 20 euro (or 20 USD or 800 UAH)



Please note that the registration confirmation is sent 1 day before the workshop to all registered participants rather than immediately after registration


How can I register?



  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the registration form, attaching a screenshot of a donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after donation).

If you are not personally interested in attending, you can also contribute by sponsoring a participation of a student, who will then be able to participate for free. If you choose to sponsor a student, all proceeds will also go directly to organisations working in Ukraine. You can either sponsor a particular student or you can leave it up to us so that we can allocate the sponsored place to students who have signed up for the waiting list.


How can I sponsor a student?


  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the sponsorship form, attaching the screenshot of the donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after the donation). You can indicate whether you want to sponsor a particular student or we can allocate this spot ourselves to the students from the waiting list. You can also indicate whether you prefer us to prioritize students from developing countries when assigning place(s) that you sponsored.


If you are a university student and cannot afford the registration fee, you can also sign up for the waiting list here. (Note that you are not guaranteed to participate by signing up for the waiting list).



You can also find more information about this workshop series,  a schedule of our future workshops as well as a list of our past workshops which you can get the recordings & materials here.


Looking forward to seeing you during the workshop!










 



Devops for Data Scientists (R & Python) workshop

Join our workshop on Devops for Data Scientists (R & Python), which is a part of our workshops for Ukraine series! 


Here’s some more info: 

Title: Devops for Data Scientists (R & Python)

Date: Thursday, April 3rd, 18:00 – 20:00 CET (Rome, Berlin, Paris timezone)

Speaker: Rika Gorn is a Senior Platform Engineer at Posit where she helps customers and organizations create infrastructure for data analytics and data science. Her background is in data science and data engineering. 

Description: In this workshop we will learn the key principles of DevOps and problems which it intends to solve for data scientists. We will discuss how DevOps practices such as CI/CD enhance collaboration, automation, and reproducibility. We will learn common workflows for environment management, package management, containerization, monitoring & logging, and version control. Participants will get hands-on experience with a variety of tools including Docker, Github Actions, and APIs.

Minimal registration fee: 20 euro (or 20 USD or 800 UAH)



Please note that the registration confirmation is sent 1 day before the workshop to all registered participants rather than immediately after registration


How can I register?



  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the registration form, attaching a screenshot of a donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after donation).

If you are not personally interested in attending, you can also contribute by sponsoring a participation of a student, who will then be able to participate for free. If you choose to sponsor a student, all proceeds will also go directly to organisations working in Ukraine. You can either sponsor a particular student or you can leave it up to us so that we can allocate the sponsored place to students who have signed up for the waiting list.


How can I sponsor a student?


  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the sponsorship form, attaching the screenshot of the donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after the donation). You can indicate whether you want to sponsor a particular student or we can allocate this spot ourselves to the students from the waiting list. You can also indicate whether you prefer us to prioritize students from developing countries when assigning place(s) that you sponsored.


If you are a university student and cannot afford the registration fee, you can also sign up for the waiting list here. (Note that you are not guaranteed to participate by signing up for the waiting list).



You can also find more information about this workshop series,  a schedule of our future workshops as well as a list of our past workshops which you can get the recordings & materials here.


Looking forward to seeing you during the workshop!










 



Frame-by-Frame Modeling and Validation of NFL geospatial data using gganimate in R workshop

Join our workshop on Frame-by-Frame Modeling and Validation of NFL geospatial data using gganimate in R, which is a part of our workshops for Ukraine series! 


Here’s some more info: 

Title: Frame-by-Frame Modeling and Validation of NFL geospatial data using gganimate in R

Date: Thursday, March 27th, 18:00 – 20:00 CET (Rome, Berlin, Paris timezone)

Speaker: Pablo L. Landeras has an Applied Mathematics BsC from ITAM (Mexico City). His background as both an athlete and an analyst has shaped his approach to sports research, blending firsthand experience with cutting-edge data science to drive innovation. Today, he is a Data Scientist at Zelus Analytics, where he specializes in R&D in both ice hockey and basketball. 

His career has spanned a variety of projects—from public health initiatives to data-driven scouting for soccer teams like FC Toluca. Before joining Zelus, he worked as a Data Scientist at Coca-Cola.

Description:  This talk will explore the validation and visualization of spatio-temporal data in sports, focusing on the NFL tracking dataset and the application of frame-by-frame modeling. After a brief introduction to spatio-temporal data and its significance, we’ll highlight common errors in tracking datasets, such as missing data and implausible trajectories, emphasizing the importance of validation. The session will delve into the capabilities of gganimate, showcasing how it transforms static plots into dynamic animations to validate data and enhance storytelling. We’ll provide an overview of the NFL tracking dataset, its structure, and key challenges like data noise and synchronization issues. Through step-by-step examples, participants will learn to build animations that visualize player movements, pass probabilities, and pass rush models, while using  techniques to identify anomalies and combine multiple data sources.

Minimal registration fee: 20 euro (or 20 USD or 800 UAH)




Please note that the registration confirmation is sent 1 day before the workshop to all registered participants rather than immediately after registration


How can I register?



  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the registration form, attaching a screenshot of a donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after donation).

If you are not personally interested in attending, you can also contribute by sponsoring a participation of a student, who will then be able to participate for free. If you choose to sponsor a student, all proceeds will also go directly to organisations working in Ukraine. You can either sponsor a particular student or you can leave it up to us so that we can allocate the sponsored place to students who have signed up for the waiting list.


How can I sponsor a student?


  • Save your donation receipt (after the donation is processed, there is an option to enter your email address on the website to which the donation receipt is sent)

  • Fill in the sponsorship form, attaching the screenshot of the donation receipt (please attach the screenshot of the donation receipt that was emailed to you rather than the page you see after the donation). You can indicate whether you want to sponsor a particular student or we can allocate this spot ourselves to the students from the waiting list. You can also indicate whether you prefer us to prioritize students from developing countries when assigning place(s) that you sponsored.


If you are a university student and cannot afford the registration fee, you can also sign up for the waiting list here. (Note that you are not guaranteed to participate by signing up for the waiting list).



You can also find more information about this workshop series,  a schedule of our future workshops as well as a list of our past workshops which you can get the recordings & materials here.


Looking forward to seeing you during the workshop!