Spaces:
Sleeping
Sleeping
Create inspect_model.py
Browse files- inspect_model.py +51 -0
inspect_model.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# inspect_model.py
|
| 2 |
+
import joblib, pprint, importlib, sys
|
| 3 |
+
p = "best_overall_XGBoost.joblib"
|
| 4 |
+
print("Python:", sys.version)
|
| 5 |
+
try:
|
| 6 |
+
obj = joblib.load(p)
|
| 7 |
+
except Exception as e:
|
| 8 |
+
import traceback
|
| 9 |
+
traceback.print_exc()
|
| 10 |
+
raise SystemExit(1)
|
| 11 |
+
|
| 12 |
+
print("Top-level object type:", type(obj))
|
| 13 |
+
# If it's a sklearn pipeline, list steps
|
| 14 |
+
try:
|
| 15 |
+
from sklearn.pipeline import Pipeline
|
| 16 |
+
if isinstance(obj, Pipeline):
|
| 17 |
+
print("Detected sklearn Pipeline with steps:")
|
| 18 |
+
for name, step in obj.steps:
|
| 19 |
+
print(" -", name, ":", type(step))
|
| 20 |
+
else:
|
| 21 |
+
# try to detect XGBClassifier inside
|
| 22 |
+
attrs = dir(obj)
|
| 23 |
+
print("Top-level attrs preview:", attrs[:40])
|
| 24 |
+
# print some attr types if present
|
| 25 |
+
for candidate in ("estimator_", "steps", "named_steps", "booster", "get_booster", "classes_"):
|
| 26 |
+
if hasattr(obj, candidate):
|
| 27 |
+
val = getattr(obj, candidate)
|
| 28 |
+
print(f"Has {candidate}: type = {type(val)}")
|
| 29 |
+
except Exception:
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
# versions
|
| 33 |
+
def ver(name):
|
| 34 |
+
try:
|
| 35 |
+
m = importlib.import_module(name)
|
| 36 |
+
return getattr(m, "__version__", "unknown")
|
| 37 |
+
except Exception:
|
| 38 |
+
return "not installed"
|
| 39 |
+
for mod in ("xgboost", "sklearn", "numpy", "pandas"):
|
| 40 |
+
print(f"{mod}:", ver(mod))
|
| 41 |
+
|
| 42 |
+
# If pipeline, inspect nested steps types
|
| 43 |
+
try:
|
| 44 |
+
if hasattr(obj, "named_steps"):
|
| 45 |
+
print("named_steps detail:")
|
| 46 |
+
for k,v in obj.named_steps.items():
|
| 47 |
+
print(k, "->", type(v))
|
| 48 |
+
except Exception:
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
pprint.pprint(obj.__dict__ if hasattr(obj, "__dict__") else {})
|