Przejdź do treści
Biblioteka skilli
Dane i analityka · Analiza

pca-dimensionality-reduction

/pca-dimensionality-reduction

Redukuje wymiarowość tabelarycznych danych liczbowych analizą PCA z parametrami z wiersza poleceń, automatycznym wyborem cech i eksportem wyników do CSV lub TXT.

Licencja
MIT
Ostatnia zmiana repozytorium
17.09.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
12
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
3
Przestarzałość

Brak sygnałów. Repozytorium zmienione 17.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Redukuje wymiarowość tabelarycznych danych liczbowych analizą PCA z parametrami z wiersza poleceń, automatycznym wyborem cech i eksportem wyników do CSV lub TXT.

Oryginalny opis (EN)

Use when performing PCA principal component dimensionality reduction on tabular numeric data. Supports command-line parameter input, automatic numeric feature selection, parameter validation, result directory creation, and CSV or TXT format result export.

Jak działa

  1. Use This Skill When
  2. Primary Command
  3. Prerequisites
  4. Core Arguments
  5. Input Requirements
  6. Minimal Workflow
  7. Outputs
  8. Interpretation Guide
  9. Read These Files When Needed
  10. Quick Examples
Sekcje z nagłówków SKILL.md, w oryginale · 179 linii, 718 słów
Podgląd SKILL.md
---
name: pca-dimensionality-reduction
description: Use when performing PCA principal component dimensionality reduction on tabular numeric data. Supports command-line parameter input, automatic numeric feature selection, parameter validation, result directory creation, and CSV or TXT format result export.
license: MIT
author: AIPOCH
---
> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)

# PCA Dimensionality Reduction Analysis

Use this skill to run principal component analysis on a tabular dataset and export explained variance, sample scores, feature loadings, and diagnostic figures.

## Use This Skill When

- You need to reduce multiple numeric variables into a smaller set of principal components.
- You need a command-line PCA workflow with parameter validation.
- You need standardized output files for downstream analysis.

## Primary Command

```bash
Rscript scripts/main.R \
  --data_file <input_file> \
  --output_dir <output_dir> \
  --feature_columns <comma_separated_numeric_columns>
```

## Prerequisites

- `Rscript` is available in the shell.
- Required R packages: `optparse`, `data.table`.
- Install missing packages with `Rscript -e 'install.packages(c("optparse", "data.table"), repos="https://cloud.r-project.org")'`.

## Core Arguments

| Argument | Required | Description |
|----------|----------|-------------|
| `--data_file` | Yes | Input data file in CSV, TXT, or TSV format |
| `--output_dir` | No | Output directory, default `./PCA_Results` |
| `--feature_columns` | No | Comma-separated numeric feature columns. Default uses all numeric columns except ID/group columns |
| `--sample_id_column` | No | Optional sample ID column. If omitted and the first column is non-numeric with unique values, it is used automatically |
| `--group_column` | No | Optional grouping column to carry into score output and score plot |
| `--n_components` | No | Maximum number of principal components to export, default `5` |
| `--center_data` | No | `true` or `false`, default `true` |
| `--scale_data` | No | `true` or `false`, default `true` |
| `--top_loadings` | No | Number of top absolute loadings to export per component, default `10` |
| `--output_format` | No | `csv` or `txt`, default `csv` |
| `--output_prefix` | No | Output filename prefix, default `pca` |

## Input Requirements

- The input file must contain at least 2 usable numeric feature columns.
- PCA is run on rows as samples and columns as features.
- Missing or non-finite values in selected feature columns are removed row-wise before analysis.
- At least 2 complete samples must remain after filtering.
- Selected feature columns must have non-zero variance after filtering.

Example input:

```csv
SampleID,Group,GeneA,GeneB,GeneC,GeneD
S01,Control,2.1,1.9,8.2,4.3
S02,Control,2.4,2.2,8.0,4.6
S03,Treated,6.1,5.7,2.8,8.1
```

## Minimal Workflow

1. Confirm the input file exists and identify the numeric feature columns for PCA.
2. Run `scripts/main.R` with the requested output directory and optional feature, ID, or group columns.
3. Check the output directory for result files under `table/`, `data/`, and `figure/`.

If you omit `--data_file`, the script exits with `SKILL_MISSING_INPUT`.

## Outputs

Expected output structure:

```text
<output_dir>/
├── table/
├── figure/
└── data/
```

Primary result files:

