Add files using upload-large-folder tool
Browse filesFiles changed (20)
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/_bayesnet_generate.pyAdded+105
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/_bayesnet_train.pyAdded+133
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet-c14-240000-20260501_232624.csvAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_coltypes.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pklAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/const_cols.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/gen_20260501_232624.logAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/input_snapshot.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/normalized_schema_snapshot.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/public_gate_report.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/staged_input_manifest.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/runtime_result.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/adapter_report.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/adapter_transforms_applied.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/model_input_manifest.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/staged_features.jsonAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/test.csvAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/train.csvAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/val.csvAdded+3
- syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/train_20260501_232611.logAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
import pickleimport subprocessimport sysimport warnings
import numpy as npimport pandas as pdfrom pgmpy.sampling import BayesianModelSampling
warnings.filterwarnings("ignore", category=FutureWarning)
def _ensure_cloudpickle(): try: import cloudpickle # noqa: F401 except ModuleNotFoundError: subprocess.check_call( [sys.executable, "-m", "pip", "install", "--quiet", "cloudpickle"], )
_ensure_cloudpickle()
with open("/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pkl", "rb") as f: bundle = pickle.load(f)
network = bundle["network"]inverse = bundle["inverse"]cols = bundle["column_order"]integer_columns = set(bundle.get("integer_columns") or [])full_order = bundle.get("full_column_order") or colsconst_cols = bundle.get("const_cols") or {}
num_rows = int(240000)sampler = BayesianModelSampling(network)raw = sampler.forward_sample(size=num_rows, show_progress=False)raw = raw.reset_index(drop=True)if len(raw) > num_rows: raw = raw.iloc[:num_rows]_tries = 0while len(raw) < num_rows and _tries < 64: _tries += 1 nextra = min(10000, num_rows - len(raw)) more = sampler.forward_sample(size=max(nextra, 1), show_progress=False) more = more.reset_index(drop=True) if len(more) == 0: break raw = pd.concat([raw, more], ignore_index=True) if len(raw) > num_rows: raw = raw.iloc[:num_rows]
out = pd.DataFrame(index=raw.index)rng = np.random.default_rng()
for c in cols: if c in inverse["categorical"]: levels = inverse["categorical"][c] idx = raw[c].astype(int).to_numpy() idx = np.clip(idx, 0, max(0, len(levels) - 1)) out[c] = [levels[i] for i in idx] else: edges = np.asarray(inverse["continuous"][c], dtype=float) if edges.size < 2: out[c] = 0.0 else: nbin = edges.size - 1 res = [] for k in raw[c].astype(int).to_numpy(): k = int(k) if k < 0: k = 0 if k >= nbin: k = nbin - 1 lo, hi = float(edges[k]), float(edges[k + 1]) if hi < lo: lo, hi = hi, lo v = rng.uniform(lo, hi) if c in integer_columns: v = int(round(v)) res.append(v) out[c] = res
final = pd.DataFrame(index=out.index)for c in full_order: if c in const_cols: final[c] = const_cols[c] elif c in out.columns: final[c] = out[c]
dtypes = bundle.get("original_dtypes") or {}for c, dts in dtypes.items(): if c not in final.columns: continue try: if "int" in dts: final[c] = pd.to_numeric(final[c], errors="coerce").astype("Int64") elif "float" in dts: final[c] = pd.to_numeric(final[c], errors="coerce") except Exception: pass
if len(final) != num_rows: final = final.iloc[:num_rows].copy()final = final.reset_index(drop=True)final.to_csv("/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet-c14-240000-20260501_232624.csv", index=False)print(f"[BayesNet] Generated {len(final)} rows (requested {num_rows}) -> /work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet-c14-240000-20260501_232624.csv")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
import jsonimport pickleimport subprocessimport sysimport warnings
import numpy as npimport pandas as pdfrom pgmpy.estimators import TreeSearchfrom pgmpy.models import DiscreteBayesianNetworkwarnings.filterwarnings("ignore", category=FutureWarning)
def _ensure_cloudpickle(): try: import cloudpickle # noqa: F401 except ModuleNotFoundError: subprocess.check_call( [sys.executable, "-m", "pip", "install", "--quiet", "cloudpickle"], )
_ensure_cloudpickle()
with open("/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_coltypes.json", "r", encoding="utf-8") as _f: colmeta = json.load(_f)integer_columns = set(colmeta.get("integer_columns") or [])
df = pd.read_csv("/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/train.csv")df = df.dropna(axis=1, how="all")full_column_order = list(df.columns)
const_cols = {}for col in list(df.columns): if df[col].nunique(dropna=True) <= 1: const_cols[col] = df[col].iloc[0] if len(df) > 0 else None df = df.drop(columns=[col]) print(f"[BayesNet] Dropped zero-variance column '{col}'")
const_path = "/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pkl".replace("bayesnet_model.pkl", "const_cols.json")with open(const_path, "w", encoding="utf-8") as _f: json.dump({k: str(v) for k, v in const_cols.items()}, _f)
inverse = {"categorical": {}, "continuous": {}}enc = pd.DataFrame(index=df.index)_n_samples = len(df)_n_plan = sum( 1 for e in colmeta["columns"] if str(e.get("name", "")) in df.columns)max_bins = 10max_cat_levels = 256if _n_plan > 35 or _n_samples > 200000: max_bins = 5 max_cat_levels = 64if _n_plan > 55: max_bins = 4 max_cat_levels = 32print( f"[BayesNet] max_bins={max_bins}, max_cat_levels={max_cat_levels} " f"(cols_in_df={_n_plan}, rows={_n_samples})")
for entry in colmeta["columns"]: name = entry["name"] if name not in df.columns: continue kind = entry["type"] s = df[name] if kind == "categorical": s2 = s.astype(str).fillna("__NA__") counts = s2.value_counts(dropna=False) if len(counts) > max_cat_levels: keep = set(counts.index[: max_cat_levels - 1].tolist()) s2 = s2.map(lambda x: x if x in keep else "__OTHER__") uniques = sorted(s2.dropna().unique(), key=lambda x: str(x)) mapping = {str(v): i for i, v in enumerate(uniques)} inverse["categorical"][name] = [uniques[i] for i in range(len(uniques))] enc[name] = s2.map(lambda x, m=mapping: m.get(str(x), 0)).astype(int) else: s_num = pd.to_numeric(s, errors="coerce") nu = int(s_num.nunique(dropna=True)) q = min(max_bins, max(2, nu)) if nu < 2: enc[name] = np.zeros(len(s_num), dtype=int) lo, hi = float(s_num.min()), float(s_num.max()) inverse["continuous"][name] = [lo, hi] else: try: _, bins = pd.qcut( s_num, q=q, retbins=True, duplicates="drop" ) except Exception: med = float(s_num.median()) s2 = s_num.fillna(med) _, bins = pd.qcut( s2, q=min(q, 3), retbins=True, duplicates="drop" ) bins = np.asarray(bins, dtype=float) lab = pd.cut( s_num, bins=bins, labels=False, include_lowest=True ) enc[name] = lab.fillna(0).astype(int) inverse["continuous"][name] = bins.tolist()
print(f"[BayesNet] Training on {len(enc)} rows, {len(enc.columns)} cols (encoded)")
enc_struct = encif len(enc) > 25000: enc_struct = enc.sample(n=25000, random_state=0, replace=False) print(f"[BayesNet] TreeSearch on {len(enc_struct)} rows (subsample; full n={len(enc)})")dag = TreeSearch(enc_struct).estimate(show_progress=False)for col in enc.columns: if col not in dag.nodes(): dag.add_node(col) print(f"[BayesNet] Added isolated node to DAG: {col}")network = DiscreteBayesianNetwork(dag)enc_fit = encif len(enc) > 120000: enc_fit = enc.sample(n=120000, random_state=1, replace=False) print(f"[BayesNet] fit() on {len(enc_fit)} rows (full n={len(enc)})")network.fit(enc_fit)
bundle = { "network": network, "inverse": inverse, "column_order": list(enc.columns), "full_column_order": full_column_order, "integer_columns": list(integer_columns), "original_dtypes": {c: str(df[c].dtype) for c in enc.columns}, "const_cols": const_cols,}with open("/work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pkl", "wb") as _f: pickle.dump(bundle, _f)print(f"[BayesNet] Model saved -> /work/output-Benchmark-trainonly-v1/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pkl")123version https://git-lfs.github.com/spec/v1oid sha256:aa4811bed2557c8413d8b6be76ea82df525c17a5536229f9fd03daef708f9088size 47204687123version https://git-lfs.github.com/spec/v1oid sha256:35108287569922a26c671a926ba51bbf4c60d2171dc4a80cd09c609cd31be150size 1638123version https://git-lfs.github.com/spec/v1oid sha256:074778d5a61cf4a8caad7fd4ab35106eb271707e99573b94594d2e195a19f9e6size 251724123version https://git-lfs.github.com/spec/v1oid sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8asize 2123version https://git-lfs.github.com/spec/v1oid sha256:0ef23e09cfb65a3edd951d40d3fa0a020d465424c9dde13228e08bdca140552fsize 3671123version https://git-lfs.github.com/spec/v1oid sha256:29c461771dde509c439181ee90a81352334720ad44af7ec91a4eb0b5ae6c0cbesize 1365123version https://git-lfs.github.com/spec/v1oid sha256:2e559ea7c300bee8dca838c3419b8517cfe17c153470e56a6f1c1fab72b7a10bsize 11306123version https://git-lfs.github.com/spec/v1oid sha256:465dc423a1ca46fea5f39f1b0c83b6cce2c16cdb3be3f582e8ce20fbce674981size 920123version https://git-lfs.github.com/spec/v1oid sha256:f31f76d6b51c1cd888b628d46469973a55f24df5430300ea0896a6feb7739046size 12132123version https://git-lfs.github.com/spec/v1oid sha256:01949cd54b7d6b8737ebf045c7868c29eda57e816282f54a3ad6bd4c83f1ea01size 915123version https://git-lfs.github.com/spec/v1oid sha256:8dbcb091f60c98cd0f38640ed40f379e35373ca94022efb9d8b0a33fdc65a0f4size 326123version https://git-lfs.github.com/spec/v1oid sha256:4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945size 2123version https://git-lfs.github.com/spec/v1oid sha256:e05a52ef9a3144dacabb770603e092df929e3c17ca2fdfa21d3451d9332f71c1size 12334123version https://git-lfs.github.com/spec/v1oid sha256:1c92cf6530ea76cef171daa9d723513c36aafe5dc5d8f5dfc27778090e2b0c03size 2288123version https://git-lfs.github.com/spec/v1oid sha256:617ecb620416375c67546e0fa5a8b9a3923d689bda904dc23824ea175d1f8597size 3965839123version https://git-lfs.github.com/spec/v1oid sha256:12398ccb68a2499b9c126f61b25f03c36a65f026d755e1d5ff5653e614676167size 31717079123version https://git-lfs.github.com/spec/v1oid sha256:f40dbd7bbd9e2783c24d0d12ec35a85581835d45238774eb0676de44a734fedasize 3965919123version https://git-lfs.github.com/spec/v1oid sha256:2ae9f8db5a15c6148385194ff5ab45561342d3e84aa3c61b0da51c2edd424e4csize 3856syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/_bayesnet_generate.pyAdded+105
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/_bayesnet_train.pyAdded+133
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet-c14-240000-20260501_232624.csvAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_coltypes.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/bayesnet_model.pklAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/const_cols.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/gen_20260501_232624.logAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/input_snapshot.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/normalized_schema_snapshot.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/public_gate_report.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/public_gate/staged_input_manifest.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/runtime_result.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/adapter_report.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/adapter_transforms_applied.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/bayesnet/model_input_manifest.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/staged_features.jsonAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/test.csvAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/train.csvAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/staged/public/val.csvAdded+3
syntheticSuccess/c14/bayesnet/bayesnet-c14-20260501_232608/train_20260501_232611.logAdded+3