| name | scientific-data-profiling |
| description | データプロファイリング・品質スキル。ydata-profiling 自動 EDA ・
Great Expectations データバリデーション・データ品質スコア・
型推論・相関検出・外れ値フラグ・データカタログ生成。
|
| tu_tools | [{"key":"biotools","name":"bio.tools","description":"データプロファイリングツール検索"}] |
Scientific Data Profiling
データセットの包括的プロファイリング・品質評価・
自動 EDA レポートパイプラインを提供する。
When to Use
- 新しいデータセットの全体像を素早く把握するとき
- データ品質スコアを算出して品質基準をチェックするとき
- ydata-profiling で自動 EDA レポートを生成するとき
- Great Expectations でデータバリデーションルールを定義するとき
- データカタログ (辞書) を自動生成するとき
- 相関・外れ値・欠損を一括診断するとき
Quick Start
1. ydata-profiling 自動 EDA
import numpy as np
import pandas as pd
def auto_profile_report(df, title="Data Profile Report",
minimal=False, output="profile_report.html"):
"""
ydata-profiling 自動 EDA レポート。
Parameters:
df: pd.DataFrame — 入力データ
title: str — レポートタイトル
minimal: bool — 軽量モード
output: str — 出力 HTML パス
"""
from ydata_profiling import ProfileReport
profile = ProfileReport(
df, title=title, minimal=minimal,
correlations={"pearson": {"calculate": True},
"spearman": {"calculate": True},
"kendall": {"calculate": True}},
missing_diagrams={"bar": True, "matrix": True, "heatmap": True})
profile.to_file(output)
desc = profile.get_description()
summary = {
"n_rows": len(df),
"n_cols": len(df.columns),
"n_numeric": len(df.select_dtypes(include=[np.number]).columns),
"n_categorical": len(df.select_dtypes(include=["object", "category"]).columns),
"total_missing": int(df.isnull().sum().sum()),
"missing_pct": float(df.isnull().sum().sum() / (len(df) * len(df.columns)) * 100),
"n_duplicates": int(df.duplicated().sum()),
}
print(f"Profile Report → {output}")
print(f" {summary['n_rows']} rows × {summary['n_cols']} cols, "
f"{summary['missing_pct']:.1f}% missing, "
f"{summary['n_duplicates']} duplicates")
return {"report_path": output, "summary": summary}
2. データ品質スコア
def data_quality_score(df, rules=None):
"""
データ品質スコア算出 (0-100)。
Parameters:
df: pd.DataFrame — 入力データ
rules: dict | None — カスタムルール
"""
scores = {}
completeness = 1.0 - df.isnull().sum().sum() / (len(df) * len(df.columns))
scores["completeness"] = completeness
uniqueness = 1.0 - df.duplicated().sum() / len(df) if len(df) > 0 else 1.0
scores["uniqueness"] = uniqueness
type_consistent = 0
for col in df.columns:
non_null = df[col].dropna()
if len(non_null) == 0:
type_consistent += 1
continue
try:
inferred = pd.api.types.infer_dtype(non_null, skipna=True)
if inferred not in ["mixed", "mixed-integer"]:
type_consistent += 1
except Exception:
pass
consistency = type_consistent / len(df.columns) if len(df.columns) > 0
scores[] = consistency
date_cols = df.select_dtypes(include=[]).columns
(date_cols) > :
max_date = df[date_cols[]].()
freshness =
scores[] = freshness
:
scores[] =
numeric_cols = df.select_dtypes(include=[np.number]).columns
(numeric_cols) > :
finite_rate = df[numeric_cols].apply( x: np.isfinite(x.dropna()).mean()).mean()
scores[] = (finite_rate)
:
scores[] =
weights = {: , : ,
: , : , : }
total_score = (scores[k] * weights[k] k weights) *
rule_results = []
rules:
rule_name, rule_fn rules.items():
:
passed = rule_fn(df)
rule_results.append({: rule_name, : passed})
Exception e:
rule_results.append({: rule_name, : ,
: (e)})
()
k, v scores.items():
()
{: total_score, : scores,
: rule_results}
3. Great Expectations バリデーション
def great_expectations_validate(df, expectations=None):
"""
Great Expectations スタイルのデータバリデーション。
Parameters:
df: pd.DataFrame — 入力データ
expectations: list[dict] | None — バリデーションルール
"""
if expectations is None:
expectations = _auto_generate_expectations(df)
results = []
for exp in expectations:
exp_type = exp["type"]
col = exp.get("column")
kwargs = exp.get("kwargs", {})
try:
if exp_type == "expect_column_to_exist":
success = col in df.columns
elif exp_type == "expect_column_values_to_not_be_null":
max_pct = kwargs.get("mostly", 1.0)
non_null_pct = df[col].notnull().mean()
success = non_null_pct >= max_pct
elif exp_type == "expect_column_values_to_be_between":
min_val, max_val = kwargs["min_value"], kwargs["max_value"]
vals = df[col].dropna()
success = bool((vals >= min_val).all() and (vals <= max_val).all())
elif exp_type == "expect_column_values_to_be_unique":
success = not df[col].duplicated().any()
elif exp_type == "expect_column_values_to_be_in_set":
valid_set = set(kwargs["value_set"])
success = df[col].dropna().isin(valid_set).all()
exp_type == :
success = kwargs[] <= (df) <= kwargs[]
:
success =
results.append({: exp_type, : col,
: success})
Exception e:
results.append({: exp_type, : col,
: , : (e)})
results_df = pd.DataFrame(results)
n_pass = results_df[].()
n_total = (results_df)
(
)
results_df
():
expectations = []
col df.columns:
expectations.append({: , : col})
expectations.append({
: ,
: col,
: {: }})
df[col].dtype [np.float64, np.int64]:
q1, q3 = df[col].quantile([, ])
iqr = q3 - q1
expectations.append({
: ,
: col,
: {: (q1 - * iqr),
: (q3 + * iqr)}})
expectations
パイプライン統合
[データ取得] → data-profiling → eda-correlation
(品質診断) (探索的解析)
│ ↓
missing-data-analysis anomaly-detection
(欠損補完) (異常検知)
パイプライン出力
| ファイル | 説明 | 次スキル |
|---|
profile_report.html | ydata-profiling レポート | → EDA |
quality_score.json | データ品質スコア | → 品質管理 |
validation_results.csv | バリデーション結果 | → データ修正 |
ToolUniverse 連携
| TU Key | ツール名 | 連携内容 |
|---|
biotools | bio.tools | データプロファイリングツール検索 |