### Install Spotlight via pip Source: https://renumics.com/docs/getting-started Installs the renumics-spotlight package using pip. It's recommended to install in a virtual environment. ```bash pip install renumics-spotlight ``` -------------------------------- ### Initialize Spotlight Development Environment Source: https://renumics.com/docs/development Initializes the Spotlight development environment by installing dependencies and setting up pre-commit hooks using the provided Makefile. This command streamlines the setup process. ```bash make init ``` -------------------------------- ### Load CSV and Show with Spotlight (CLI) Source: https://renumics.com/docs/getting-started Downloads a CSV file using curl and then displays it using the Spotlight CLI. Custom data types can be specified using --dtype. ```bash curl https://renumics.com/data/mnist/mnist-tiny.csv -o mnist-tiny.csv spotlight mnist-tiny.csv --dtype image=Image --dtype embedding=Embedding ``` -------------------------------- ### Install renumics-spotlight and datasets Source: https://renumics.com/docs/data-centric-ai/playbook/decision-boundary Installs the required Python packages, renumics-spotlight and datasets, using pip. This is a prerequisite for running the provided code examples. ```python #@title Install required packages with PIP !pip install renumics-spotlight datasets ``` -------------------------------- ### Load Hugging Face Dataset and Show with Spotlight (Python) Source: https://renumics.com/docs/getting-started Loads a dataset from the Hugging Face hub and displays it with Spotlight. Spotlight automatically parses data type descriptions and label mappings. ```python import datasets from renumics import spotlight ds = datasets.load_dataset('speech_commands', 'v0.01', split='all') spotlight.show(ds) ``` -------------------------------- ### Install Dependencies for Towhee and Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/towhee-embedding Installs the necessary Python packages including renumics-spotlight, towhee, and datasets for image embedding generation and data handling. This is a prerequisite for running the provided code examples. ```python # Install dependencies !pip install renumics-spotlight towhee datasets ``` -------------------------------- ### Opt-out of Usage Tracking (Bash) Source: https://renumics.com/docs/getting-started Sets an environment variable to opt out of crash report and performance collection in Spotlight. ```bash export SPOTLIGHT_OPT_OUT=true ``` -------------------------------- ### Install Dependencies Source: https://renumics.com/docs/data-centric-ai/playbook/huggingface-embedding Installs the necessary Python packages for using Huggingface transformers, torch, datasets, and renumics-spotlight. ```python !pip install renumics-spotlight transformers torch datasets ``` -------------------------------- ### Install and Verify Pre-commit Hooks Source: https://renumics.com/docs/development Installs and verifies pre-commit hooks for the Spotlight project using Poetry. These hooks automate code formatting and testing before commits and pushes, ensuring code quality. ```bash poetry run pre-commit install --hook-type pre-commit poetry run pre-commit install --hook-type pre-push ``` -------------------------------- ### Install Dependencies for Sliceguard and Spotlight Source: https://renumics.com/docs/use-cases/image-fine-tuning Installs the necessary Python packages, including renumics-spotlight and sliceguard with all optional dependencies, required for image dataset creation and model fine-tuning. ```bash pip install renumics-spotlight sliceguard[all] ``` -------------------------------- ### Run Spotlight Development Server Source: https://renumics.com/docs/development Starts the development server for the Spotlight project using the 'dev' target in the Makefile. This command allows for live development and testing of both the backend and frontend. ```bash make dev ``` -------------------------------- ### Clone and Setup Spotlight Repository Source: https://renumics.com/docs/development Clones the Spotlight repository from GitHub and sets up an 'upstream' remote pointing to the original repository. This allows for tracking changes and contributing back to the project. ```bash git clone https://github.com/YOUR_GIT_USERNAME/spotlight.git cd spotlight git remote add upstream https://github.com/renumics/spotlight.git ``` -------------------------------- ### Install Node.js and pnpm on Linux Source: https://renumics.com/docs/development Installs Node.js and pnpm, a package manager for Node.js, on a Linux system. This is required for developing the React frontend of Spotlight. It also includes a check for the Node.js version. ```bash sudo apt install nodejs curl -fsSL https://get.pnpm.io/install.sh | sh - # check your installed node version node -v ``` -------------------------------- ### Install Python and Poetry on Linux Source: https://renumics.com/docs/development Installs Python 3 and Poetry, a dependency management tool for Python, on a Linux system using apt package manager. This is a prerequisite for developing the Python backend of Spotlight. ```bash sudo apt update sudo apt install python3 python3-dev curl -sSL https://install.python-poetry.org | python3 - ``` -------------------------------- ### Install Dependencies for SliceGuard and Spotlight Source: https://renumics.com/docs/use-cases/audio-classification Installs the necessary Python packages for using renumics-spotlight and sliceguard, including optional dependencies for full functionality. This command is essential before running the data detection code. ```bash pip install renumics-spotlight sliceguard[all] scikit-learn ``` -------------------------------- ### Install Dependencies for Duplicate Detection Source: https://renumics.com/docs/data-centric-ai/playbook/duplicates-annoy Installs the necessary Python packages for using Annoy and Renumics Spotlight. This includes 'renumics-spotlight', 'datasets', and 'annoy'. These libraries are essential for loading data, computing embeddings, and performing nearest neighbor searches. ```python #@title Install required packages with PIP !pip install renumics-spotlight datasets annoy ``` -------------------------------- ### Load Pandas DataFrame and Show with Spotlight (Python) Source: https://renumics.com/docs/getting-started Loads a CSV file into a Pandas DataFrame and displays it using Spotlight's show function. Custom data types like Image and Embedding can be specified. ```python import pandas as pd from renumics import spotlight df = pd.read_csv("https://renumics.com/data/mnist/mnist-tiny.csv") spotlight.show(df, dtype={"image": spotlight.Image, "embedding": spotlight.Embedding}) ``` -------------------------------- ### Install Required Packages with PIP Source: https://renumics.com/docs/data-centric-ai/playbook/label-errors-cleanlab Installs the necessary Python packages: renumics-spotlight, cleanlab, and datasets. These are required for data analysis and visualization. ```python #@title Install required packages with PIP !pip install renumics-spotlight cleanlab datasets ``` -------------------------------- ### Install Sliceguard and related packages Source: https://renumics.com/docs/data-centric-ai/playbook/data-slices-sliceguard Installs the necessary Python packages including renumics-spotlight, sliceguard, datasets, and cleanvision using pip. This is a prerequisite for using the provided code snippets. ```python #@title Install required packages with PIP !pip install renumics-spotlight sliceguard datasets cleanvision ``` -------------------------------- ### Install Dependencies for F1 Data Analysis Source: https://renumics.com/docs/use-cases/motorsports-telemetry Installs the necessary Python libraries for loading F1 data and for visualization. This includes 'renumics-spotlight' for data visualization and 'fastf1' for accessing Formula 1 telemetry data. ```bash pip install renumics-spotlight fastf1 ``` -------------------------------- ### Explore Enriched Dataset with Custom Layout (Python) Source: https://renumics.com/docs/getting-started Displays an enriched Hugging Face dataset using Spotlight with a custom visualization layout for classification debugging. It specifies embedding columns and inspects audio data types. ```python from renumics import spotlight layout = spotlight.layouts.debug_classification(embedding='embedding', inspect={'audio': spotlight.dtypes.audio_dtype}) spotlight.show(ds, dtype={'embedding': spotlight.Embedding}, layout=layout ) ``` -------------------------------- ### Load CSV File via CLI Source: https://renumics.com/docs/loading-data Loads a dataset from a CSV file using the Spotlight Command Line Interface (CLI). This is a straightforward way to start exploring tabular data. ```bash spotlight mnist-tiny.csv ``` -------------------------------- ### Concatenate Hugging Face Datasets (Python) Source: https://renumics.com/docs/getting-started Loads two datasets from the Hugging Face hub and concatenates them along axis 1. This is useful for combining raw data with enrichment results. ```python import datasets ds = datasets.load_dataset('speech_commands', 'v0.01', split='all') ds_results = datasets.load_dataset('renumics/speech_commands-ast-finetuned-results', 'v0.01', split='all') ds = datasets.concatenate_datasets([ds, ds_results], axis=1) ``` -------------------------------- ### Load CIFAR-100 dataset and convert to Pandas DataFrame Source: https://renumics.com/docs/data-centric-ai/playbook/data-slices-sliceguard Loads the CIFAR-100 dataset from the Huggingface hub and converts it into a pandas DataFrame for further analysis. This is the first step in the example walkthrough. ```python dataset = datasets.load_dataset("renumics/cifar100-enriched", split="test") df = dataset.to_pandas() ``` -------------------------------- ### Load and Show Hugging Face 'speech_commands' Dataset with Spotlight Source: https://renumics.com/docs/loading-data/huggingface Loads the 'speech_commands' dataset from Hugging Face and visualizes it using Renumics Spotlight. This requires the 'datasets' and 'renumics' libraries. It takes the dataset split as input and outputs an interactive Spotlight visualization. ```python import datasets from renumics import spotlight ds = datasets.load_dataset('speech_commands', 'v0.01', split='validation') spotlight.show(ds) ``` -------------------------------- ### Load and View FSD50K Dataset with Spotlight Source: https://renumics.com/docs/configure-visualizations/ui-components This snippet shows how to download the 'fsd50k-tiny.csv' dataset using curl and then load it into Spotlight. It defines the data types for 'window', 'embedding', and 'audio' columns, allowing Spotlight to correctly interpret and visualize audio-related data. ```shell curl https://spotlight.renumics.com/data/fsd50k/fsd50k-tiny.csv -o fsd50k-tiny.csv spotlight fsd50k-tiny.csv --dtype window=Window --dtype embedding=Embedding --dtype audio=Audio ``` -------------------------------- ### Append Data to HDF5 Dataset with Spotlight Source: https://renumics.com/docs/loading-data/hdf5 Demonstrates appending data to an existing HDF5 dataset in append mode ('a'). It shows how to add columns with default values and optional columns, and how to set specific rows to None. ```python from datetime import datetime with spotlight.Dataset("example.h5", "w") as dataset: dataset.append_bool_column("boolean", [True, True, True, False], default=False) dataset.append_int_column("integer", range(4), default=-1) dataset.append_float_column("float", 1.0, optional=True) dataset.append_string_column("string", "foo", optional=True) dataset.append_categorical_column( "categorical", ["test", "train", "test", "train"], optional=True ) dataset.append_datetime_column("datetime", datetime.now(), optional=True) with spotlight.Dataset("example.h5", "a") as dataset: dataset[1] = {key: None for key in dataset.keys()} spotlight.show("example.h5") ``` -------------------------------- ### Load and Show Hugging Face 'cifar100' Dataset with Spotlight Source: https://renumics.com/docs/loading-data/huggingface Loads the 'cifar100' dataset from Hugging Face and displays it using Renumics Spotlight. This demonstrates a straightforward integration for image datasets. It requires the 'datasets' library and outputs an interactive visualization. ```python ds = datasets.load_dataset('cifar100', split='test') spotlight.show(ds) ``` -------------------------------- ### Load and View MNIST Dataset with Spotlight Source: https://renumics.com/docs/configure-visualizations/ui-components This snippet demonstrates how to download the 'mnist-tiny.csv' dataset using curl and then load it into Spotlight for analysis. It specifies the data types for 'image', 'embedding', and 'label' columns, enabling specialized visualizations and interactions within Spotlight. ```shell curl https://renumics.com/docs/data/mnist/mnist-tiny.csv -o mnist-tiny.csv spotlight mnist-tiny.csv --dtype image=Image --dtype embedding=Embedding --dtype label=Category ``` -------------------------------- ### Inspect Data Drift Candidates with RENUMICS Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/drift-kcore Prepares a DataFrame for visualization by dropping unnecessary columns and then uses RENUMICS Spotlight to inspect potential data drift candidates. It loads a layout configuration from a URL and displays the data with specified data types and layout. ```python import requests import json df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/drift_kcore.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Visualize Hugging Face Dataset with Spotlight Source: https://renumics.com/docs/use-cases/motorsports-telemetry Visualizes a Hugging Face Dataset using renumics-spotlight. This method loads data lazily, allowing for the processing and visualization of very large time series datasets without consuming significant memory. ```python from renumics import spotlight # Assuming ds is a loaded Hugging Face Dataset spotlight.show(ds) ``` -------------------------------- ### Build Layout with Python API - RENUMICS Spotlight Source: https://renumics.com/docs/custom-visualizations/ui-components/layout This Python code snippet demonstrates how to programmatically build a RENUMICS Spotlight layout using its Python API. It involves loading a pandas DataFrame, defining data types, and configuring various widgets like Table, SimilarityMap, and Histogram, along with an Inspector widget, to create a custom layout. Dependencies include pandas and renumics.spotlight. ```python import pandas as pd from renumics import spotlight from renumics.spotlight import layout df = pd.read_csv("https://spotlight.renumics.com/data/fsd50k/fsd50k-tiny.csv") spotlight.show( df, dtype={"audio": spotlight.Audio, "embedding": spotlight.Embedding}, layout=layout.layout( [ [layout.table()], [ layout.similaritymap( columns=["embedding"], color_by_column="annotation", size_by_column="entropy", ) ], [ layout.histogram( column="annotation", stack_by_column="prediction_incorrect" ) ], ], layout.widgets.Inspector(), ), ) ``` -------------------------------- ### Register TextLengthLens in index.ts Source: https://renumics.com/docs/development/lenses Shows how to register the newly created 'TextLengthLens' within the 'ALL_LENSES' array in the 'src/lenses/index.ts' file. This step is crucial for the RENUMICS platform to recognize and utilize the custom Lens. ```typescript ... import TextLengthLens from './TextLengthLens'; export const ALL_LENSES = [ ... TextLengthLens, ]; ``` -------------------------------- ### Inspect Label Errors with Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/label-errors-cleanlab Prepares data for inspection by dropping unnecessary columns and then uses Renumics Spotlight to visualize the dataset, highlighting potential label errors. It loads a layout configuration from a URL for the Spotlight display. ```python import requests import json df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/label_errors_cleanlab.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Inspect and Visualize Duplicates with Renumics Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/duplicates-annoy Prepares the DataFrame for visualization by dropping embedding and probability columns, fetches a layout configuration from a URL, and then displays the data using Renumics Spotlight. This step allows for interactive inspection and identification of near-duplicate images. ```python df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/duplicates_annoy.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Write Image Dataset to HDF5 with Spotlight Source: https://renumics.com/docs/loading-data/hdf5 Saves an image dataset to an HDF5 file using Spotlight. It includes columns for index, label, and image data. The image data is preprocessed for display. ```python from sklearn import datasets import numpy as np from renumics import spotlight OUTPUT_DATASET = "image_example_dataset.h5" digits = datasets.load_digits() with spotlight.Dataset(OUTPUT_DATASET, "w") as dataset: dataset.append_int_column("index", order=1) dataset.append_int_column("label", order=0) dataset.append_image_column("image") for i, (image, label) in enumerate(zip(digits.images, digits.target)): # in the sample dataset the value 0 means white and 16 means black # in order to display it correctly in the browser, we need to switch that # to have 0 as black and 255 as white image = (255 * (1 - image / 16)).round().astype("uint8") # scale image by 32 along each dimension in order to display it in the browser image = np.repeat(image, 32, axis=1) image = np.repeat(image, 32, axis=0) dataset.append_row(index=i, label=label, image=image) ``` -------------------------------- ### Load CIFAR-100 Dataset and Convert to Pandas Source: https://renumics.com/docs/data-centric-ai/playbook/label-errors-cleanlab Loads the CIFAR-100 dataset from the Huggingface hub and converts it into a Pandas DataFrame. This is a preparatory step for further analysis. ```python dataset = datasets.load_dataset("renumics/cifar100-enriched", split="train") df = dataset.to_pandas() ``` -------------------------------- ### Manually Specify Data Types via Python API Source: https://renumics.com/docs/loading-data Demonstrates how to manually specify data types for columns when loading a Pandas DataFrame with Spotlight. This allows for explicit control over how unstructured data like images and embeddings are interpreted. ```python from renumics import spotlight dtype = {"image": spotlight.Image, "embedding":spotlight.Embedding} spotlight.show(df, dtype=dtype) ``` -------------------------------- ### Perform EDA with Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/huggingface-embedding Uses the renumics-spotlight library to visualize the processed data, including the reduced embeddings. It specifies the data types for 'image' and 'embedding_reduced' to enable interactive exploration. ```python df_show = df.drop(columns=['embedding', 'probabilities']) spotlight.show(df_show, port=port, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}) ``` -------------------------------- ### Create Bing Image Dataset and Fine-tune ViT Model Source: https://renumics.com/docs/use-cases/image-fine-tuning This Python script generates an image dataset from Bing search results for specified class names, splits it into training and validation sets, fine-tunes a ViT model for image classification, and then enriches the dataset with model predictions and embeddings. Finally, it launches a Spotlight interface to visualize the results and identify clusters. ```python # The Imports from renumics import spotlight from sliceguard.data import create_imagedataset_from_bing from sliceguard.models.huggingface import finetune_image_classifier, generate_image_pred_probs_embeddings from sliceguard.embeddings import generate_image_embeddings # Create an Image Dataset from Bing class_names = [ "Blue Tang", "Clownfish", "Spotted Eagle Ray", "Longnose Butterfly Fish", "Moorish Idol", "Royal Gramma Fish", ] df = create_imagedataset_from_bing( class_names, 25, "data", test_split=0.2, license="Free to share and use" ) # DataFrame Format: #+----+-------------------------------------+-------------------+---------+---------+ #| | image | label_str | label | split | #|----+-------------------------------------+-------------------+---------+---------| #| 6 | data/Blue Tang/Image_15.jpg | Blue Tang | 0 | val | #| 73 | data/Spotted Eagle Ray/Image_11.jpg | Spotted Eagle Ray | 2 | train | #| 51 | data/Spotted Eagle Ray/Image_13.jpg | Spotted Eagle Ray | 2 | train | #| 57 | data/Spotted Eagle Ray/Image_7.jpg | Spotted Eagle Ray | 2 | val | #| 31 | data/Clownfish/Image_10.jpg | Clownfish | 1 | train | #| 27 | data/Clownfish/Image_13.jpg | Clownfish | 1 | train | #+----+-------------------------------------+-------------------+---------+---------+ # Fine-tune a ViT Model with the data (in 1-2 minutes on a GPU) finetune_image_classifier( df[df["split"] == "train"], model_name="google/vit-base-patch16-224-in21k", output_model_folder="./model_folder", epochs=15, ) # Enrich the DataFrame with Predictions, Probabilities and Embeddings df["prediction"], df["probs"], df["embeddings"] = generate_image_pred_probs_embeddings( df["image"].values, model_name="./model_folder" ) # Check the result and detect problematic clusters spotlight.show( df, layout="https://spotlight.renumics.com/resources/image_classification_v1.0.json" ) ``` -------------------------------- ### Display HDF5 Dataset with Spotlight Source: https://renumics.com/docs/loading-data/hdf5 Loads and displays an HDF5 dataset using the Spotlight API. This function can be used to view the data stored in the HDF5 file. ```python spotlight.show(OUTPUT_DATASET) ``` -------------------------------- ### Load CIFAR-100 Dataset and Convert to Pandas DataFrame Source: https://renumics.com/docs/data-centric-ai/playbook/duplicates-annoy Loads the CIFAR-100 dataset from the Huggingface hub using the 'datasets' library and converts it into a Pandas DataFrame. This is the first step in preparing the data for nearest neighbor analysis. ```python dataset = datasets.load_dataset("renumics/cifar100-enriched", split="train") df = dataset.to_pandas() ``` -------------------------------- ### Write Mixed Data Types to HDF5 with Spotlight Source: https://renumics.com/docs/loading-data/hdf5 Creates an HDF5 file containing various data types: boolean, integer, float, string, categorical, and datetime. The dataset is then displayed. ```python from datetime import datetime with spotlight.Dataset("example.h5", "w") as dataset: dataset.append_bool_column("boolean", [True, False, False, True]) dataset.append_int_column("integer", range(4)) dataset.append_float_column("float", 1.0) dataset.append_string_column("string", "foo") dataset.append_categorical_column( "categorical", ["test", "train", "test", "train"] ) dataset.append_datetime_column("datetime", datetime.now()) spotlight.show("example.h5") ``` -------------------------------- ### Inspect and Detect Problematic Data Segments with Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/cv-issues This code demonstrates how to inspect errors and detect problematic data segments using Spotlight. It prepares the DataFrame, fetches a layout configuration, and then displays the data with specified image and embedding data types. ```python df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/cv_issues.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Inspect Outliers with Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/outliers-cleanlab Prepares the DataFrame for visualization by removing 'embedding' and 'probabilities' columns. It then fetches a layout configuration from a URL and uses `renumics-spotlight.show` to display the data, specifying data types for 'image' and 'embedding_reduced', and applying the fetched layout for interactive outlier inspection. ```python df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/outlier_cleanlab.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Detect and Visualize Audio Classification Dataset Issues with Python Source: https://renumics.com/docs/use-cases/audio-classification This Python script uses SliceGuard to detect issues in an audio classification dataset loaded from Hugging Face. It then visualizes these issues using Spotlight. The script requires the renumics-spotlight, sliceguard, and scikit-learn libraries. ```python # The Imports from renumics import spotlight from sliceguard import SliceGuard from sliceguard.data import from_huggingface from sklearn.metrics import accuracy_score # Load an Example Dataset as DataFrame df = from_huggingface("renumics/emodb") # DataFrame Format: # +---------------------+---------+ # | audio | emotion | # +---------------------+---------+ # | /path/to/audio1.wav | joy | # | /path/to/audio2.wav | anger | # | /path/to/audio3.wav | joy | # | ... | | # +---------------------+---------+ # Detect Issues Using sliceguard sg = SliceGuard() issues = sg.find_issues(df, features=["audio"], y="emotion", metric=accuracy_score) report_df, spotlight_data_issues, spotlight_dtypes, spotlight_layout = sg.report( no_browser=True ) # Visualize Detected Issues in Spotlight: spotlight.show( report_df, dtype=spotlight_dtypes, issues=spotlight_data_issues, layout=spotlight_layout, ) ``` -------------------------------- ### Load Hugging Face Dataset with Memory Mapping Source: https://renumics.com/docs/use-cases/motorsports-telemetry Loads a Hugging Face Dataset from disk, which is stored in Arrow format. This process utilizes memory mapping, resulting in negligible RAM usage for loading, making it highly efficient for large datasets. ```python import datasets import psutil print('memory used in MB:', psutil.virtual_memory()[3]/ 1024 ** 2) ds = datasets.Dataset.load_from_disk('f1telemetry') print('memory used in MB:', psutil.virtual_memory()[3]/ 1024 ** 2) ``` -------------------------------- ### Detect and Visualize Dataset Issues with SliceGuard and Spotlight (Python) Source: https://renumics.com/docs/use-cases/image-classification Loads an image classification dataset from Hugging Face, detects problematic data clusters using SliceGuard, and visualizes the findings with Spotlight. Requires a DataFrame with 'image' paths and 'label' columns. Outputs a report and Spotlight visualization. ```python # The Imports from renumics import spotlight from sliceguard import SliceGuard from sliceguard.data import from_huggingface from sklearn.metrics import accuracy_score # Load an Example Dataset as DataFrame df = from_huggingface("Matthijs/snacks") # DataFrame Format: # +-------------------+---------+ # | image | label | # +-------------------+---------+ # | /path/to/img1.png | popcorn | # | /path/to/img2.png | muffin | # | /path/to/img3.png | cake | # | ... | | # +-------------------+---------+ # Detect Issues Using sliceguard sg = SliceGuard() issues = sg.find_issues(df, features=["image"], y="label", metric=accuracy_score) report_df, spotlight_data_issues, spotlight_dtypes, spotlight_layout = sg.report( no_browser=True ) # Visualize Detected Issues in Spotlight: spotlight.show( report_df, dtype=spotlight_dtypes, issues=spotlight_data_issues, layout=spotlight_layout, ) ``` -------------------------------- ### Load CIFAR-100 Dataset Source: https://renumics.com/docs/data-centric-ai/playbook/huggingface-embedding Loads the CIFAR-100 dataset from the Huggingface hub and converts it into a Pandas DataFrame for further processing. This step prepares the data for embedding computation. ```python dataset = datasets.load_dataset("renumics/cifar100-enriched", split="train") df = dataset.to_pandas() ``` -------------------------------- ### Concatenate and Visualize Data with Spotlight Source: https://renumics.com/docs/use-cases/motorsports-telemetry Combines lap metadata with extracted telemetry data into a single pandas DataFrame and then visualizes this combined dataset using the renumics-spotlight library. This allows for interactive exploration of the F1 race data. ```python from renumics import spotlight import pandas as pd # Assuming df_metadata and df_telemetry are already defined from previous steps df_metadata = pd.DataFrame(laps) df = pd.concat([df_metadata, df_telemetry], axis=1) spotlight.show(df) ``` -------------------------------- ### Manually Assign Data Types for Spotlight Visualization Source: https://renumics.com/docs/loading-data/huggingface Manually assigns data types for image and categorical labels when they are ambiguous or not specified in the Hugging Face dataset. This allows Spotlight to correctly interpret and visualize specific features like images and fine labels. It takes the dataset and a dictionary of data type mappings as input. ```python label_mapping = dict(zip(ds.features['fine_label'].names, range(len(ds.features['fine_label'].names)))) spotlight.show(ds, dtype={'img': spotlight.Image, 'fine_label': spotlight.dtypes.CategoryDType(categories=label_mapping)}) ``` -------------------------------- ### Specify Categorical Data Type with Mapping Source: https://renumics.com/docs/loading-data/data-types Shows how to use the `CategoryDType` for categorical variables in RENUMICS Spotlight, including the ability to provide a label mapping. This is particularly useful for assigning numerical representations to string labels. ```python label_mapping = {'cat': 0, 'dog': 1, 'mouse': 2} spotlight.show(ds, dtype={'img': spotlight.Image, 'label': spotlight.dtypes.CategoryDType(categories=label_mapping)}) ``` -------------------------------- ### Style TextLengthLens with Tailwind CSS and twin.macro Source: https://renumics.com/docs/development/lenses Enhances the 'TextLengthLens' component by applying styling using tailwindcss utility classes through twin.macro. It adds basic styling to the displayed text length, including font size, weight, and padding. ```typescript import 'twin.macro'; import { Lens } from '../types'; const TextLengthLens: Lens = ({ value }) => { return
{`${value}`.length}
; }; ... ``` -------------------------------- ### Inspect Decision Boundary with Spotlight Source: https://renumics.com/docs/data-centric-ai/playbook/decision-boundary Visualizes the data with computed decision boundary scores using the renumics-spotlight library. It drops unnecessary columns, fetches a layout configuration, and then displays the DataFrame with specified data types and layout. ```python df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/decision_boundary_layout.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ``` -------------------------------- ### Create TextLengthLens Component in TypeScript Source: https://renumics.com/docs/development/lenses Defines a basic React Lens component named 'TextLengthLens' using TypeScript. It specifies metadata like key, data types, and dimensions. This Lens is intended to be registered and used within the RENUMICS platform. ```typescript import { Lens } from "../types"; const TextLengthLens: Lens = () => { return <>TextLengthView; }; TextLengthLens.key = "TextLengthView"; TextLengthLens.dataTypes = [ "int", "float", "bool", "str", "datetime", "Category", ]; TextLengthLens.defaultHeight = 22; TextLengthLens.minHeight = 22; TextLengthLens.maxHeight = 64; TextLengthLens.displayName = "Text Length"; export default TextLengthLens; ``` -------------------------------- ### Load F1 Race Session Data with FastF1 Source: https://renumics.com/docs/use-cases/motorsports-telemetry Loads a specific Formula 1 race session's data, including telemetry, laps, and other relevant information, using the fastf1 library. This function retrieves session details for a given year, location, and session type. ```python import fastf1 session = fastf1.get_session(2023, 'Montreal', 'Race') session.load(telemetry=True, laps=True) laps = session.laps ``` -------------------------------- ### Add PCA Embeddings to HDF5 Dataset with Spotlight Source: https://renumics.com/docs/loading-data/hdf5 Appends Principal Component Analysis (PCA) embeddings to an existing HDF5 dataset. This is done by opening the dataset in append mode ('a'). ```python from sklearn.decomposition import PCA pca_embeddings = PCA(8).fit_transform(digits.data) with spotlight.Dataset(OUTPUT_DATASET, "a") as dataset: dataset.append_embedding_column("pca", pca_embeddings) ``` -------------------------------- ### Detect and Visualize Text Classification Dataset Issues with SliceGuard and Spotlight (Python) Source: https://renumics.com/docs/use-cases/text-classification Loads a dataset from Hugging Face, detects problematic clusters using SliceGuard based on text features and labels, and visualizes these issues using Spotlight. It requires the 'renumics-spotlight', 'sliceguard', and 'scikit-learn' libraries. ```python # The Imports from renumics import spotlight from sliceguard import SliceGuard from sliceguard.data import from_huggingface from sklearn.metrics import accuracy_score # Load an Example Dataset as DataFrame df = from_huggingface("dair-ai/emotion") # DataFrame Format: # +-------+-------+ # | text | label | # +-------+-------+ # | text1 | joy | # | text2 | anger | # | text3 | joy | # | ... | | # +-------+-------+ # Detect Issues Using sliceguard sg = SliceGuard() issues = sg.find_issues(df, features=["text"], y="label", metric=accuracy_score) report_df, spotlight_data_issues, spotlight_dtypes, spotlight_layout = sg.report( no_browser=True ) # Visualize Detected Issues in Spotlight: spotlight.show( report_df, dtype=spotlight_dtypes, issues=spotlight_data_issues, layout=spotlight_layout, ) ``` -------------------------------- ### Compute and Concatenate k-Nearest Neighbor Distances Source: https://renumics.com/docs/data-centric-ai/playbook/drift-kcore Computes the k-nearest neighbor distances for the loaded CIFAR-100 dataset using the `compute_k_core_distances` function and then concatenates the resulting distances and indices back to the original DataFrame. ```python df_kcore = compute_k_core_distances(df) df = pd.concat([df, df_kcore], axis=1) ``` -------------------------------- ### Load Pandas DataFrame via Python API Source: https://renumics.com/docs/loading-data Loads an in-memory Pandas DataFrame for interactive exploration using the Spotlight Python API. This is particularly useful within notebook environments. ```python from renumics import spotlight spotlight.show(df) ``` -------------------------------- ### Inspect and Remove Leakage with Spotlight (Python) Source: https://renumics.com/docs/data-centric-ai/playbook/leakage-annoy Visualizes the data and identifies leakage using renumics-spotlight. It drops unnecessary columns, fetches a layout configuration from a URL, and then displays the DataFrame with specified data types and layout. ```python df_show = df.drop(columns=['embedding', 'probabilities']) layout_url = "https://raw.githubusercontent.com/Renumics/spotlight/playbook_initial_draft/playbook/rookie/leakage_annoy.json" response = requests.get(layout_url) layout = spotlight.layout.nodes.Layout(**json.loads(response.text)) spotlight.show(df_show, dtype={"image": spotlight.Image, "embedding_reduced": spotlight.Embedding}, layout=layout) ```