- `table/<output_prefix>_summary.csv`
- `table/<output_prefix>_scores.csv`
- `table/<output_prefix>_loadings.csv`
- `table/<output_prefix>_top_loadings.csv`

Figure files:

- `figure/<output_prefix>_scree_plot.png`
- `figure/<output_prefix>_score_plot.png`

Key fields include:

- `component`
- `standard_deviation`
- `variance`
- `proportion_variance`
- `cumulative_variance`
- `sample_id`
- `feature`
- `loading`

## Interpretation Guide

- Use `proportion_variance` and `cumulative_variance` to decide how many components to retain.
- Use the score table to inspect sample separation in PC space.
- Use the loading tables to identify which original variables drive each component.

## Read These Files When Needed

| Need | File |
|------|------|
| PCA method details and interpretation | `references/algorithm.md` |
| More CLI examples | `references/cli-guide.md` |
| Error diagnosis | `references/troubleshooting.md` |
| Main execution entry point | `scripts/main.R` |
| Sample test data | `tests/data/` |

## Quick Examples

Basic PCA with explicit feature columns:

```bash
Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --feature_columns GeneA,GeneB,GeneC,GeneD,GeneE \
  --output_dir tests/output_basic
```

Auto-detect all numeric columns:

```bash
Rscript scripts/main.R \
  --data_file tests/data/sample_pca_2.csv \
  --n_components 3 \
  --output_dir tests/output_numeric_only
```

Disable scaling:

```bash
Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --scale_data false \
  --output_dir tests/output_unscaled
```

## Validation

```bash
Rscript scripts/main.R --help
```

```bash
Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --feature_columns GeneA,GeneB,GeneC,GeneD,GeneE \
  --output_dir tests/validation_output
```

After running analysis, verify that `tests/validation_output/table/pca_summary.csv` exists.

## Common Errors

- `SKILL_FILE_NOT_FOUND`: Input file path is wrong or inaccessible.
- `SKILL_MISSING_COLUMNS`: A requested feature, sample ID, or group column is missing.
- `SKILL_INVALID_DATA`: Input data is malformed or unsuitable for PCA.
- `SKILL_INVALID_PARAMETER`: An argument value is invalid.
- `SKILL_INSUFFICIENT_DATA`: Too few complete samples or features remain for PCA.
- `SKILL_DEPENDENCY_MISSING`: A required R package such as `optparse` or `data.table` is unavailable.

If the issue is not obvious, read `references/troubleshooting.md`.
Pliki w paczce (12)
  • SKILL.md 6 KB
  • eval_report_pca-dimensionality-reduction_result.json 15 KB
  • references/algorithm.md 4 KB
  • references/cli-guide.md 4 KB
  • references/troubleshooting.md 4 KB
  • scripts/functions.R 8 KB
  • scripts/main.R 4 KB
  • scripts/run_analysis.R 5 KB
  • scripts/utils.R 5 KB
  • tests/data/sample_pca_1.csv 1 KB
  • tests/data/sample_pca_2.csv 3 266 KB
  • tests/data/sample_pca_3.csv 1 KB

Wersje

W bazie nie ma innych skilli o nazwie pca-dimensionality-reduction.

Migawka bazy z 13.11.2026 · wersja paczki d3099d844581 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90dimensionality-reduction
    Redukuje liczbę cech danych metodami PCA, t-SNE lub UMAP, do wizualizacji albo inżynierii cech.
  • 100sample-correlation-analysis
    Wykonuje analizę korelacji Pearsona i Spearmana między dwiema zmiennymi, z parametrami z wiersza poleceń, wykrywaniem formatu danych, walidacją i eksportem wyników do CSV lub TXT.
  • 100pca-decomposition
    Redukuje wymiarowość danych wielowymiarowych metodą PCA z rotacją varimax, gdy wiele skorelowanych zmiennych wymaga wskazania czynników ukrytych lub ograniczenia współliniowości.
  • 95bio-data-visualization-dimensionality-reduction-plots
    Tworzy i interpretuje wykresy PCA, t-SNE, UMAP i PHATE dla danych omicznych, wskazując, co każda metoda zachowuje, jak wrażliwe są hiperparametry i jakie są granice osadzeń 2D.
  • 90feature-engineering
    Tworzy, wyodrębnia i wybiera cechy wejściowe modelu, od PCA i embeddingów po kodowanie dat, opóźnienia i selekcję cech.
  • 100umap-learn
    Redukuje wymiarowość danych do 2D lub 3D metodą UMAP, do wizualizacji albo przed klasteryzacją HDBSCAN, także w modelach parametrycznych.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.