stratified_sampler

Sample structured data by strata using pandas with specified sample sizes.

541|171|Updated May 3, 2018
One-click install
npx skills add https://github.com/cas-bigdatalab/piflow --skill stratified-sampler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: stratified_sampler
Source: https://github.com/cas-bigdatalab/piflow/tree/main/workspace/skills/stratified_sampler
Command: npx skills add https://github.com/cas-bigdatalab/piflow --skill stratified-sampler

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

The stratified_sampler Skill addresses the need for precise and representative sampling of structured data, particularly useful for ensuring balanced representation across categories.

Core Features & Use Cases

  • Stratified Sampling: Divides the data into strata based on specified categories and samples from each stratum to create a representative subset.
  • Supports Multiple Formats: Operates on JSONL, JSON, CSV, TSV, XLSX, and XLS data formats.
  • Use Case: For instance, when you need a balanced training dataset from customer transactions where the number of transactions per customer segment varies.

Quick Start

Execute the stratified_sampler skill by running the following command: python scripts/run_stratified_sampler.py --input data.csv --output sampled.csv --strata_field category --sample_size 100

Frequently Asked Questions about stratified_sampler

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a balanced training dataset from structured data with uneven category distributions?

Stratified sampling creates a balanced training dataset by dividing structured data into strata based on specified categories and sampling from each to ensure representative subsets. It is ideal for category-balanced data science and market research tasks.

What file formats can I use for stratified sampling on structured data?

Stratified sampling supports JSONL, JSON, CSV, TSV, XLSX, and XLS data formats. You can load any of these structured data files and define a category column to sample across strata.

How to perform stratified sampling on a CSV file using pandas?

Run the stratified sampler script via command line, specifying your input CSV, output path, strata field, and sample size. It utilizes pandas for data manipulation to extract representative subsets from your specified categories.

When do I need stratified sampling instead of random sampling for data processing?

You need stratified sampling when your data has varying category sizes and you require proportional or balanced representation across strata. It ensures that minority categories are properly represented in analysis or training subsets.

Can I specify a custom sample size for each category during stratified sampling?

The stratified sampler accepts a sample size parameter to define the number of records drawn from the strata defined in your input data. This allows you to control the volume of the representative subset generated.

Does the stratified sampler require any external dependencies to run?

The stratified sampler operates as a standalone script with no listed external dependencies. It utilizes pandas internally for data manipulation, requiring only a standard Python environment to execute the sampling process.