Add files using upload-large-folder tool
Browse filesFiles changed (20)
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/_bayesnet_generate.pyAdded+105
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/_bayesnet_train.pyAdded+133
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet-c7-10368-20260429_031053.csvAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_coltypes.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_model.pklAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/const_cols.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/gen_20260429_031053.logAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/input_snapshot.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/normalized_schema_snapshot.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/public_gate_report.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/staged_input_manifest.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/runtime_result.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/adapter_report.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/adapter_transforms_applied.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/model_input_manifest.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/staged_features.jsonAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/test.csvAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/train.csvAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/val.csvAdded+3
- syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/train_20260429_031038.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/c7/bayesnet/bayesnet-c7-20260429_031038/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(10368)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/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet-c7-10368-20260429_031053.csv", index=False)print(f"[BayesNet] Generated {len(final)} rows (requested {num_rows}) -> /work/output-Benchmark-trainonly-v1/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet-c7-10368-20260429_031053.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/c7/bayesnet/bayesnet-c7-20260429_031038/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/c7/bayesnet/bayesnet-c7-20260429_031038/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/c7/bayesnet/bayesnet-c7-20260429_031038/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/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_model.pkl", "wb") as _f: pickle.dump(bundle, _f)print(f"[BayesNet] Model saved -> /work/output-Benchmark-trainonly-v1/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_model.pkl")123version https://git-lfs.github.com/spec/v1oid sha256:0ec483f732565f4c875574544cd638c236741ab73b64670c524b307e81d3762asize 847720123version https://git-lfs.github.com/spec/v1oid sha256:1cde99b1974184c5df0d3fccfade8f11ca79c02b92a5c659dc5ba44c4aefe1absize 635123version https://git-lfs.github.com/spec/v1oid sha256:342563385d822291efea03ef34858a3fa7a9c37695d1d9aa761ad616bb14bd4fsize 5680123version https://git-lfs.github.com/spec/v1oid sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8asize 2123version https://git-lfs.github.com/spec/v1oid sha256:e814c1f07c97634a205072c6af264b79105ca899b88cdfec9e2a14198170e22esize 3664123version https://git-lfs.github.com/spec/v1oid sha256:f14cece186149619179cfb8958e71a76b2fbcabb5fa6692b86991573a8d3b9d4size 1349123version https://git-lfs.github.com/spec/v1oid sha256:5dd68094a5d8fc40d291695c5aa12bc01cfe8d3a62848b4bcfd82c2e88ed19c9size 4177123version https://git-lfs.github.com/spec/v1oid sha256:f08566bcd78a9005059bf27f5f9ecf74954e2be289410d19100e900577f651easize 912123version https://git-lfs.github.com/spec/v1oid sha256:10fcaae37cee3c1cecb035645a99b986db3843874586926587633a65d1d6d835size 4993123version https://git-lfs.github.com/spec/v1oid sha256:a94883ffb73e985e889ae5e8791d48ba9a58afdf509bbb913053485e0feb65f2size 616123version https://git-lfs.github.com/spec/v1oid sha256:906add5afc393cc78cc1424a22b842aec8297d88dc80cb495fe3c24ed7249e55size 324123version https://git-lfs.github.com/spec/v1oid sha256:4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945size 2123version https://git-lfs.github.com/spec/v1oid sha256:1b718a92aed504ba5d07eb0fb848edd8d33a916bc26a39393436602dc0e3f5f7size 5193123version https://git-lfs.github.com/spec/v1oid sha256:07596ae0689482090a05749dba332eca061d863cde5d8bf7a83e8c2c92abb330size 851123version https://git-lfs.github.com/spec/v1oid sha256:2042076337d5c37c6476e6bca2bd33cb5a171450c27894534ef50ac223256058size 106030123version https://git-lfs.github.com/spec/v1oid sha256:b37f6b2ef5257f40bd826ac956749881f0f474362bdb56e8c5728ad629242e3asize 847349123version https://git-lfs.github.com/spec/v1oid sha256:eff6dec27c3740661a1ae84dea391d690dfb60342bfd5d7527b903fdd6009780size 106192123version https://git-lfs.github.com/spec/v1oid sha256:4111c669d5532e874b7f7b68b102dfe387746d6756cffa5d3ad8d7cb0ea7f147size 3741syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/_bayesnet_generate.pyAdded+105
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/_bayesnet_train.pyAdded+133
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet-c7-10368-20260429_031053.csvAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_coltypes.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/bayesnet_model.pklAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/const_cols.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/gen_20260429_031053.logAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/input_snapshot.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/normalized_schema_snapshot.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/public_gate_report.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/public_gate/staged_input_manifest.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/runtime_result.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/adapter_report.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/adapter_transforms_applied.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/bayesnet/model_input_manifest.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/staged_features.jsonAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/test.csvAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/train.csvAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/staged/public/val.csvAdded+3
syntheticSuccess/c7/bayesnet/bayesnet-c7-20260429_031038/train_20260429_031038.logAdded+3