跳到正文
DEV Community· masaya oka·· 5 小時前AI 評分55

DIY AutoML 如何用 Parquet 和 DuckDB 保留原始 CSV 並重用工作副本

Keep the CSV and reuse a working copy with Parquet and DuckDB

AI 導讀

DIY AutoML 的資料流程保留並稽核原始 CSV,並可轉成 Parquet 或 DuckDB 工作檔,再抽取訓練資料。在 16 GB RAM 的 Windows PC 上,稽核並轉換 1,000,000 列合成資料至 Parquet 用時 91.1 秒;從已備妥的 Parquet 抽取 10,000 列用時 2.3 秒,兩項數值均為三次執行的中位數。

正文

On a Windows PC with 16 GB of RAM, auditing a million-row CSV and writing Parquet took 91.1 seconds. A later run took 2.3 seconds to extract 10,000 rows from the prepared file. Here is how DIY AutoML keeps track of the original CSV, the working copy, and the data that goes into training. Japanese original

Keep the original CSV and record the working copy

The workflow keeps and audits the original CSV, optionally creates a working file, then extracts and checks the training data. The audit looks at row counts, missing values, duplicate rows, and label counts. A conversion records the output row count, column types, and SHA-256 hash of the source CSV.

  • Parquet stores data by column. DIY AutoML writes it with Zstandard compression to reduce the bytes stored and read. Apache Parquet overview
  • DuckDB reads Parquet directly and can limit reads to the projected columns. If the row group statistics show that a group cannot match a filter, DuckDB can skip it. A persistent .duckdb file can also hold a table for reuse. DuckDB Parquet documentation

By default, conversion preserves the text read from each CSV field. That keeps leading zeros in identifiers, for example. The --conversion-types numeric option gives numerical types to feature columns whose values can be represented exactly. Conversion and verification rules (Japanese)

Select columns from Raisin while keeping every row

The Raisin CSV has 900 records. I extracted area (Area), perimeter (Perimeter), and the recorded variety (target). Run the PowerShell commands from the repository root. If needed, install the optional dependencies with .\.venv\Scripts\python.exe -m pip install -e ".[storage]".

$python = ".\.venv\Scripts\python.exe"
$work = "runs/dev-note-03-raisin"

& $python -X utf8 -m diy_automl audit-data --csv data/reference/raisin.csv --target target --convert parquet --convert duckdb --output "$work/source-audit"
& $python -X utf8 -m diy_automl extract-data --source "$work/source-audit/converted/data.parquet" --columns Area Perimeter target --output "$work/from-parquet"
& $python -X utf8 -m diy_automl audit-data --csv "$work/from-parquet/data.csv" --target target --output "$work/extracted-audit"

The first command creates both working files. You can request a single format by passing one --convert option. To extract from DuckDB, change the input to data.duckdb and give the extraction a fresh output directory. Set a new $work path to repeat the whole example.

For both formats, the three columns and row order matched the original CSV. The counts stayed at 450 Besni and 450 Kecimen. The extracted data.csv is the file that goes to training. The audit and extraction manifests let you trace the selected columns back to the original data. Raisin source and example (Japanese)

Measure each stage on a PC with 16 GB of RAM

I used a Windows PC with a Core i5-14400 and 16 GB of RAM. The test dataset was a synthetic one-million-row table with seven numeric features and a binary label. The audit and conversion processed all one million rows, and model comparison used 10,000 extracted rows. The Parquet benchmark used --conversion-types numeric. The CSV occupied 36.2 MB and the compressed Parquet file 18.9 MB. For each stage, elapsed time is the median of three runs. Memory is the highest peak working set of the Python process across those runs.

Stage Input or output size Time (s) Memory (MiB)
Audit CSV 1,000,000 input rows 63.3 169
Audit and convert to Parquet 1,000,000 input rows 91.1 186
Extract from the existing Parquet file 10,000 output rows 2.3 186
Compare and evaluate five models 10,000 extracted rows 10.4 195

The first conversion includes the audit and the write to Parquet. The extraction timing starts with the working file already in place. For this benchmark, two filters and a 10,000-row cap defined the extraction, and the models trained on the extracted dataset. At 100,000 rows, increasing the number of features from seven to 28 raised the audit-plus-conversion time from 7.4 to 15.6 seconds. Benchmark procedure · All timings and input sizes

For an evaluation, I start with the rows and columns needed to answer the question and generally keep every row in that scope. Around 100,000 rows or 20 columns is a starting point for considering a working file, especially if I will read or reshape the data repeatedly. The cost of training still depends on the rows, features, and models passed to that stage.

AI assistance was used to adapt the project's development notes and experiment records into this English article.

來源:DEV Community · dev.to