p2predict 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
p2predict/__init__.py ADDED
@@ -0,0 +1,88 @@
1
+ """P2Predict — parametric price benchmarking for procurement and engineering.
2
+
3
+ This is the public Python API. The same functionality is also exposed via
4
+ the ``p2predict`` and ``p2predict-train`` console scripts (installed as
5
+ entry points), and via the upcoming MCP server. Pick the surface that fits
6
+ your workflow:
7
+
8
+ • Python API (this module) — embed P2Predict in scripts, notebooks, or
9
+ agent code.
10
+ • CLI — interactive use, batch processing.
11
+ • MCP — let an AI agent call P2Predict on behalf of a procurement user.
12
+
13
+ Typical Python usage::
14
+
15
+ import pandas as pd
16
+ from p2predict import auto_train, predict_interval, explain, load_model
17
+
18
+ # Train (returns a fitted pipeline ready to predict / explain).
19
+ data = pd.read_csv("purchases.csv")
20
+ features = ["Weight", "Region", "Supplier", "Size"]
21
+ model, info = auto_train(data, target="Price", features=features)
22
+
23
+ # Save and reload.
24
+ info.save("models/my_model.model")
25
+ loaded = load_model("models/my_model.model")
26
+
27
+ # Predict on a new part.
28
+ new_part = pd.DataFrame([{"Weight": 15, "Region": "EU",
29
+ "Supplier": "A", "Size": "Standard"}])
30
+ pred = loaded.predict(new_part)
31
+
32
+ # Likely range + per-feature explanation, both axiomatically grounded.
33
+ intervals = loaded.predict_interval(new_part, coverage=0.90)
34
+ explanation = loaded.explain(new_part.iloc[[0]])
35
+ """
36
+
37
+ from p2predict.explain import (
38
+ Explanation,
39
+ explain_batch,
40
+ explain_row as explain,
41
+ top_drivers,
42
+ )
43
+ from p2predict.intervals import IntervalResult, predict_interval
44
+ from p2predict.outliers import (
45
+ POLICIES as OUTLIER_POLICIES,
46
+ apply_feature_outlier_policy,
47
+ apply_outlier_policy,
48
+ )
49
+ from p2predict.trained_model_io import (
50
+ LoadModel as load_model,
51
+ P2PREDICT_VERSION,
52
+ SaveModel as save_model,
53
+ Serialize_Trained_Model,
54
+ )
55
+ from p2predict.training import ALGORITHMS, auto_train, start_training
56
+ from p2predict.whatif import WhatIfResult, compute_whatif as what_if
57
+
58
+ __version__ = P2PREDICT_VERSION.lstrip("v")
59
+
60
+ __all__ = [
61
+ # Training entry points.
62
+ "auto_train",
63
+ "start_training",
64
+ "ALGORITHMS",
65
+ # Prediction utilities (the fitted model itself has `.predict()`; we expose
66
+ # the extras here).
67
+ "predict_interval",
68
+ "explain",
69
+ "explain_batch",
70
+ "top_drivers",
71
+ "what_if",
72
+ # Persistence.
73
+ "save_model",
74
+ "load_model",
75
+ "Serialize_Trained_Model",
76
+ # Outlier handling (also wired into the train CLI; exposed here so
77
+ # programmatic users can run the same policy from Python).
78
+ "apply_outlier_policy",
79
+ "apply_feature_outlier_policy",
80
+ "OUTLIER_POLICIES",
81
+ # Result containers — useful for typed downstream code.
82
+ "Explanation",
83
+ "IntervalResult",
84
+ "WhatIfResult",
85
+ # Version (mirrors the persisted model metadata field).
86
+ "P2PREDICT_VERSION",
87
+ "__version__",
88
+ ]
p2predict/__main__.py ADDED
@@ -0,0 +1,11 @@
1
+ """Allow ``python -m p2predict`` to invoke the predict CLI without needing
2
+ the console script entry point. Equivalent to ``p2predict`` after
3
+ ``pip install``.
4
+
5
+ For training, use ``python -m p2predict.cli.train`` or the
6
+ ``p2predict-train`` console script.
7
+ """
8
+ from p2predict.cli.predict import main
9
+
10
+ if __name__ == "__main__":
11
+ main()
@@ -0,0 +1,9 @@
1
+ """Command-line entry points for P2Predict.
2
+
3
+ These are the Click commands that ``pyproject.toml`` registers as
4
+ ``p2predict-train`` and ``p2predict`` console scripts. They are also
5
+ importable for tests::
6
+
7
+ from p2predict.cli.train import train
8
+ from p2predict.cli.predict import main
9
+ """