p2predict 0.9.0__tar.gz

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.
Files changed (56) hide show
  1. p2predict-0.9.0/LICENSE +121 -0
  2. p2predict-0.9.0/PKG-INFO +216 -0
  3. p2predict-0.9.0/README.md +170 -0
  4. p2predict-0.9.0/pyproject.toml +81 -0
  5. p2predict-0.9.0/setup.cfg +4 -0
  6. p2predict-0.9.0/src/p2predict/__init__.py +88 -0
  7. p2predict-0.9.0/src/p2predict/__main__.py +11 -0
  8. p2predict-0.9.0/src/p2predict/cli/__init__.py +9 -0
  9. p2predict-0.9.0/src/p2predict/cli/predict.py +706 -0
  10. p2predict-0.9.0/src/p2predict/cli/train.py +659 -0
  11. p2predict-0.9.0/src/p2predict/cmdline_io.py +64 -0
  12. p2predict-0.9.0/src/p2predict/explain.py +464 -0
  13. p2predict-0.9.0/src/p2predict/feature_selection.py +139 -0
  14. p2predict-0.9.0/src/p2predict/hpo_training.py +44 -0
  15. p2predict-0.9.0/src/p2predict/input_checks.py +59 -0
  16. p2predict-0.9.0/src/p2predict/intervals.py +317 -0
  17. p2predict-0.9.0/src/p2predict/json_output.py +225 -0
  18. p2predict-0.9.0/src/p2predict/mcp/__init__.py +1 -0
  19. p2predict-0.9.0/src/p2predict/mcp/__main__.py +3 -0
  20. p2predict-0.9.0/src/p2predict/mcp/conversions.py +44 -0
  21. p2predict-0.9.0/src/p2predict/mcp/registry.py +149 -0
  22. p2predict-0.9.0/src/p2predict/mcp/server.py +1258 -0
  23. p2predict-0.9.0/src/p2predict/model_evals.py +36 -0
  24. p2predict-0.9.0/src/p2predict/model_utils.py +235 -0
  25. p2predict-0.9.0/src/p2predict/outliers.py +234 -0
  26. p2predict-0.9.0/src/p2predict/plotting.py +499 -0
  27. p2predict-0.9.0/src/p2predict/prepare_data.py +48 -0
  28. p2predict-0.9.0/src/p2predict/preprocessing.py +130 -0
  29. p2predict-0.9.0/src/p2predict/quality.py +457 -0
  30. p2predict-0.9.0/src/p2predict/trained_model_io.py +64 -0
  31. p2predict-0.9.0/src/p2predict/training.py +270 -0
  32. p2predict-0.9.0/src/p2predict/ui_console.py +36 -0
  33. p2predict-0.9.0/src/p2predict/whatif.py +269 -0
  34. p2predict-0.9.0/src/p2predict.egg-info/PKG-INFO +216 -0
  35. p2predict-0.9.0/src/p2predict.egg-info/SOURCES.txt +54 -0
  36. p2predict-0.9.0/src/p2predict.egg-info/dependency_links.txt +1 -0
  37. p2predict-0.9.0/src/p2predict.egg-info/entry_points.txt +4 -0
  38. p2predict-0.9.0/src/p2predict.egg-info/requires.txt +20 -0
  39. p2predict-0.9.0/src/p2predict.egg-info/top_level.txt +1 -0
  40. p2predict-0.9.0/tests/test_benchmarks.py +198 -0
  41. p2predict-0.9.0/tests/test_cli.py +415 -0
  42. p2predict-0.9.0/tests/test_explain.py +387 -0
  43. p2predict-0.9.0/tests/test_feature_selection.py +43 -0
  44. p2predict-0.9.0/tests/test_feature_selection_leakage.py +55 -0
  45. p2predict-0.9.0/tests/test_input_checks.py +40 -0
  46. p2predict-0.9.0/tests/test_intervals.py +376 -0
  47. p2predict-0.9.0/tests/test_io_and_evals.py +79 -0
  48. p2predict-0.9.0/tests/test_json_output.py +380 -0
  49. p2predict-0.9.0/tests/test_mcp.py +605 -0
  50. p2predict-0.9.0/tests/test_outliers.py +207 -0
  51. p2predict-0.9.0/tests/test_plotting.py +251 -0
  52. p2predict-0.9.0/tests/test_prepare_data.py +34 -0
  53. p2predict-0.9.0/tests/test_preprocessing.py +123 -0
  54. p2predict-0.9.0/tests/test_quality.py +212 -0
  55. p2predict-0.9.0/tests/test_training.py +248 -0
  56. p2predict-0.9.0/tests/test_whatif.py +374 -0
@@ -0,0 +1,121 @@
1
+ PolyForm Noncommercial License 1.0.0
2
+
3
+ Copyright (c) 2023 Ahmed K. Hafsi
4
+
5
+ https://polyformproject.org/licenses/noncommercial/1.0.0
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as
10
+ both strict obligations and conditions to all your licenses.
11
+
12
+ ## Copyright License
13
+
14
+ The licensor grants you a copyright license for the software to do
15
+ everything you might do with the software that would otherwise infringe
16
+ the licensor's copyright in it for any permitted purpose. However, you
17
+ may only distribute the software according to Distribution License and
18
+ make changes or new works based on the software according to Changes and
19
+ New Works License.
20
+
21
+ ## Distribution License
22
+
23
+ The licensor grants you an additional copyright license to distribute
24
+ copies of the software. Your license to distribute covers distributing
25
+ the software with changes and new works permitted by Changes and New
26
+ Works License.
27
+
28
+ ## Notices
29
+
30
+ You must ensure that anyone who gets a copy of any part of the software
31
+ from you also gets a copy of these terms or the URL for them above, as
32
+ well as copies of any plain-text lines beginning with "Required Notice:"
33
+ that the licensor provided with the software. For example:
34
+
35
+ Required Notice: Copyright 2023 Ahmed K. Hafsi
36
+
37
+ ## Changes and New Works License
38
+
39
+ The licensor grants you an additional copyright license to make changes
40
+ and new works based on the software for any permitted purpose.
41
+
42
+ ## Patent License
43
+
44
+ The licensor grants you a patent license for the software that covers
45
+ patent claims the licensor can license, or becomes able to license, that
46
+ you would infringe by using the software.
47
+
48
+ ## Noncommercial Purposes
49
+
50
+ Any noncommercial purpose is a permitted purpose.
51
+
52
+ ## Personal Uses
53
+
54
+ Personal use for research, experiment, and testing for the benefit of
55
+ public knowledge, personal study, private entertainment, hobby projects,
56
+ amateur pursuits, or religious observance, without any anticipated
57
+ commercial application, is use for a noncommercial purpose.
58
+
59
+ ## Noncommercial Organizations
60
+
61
+ Use by any charitable organization, educational institution, public
62
+ research organization, public safety or health organization,
63
+ environmental protection organization, or government institution is use
64
+ for a noncommercial purpose regardless of the source of funding or
65
+ obligations resulting from the funding.
66
+
67
+ ## Fair Use
68
+
69
+ You may have "fair use" rights for the software under the law. These
70
+ terms do not limit them.
71
+
72
+ ## No Other Rights
73
+
74
+ These terms do not allow you to sublicense or transfer any of your
75
+ licenses to anyone else, or prevent the licensor from granting licenses
76
+ to anyone else. These terms do not imply any other licenses.
77
+
78
+ ## Patent Defense
79
+
80
+ If you make any written claim that the software infringes or contributes
81
+ to infringement of any patent, your patent license for the software
82
+ granted under these terms ends immediately. If your employer makes such a
83
+ claim, your patent license ends immediately for work on behalf of your
84
+ employer.
85
+
86
+ ## Violations
87
+
88
+ The first time you are notified in writing that you have violated any of
89
+ these terms, or done anything with the software not covered by your
90
+ licenses, the violation is automatically cured if you come into
91
+ compliance within 32 days after receiving notice.
92
+
93
+ ## No Liability
94
+
95
+ As far as the law allows, the software comes as is, without any warranty
96
+ or condition, and the licensor will not be liable to you for any damages
97
+ arising out of these terms or the use or nature of the software, under
98
+ any kind of legal claim.
99
+
100
+ ## Definitions
101
+
102
+ The "licensor" is the individual or entity offering these terms, and the
103
+ "software" is the software the licensor makes available under these
104
+ terms.
105
+
106
+ "You" refers to the individual or entity agreeing to these terms.
107
+
108
+ "Your company" is any legal entity, sole proprietorship, or other kind
109
+ of organization that you work for, plus all organizations that have
110
+ control over, are under the control of, or are under common control with
111
+ that organization. "Control" means ownership of substantially all the
112
+ assets of an entity, or the power to direct its management and legal
113
+ affairs.
114
+
115
+ "Your licenses" are all the licenses granted to you for the software
116
+ under these terms.
117
+
118
+ "Use" means anything you do with the software requiring one of your
119
+ licenses.
120
+
121
+ "Trademark" means trademarks, service marks, and similar rights.
@@ -0,0 +1,216 @@
1
+ Metadata-Version: 2.4
2
+ Name: p2predict
3
+ Version: 0.9.0
4
+ Summary: Parametric price benchmarking for procurement and engineering — exact SHAP attribution, conformal likely-range intervals, what-if comparisons, all CLI- and agent-callable.
5
+ Author: Ahmed Khalil Hafsi
6
+ License-Expression: PolyForm-Noncommercial-1.0.0
7
+ Project-URL: Homepage, https://github.com/ahmed-khalil-hafsi/P2Predict
8
+ Project-URL: Repository, https://github.com/ahmed-khalil-hafsi/P2Predict
9
+ Project-URL: Issues, https://github.com/ahmed-khalil-hafsi/P2Predict/issues
10
+ Project-URL: Changelog, https://github.com/ahmed-khalil-hafsi/P2Predict/blob/main/CHANGELOG.md
11
+ Project-URL: Roadmap, https://github.com/ahmed-khalil-hafsi/P2Predict/blob/main/ROADMAP.md
12
+ Keywords: procurement,price-prediction,parametric-estimating,should-cost,shap,conformal-prediction,machine-learning,scikit-learn,xgboost,mcp
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Financial and Insurance Industry
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: joblib>=1.2
29
+ Requires-Dist: matplotlib>=3.7
30
+ Requires-Dist: mpld3>=0.5
31
+ Requires-Dist: numpy>=1.24
32
+ Requires-Dist: pandas<3.0,>=2.0
33
+ Requires-Dist: rich>=13.3
34
+ Requires-Dist: scikit-learn>=1.5
35
+ Requires-Dist: scipy>=1.10
36
+ Requires-Dist: seaborn>=0.12
37
+ Requires-Dist: xgboost>=1.7
38
+ Requires-Dist: halo>=0.0.31
39
+ Requires-Dist: questionary>=1.10
40
+ Requires-Dist: shap<0.50,>=0.44
41
+ Provides-Extra: mcp
42
+ Requires-Dist: mcp>=1.0; extra == "mcp"
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest>=7; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ <div align="center">
48
+
49
+ # P2Predict
50
+
51
+ ### The right price is already in your data.
52
+
53
+ **P2Predict turns your purchasing history into a price model your team can talk to. Ask what a part should cost, why, and how sure the answer is, in plain language, through the AI agent you already use.**
54
+
55
+ ![Works with any AI agent](https://img.shields.io/badge/works%20with-any%20AI%20agent-6E56CF) &nbsp;
56
+ ![Local first](https://img.shields.io/badge/local--first-your%20data%20never%20leaves-1F8A4C) &nbsp;
57
+ ![Built for procurement](https://img.shields.io/badge/built%20for-procurement-0B6BCB) &nbsp;
58
+ ![License](https://img.shields.io/badge/license-PolyForm%20Noncommercial-555)
59
+
60
+ ![P2Predict MCP Demo](./documentation/p2predict_mcp_demo.gif)
61
+
62
+ </div>
63
+
64
+ ## The problem
65
+
66
+ Most of what a part costs is decided upstream, in a design review procurement never sees. An engineer tightens a tolerance beyond what the application needs, or locks the part to a single supplier, and the cost rides downstream with no number attached. By the time the BOM reaches procurement, the expensive decisions are frozen and all that is left to negotiate is the rounding.
67
+
68
+ Then the quote arrives. The supplier knows their cost to the cent; you have last year's PO and a few days to respond. Multiply that across every line you buy and the leaks look the same everywhere: premiums no one benchmarked, specs no one costed, a number you cannot defend when finance asks where the savings went.
69
+
70
+ The answers are already in your purchase history. Nobody has had the time to dig them out.
71
+
72
+ ## What P2Predict does
73
+
74
+ P2Predict learns from your own purchasing data what drives the price of a part: supplier, material, size, spec, region. Then it gives your team a defensible target for any new or proposed part. Your category managers ask in plain English. The answer comes back grounded in what you have actually paid.
75
+
76
+ It runs on your machine, on your data, through any AI agent your team already uses. Nothing is uploaded. No vendor catalog, no cloud, no per-seat data-sharing.
77
+
78
+ ## What it is, and what it isn't
79
+
80
+ P2Predict is **parametric price prediction**. It learns the fundamental pricing structure in your historical buying data and benchmarks any part against it, the ones you are about to buy and the ones you already do. Being precise about that is the whole point, so here is the honest scope.
81
+
82
+ **What it does**
83
+
84
+ - Learns from the prices you have actually paid and predicts what a similar part should cost.
85
+ - Attributes that predicted price to each spec and to the supplier, so you can see what is moving the number.
86
+ - Puts a calibrated likely-range on every estimate and flags where the data is too thin to trust.
87
+ - Improves as you give it more of your own purchase history.
88
+
89
+ **What it does not do**
90
+
91
+ - **It is not a should-cost tool.** It does not build a part up from raw material, labor, and machine time, and it cannot tell you a supplier's true cost or margin.
92
+ - It only knows what your data has shown it. Ask about a part unlike anything in your history and it will widen the range or tell you to get a quote rather than guess.
93
+ - The per-spec breakdown shows what is *associated* with price in your data. It is a read on your market, not a causal or engineering model of why a part costs what it does.
94
+ - It does not invent data. No relevant history, no model.
95
+
96
+ ## The conversations it changes
97
+
98
+ This is where P2Predict earns its keep. Every one of these is a real question your team can now answer in seconds, with a number and the confidence behind it.
99
+
100
+ ### "Is this quote fair?"
101
+
102
+ Your category manager drops the quote on the agent.
103
+
104
+ > **Category manager:** *"Supplier quotes $14.20 for this part. What should it cost?"*
105
+ >
106
+ > **P2Predict:** *"$12.40. Nine times in ten the real price lands between $10.80 and $13.90. This quote is running about 15% high."*
107
+
108
+ Your category manager now knows exactly where they can push back, with real data behind it.
109
+
110
+ ### When the supplier pushes back: "Are you sure that's the right price?"
111
+
112
+ This is where most negotiations stall. Now you have an answer. Ask for the breakdown.
113
+
114
+ > **Category manager:** *"Why $12.40? Break it down."*
115
+ >
116
+ > **P2Predict:** *"Supplier choice +$0.85, rush delivery +$1.20, tighter tolerance +$0.42, size +$0.40."*
117
+
118
+ Now you argue the components line by line: *"We agreed standard lead time. Take the $1.20 rush charge off and we're aligned."* A line item is hard to wave away.
119
+
120
+ ### "What if we switch supplier?"
121
+
122
+ Hold the spec fixed, swap the supplier, read the delta.
123
+
124
+ > **Category manager:** *"What happens if we move this 16-cell pack monitor from Supplier A to Supplier B?"*
125
+ >
126
+ > **P2Predict:** *"Down 37.7%, about $2.07 a unit, with the per-feature breakdown to back it up."*
127
+
128
+ More targeted RFQs, and a faster sourcing decision. That number is your lever in the room.
129
+
130
+ ### In the design review: "Is this feature worth it?"
131
+
132
+ Engineering proposes a tighter tolerance. Before it gets locked in, price it.
133
+
134
+ > **Engineer:** *"We want to go from ±0.1mm to ±0.05mm."*
135
+ >
136
+ > **Category manager to the agent:** *"What does that do to cost?"*
137
+ >
138
+ > **P2Predict:** *"+$0.42 a unit, +18%, likely range $0.30 to $0.55."*
139
+
140
+ Now the conversation is *"is 18% worth this requirement?"*, a priced trade-off the room can settle on numbers.
141
+
142
+ ### In the cost-down workshop: "What is the design paying for that it doesn't need?"
143
+
144
+ Walk in with every spec priced. Which features carry real cost, which premiums are negotiable, where the design is paying for something the application never uses. Backed by your own data, with a confidence level on every finding.
145
+
146
+ ### RFQ triage: "Which of these 200 lines deserve a call?"
147
+
148
+ Drop the whole RFQ on the agent. Every line gets a target and a range. The eight to fifteen lines that fall outside their range are the ones worth a phone call. The rest are routine. Your team spends the afternoon on what actually moves the number.
149
+
150
+ ## It tells you how much to trust the number
151
+
152
+ Most tools hand you a number and walk away. P2Predict hands you the number **and tells you how confident to be in it**, per part, in dollars. That honesty is the whole point: a confident-but-wrong benchmark loses you credibility the moment a supplier checks it.
153
+
154
+ ![Honest confidence ranges, per part](./case-studies/battery-management-ics/assets/intervals_comparison.png)
155
+
156
+ Three real parts, three different confidence ranges. The model is tight on the part it knows well and openly uncertain on the ones it doesn't. A narrow range means negotiate hard. A wide one means get a quote first. Your category manager always knows which.
157
+
158
+ - **A confidence range on every estimate.** "$12.40, and nine times in ten the real price lands between $10.80 and $13.90."
159
+ - **An honest map of where the model is strong and where it is thin.** P2Predict flags which parts of your category it can benchmark with confidence and which need a real quote, so nobody negotiates off a number the data can't support.
160
+ - **A reason for every number.** Every estimate breaks down into what each spec and the supplier contribute, so you argue the components line by line.
161
+
162
+ ## See what actually drives the price
163
+
164
+ Point P2Predict at a category and it shows you the levers. These charts come straight out of the [Battery Management ICs case study](case-studies/battery-management-ics/), built on public catalog data anyone can reproduce.
165
+
166
+ **Supplier choice is the biggest lever on the board.** Same single-cell chip, identical spec, sorted by who makes it:
167
+
168
+ ![Supplier premium on an identical part](./case-studies/battery-management-ics/assets/manufacturer_premium.png)
169
+
170
+ The premium supplier is priced at roughly four times the value option for the same part. That is a number you take into a negotiation, backed by your own data.
171
+
172
+ **Every estimate breaks down spec by spec.** Ask why a part is priced the way it is and you get the full breakdown:
173
+
174
+ ![Per-feature dollar breakdown for one part](./case-studies/battery-management-ics/assets/ev_bms_attribution.png)
175
+
176
+ Package size, supplier premium, multi-cell architecture: each one in dollars, each one adding up exactly to the predicted price. This is what lets your category manager say *"I know what I'm paying for, and here's the line I want to cut."*
177
+
178
+ ## How it fits your stack
179
+
180
+ **You don't use P2Predict; your agent does.** It speaks to **any AI agent** through a standard connector — Claude, GPT, or a local model — so your category managers never learn a new tool. They ask the assistant they already use, and it runs the analysis for them. This is agentic-first: there is no dashboard and no app, the interface is the agent you already have.
181
+
182
+ Everything runs **on your own machine**. Your purchasing data is your most sensitive commercial asset, so P2Predict never uploads it and no third party trains on it. Pair it with a local model to keep the whole loop offline, or with a cloud agent if you prefer; either way your raw spend stays put, with no data-residency conversation to have with legal.
183
+
184
+ It complements should-cost tools, it does not replace them. Bottom-up should-costing builds a part up from material, labor, and machine time to estimate what it *should cost to make*. P2Predict does not do that and is not trying to. It answers the other question every category manager actually asks: *what has the market charged us for parts like this, and what should we expect to pay for the next one?*
185
+
186
+ ## Proof on public data
187
+
188
+ Three worked case studies, each reproducible end to end on data anyone can download:
189
+
190
+ - **[Battery Management ICs](case-studies/battery-management-ics/):** the closest thing to a real procurement job. A small, realistic parts slice, a supplier-premium lever you can quote, and an honest read on where the model is strong and where it needs a real quote.
191
+ - **[Used vehicles](case-studies/used-cars/):** the easy-to-follow walkthrough on prices that span orders of magnitude.
192
+ - **[Aerospace fasteners](case-studies/aerospace-fasteners/):** the honesty story. How P2Predict shows you when the data itself sets the limit, so you stop chasing accuracy the data can't give.
193
+
194
+ Each one leads with results, shows where to trust them, and points to exactly where every number comes from.
195
+
196
+ ## Who built it
197
+
198
+ P2Predict is built and maintained by **[Ahmed K. Hafsi](https://ahmedhafsi.com)**, Senior Manager of Negotiation Excellence at Infineon, where he leads negotiation strategy across automotive, semiconductor, consumer, and chemicals categories in Asia-Pacific. He built and led Dyson's global Negotiation Excellence capability and advised on negotiation and applied game theory at TWS Partners in Munich and London. He trained as an engineer at the Karlsruhe Institute of Technology and works across three continents in four languages.
199
+
200
+ P2Predict comes out of that work: the tools a procurement team actually needs to walk into a negotiation knowing its number and its leverage. More on his approach to negotiation, pricing, and game theory at **[ahmedhafsi.com](https://ahmedhafsi.com)**.
201
+
202
+ ## Try it / set it up
203
+
204
+ - **Set it up with your agent:** see **[INSTALL.md](INSTALL.md)** to install, connect your AI assistant, and point it at your data.
205
+ - **How it works under the hood:** the models, the math, the full reference live in **[TECHNICAL.md](TECHNICAL.md)**.
206
+
207
+ ## Licensing
208
+
209
+ Source-available under the [PolyForm Noncommercial License 1.0.0](LICENSE).
210
+
211
+ - **Free for internal use:** use P2Predict inside your own organization at no cost.
212
+ - **Commercial use requires a license:** deploying for clients, embedding it in a paid service, or consulting engagements.
213
+
214
+ For a commercial license, a partnership, or to share a procurement dataset, reach out: **[ahmedhafsi.com/contact](https://ahmedhafsi.com/contact/)**.
215
+
216
+ © Ahmed K. Hafsi. P2Predict is a copyrighted work; all rights reserved except as granted under the license above.
@@ -0,0 +1,170 @@
1
+ <div align="center">
2
+
3
+ # P2Predict
4
+
5
+ ### The right price is already in your data.
6
+
7
+ **P2Predict turns your purchasing history into a price model your team can talk to. Ask what a part should cost, why, and how sure the answer is, in plain language, through the AI agent you already use.**
8
+
9
+ ![Works with any AI agent](https://img.shields.io/badge/works%20with-any%20AI%20agent-6E56CF) &nbsp;
10
+ ![Local first](https://img.shields.io/badge/local--first-your%20data%20never%20leaves-1F8A4C) &nbsp;
11
+ ![Built for procurement](https://img.shields.io/badge/built%20for-procurement-0B6BCB) &nbsp;
12
+ ![License](https://img.shields.io/badge/license-PolyForm%20Noncommercial-555)
13
+
14
+ ![P2Predict MCP Demo](./documentation/p2predict_mcp_demo.gif)
15
+
16
+ </div>
17
+
18
+ ## The problem
19
+
20
+ Most of what a part costs is decided upstream, in a design review procurement never sees. An engineer tightens a tolerance beyond what the application needs, or locks the part to a single supplier, and the cost rides downstream with no number attached. By the time the BOM reaches procurement, the expensive decisions are frozen and all that is left to negotiate is the rounding.
21
+
22
+ Then the quote arrives. The supplier knows their cost to the cent; you have last year's PO and a few days to respond. Multiply that across every line you buy and the leaks look the same everywhere: premiums no one benchmarked, specs no one costed, a number you cannot defend when finance asks where the savings went.
23
+
24
+ The answers are already in your purchase history. Nobody has had the time to dig them out.
25
+
26
+ ## What P2Predict does
27
+
28
+ P2Predict learns from your own purchasing data what drives the price of a part: supplier, material, size, spec, region. Then it gives your team a defensible target for any new or proposed part. Your category managers ask in plain English. The answer comes back grounded in what you have actually paid.
29
+
30
+ It runs on your machine, on your data, through any AI agent your team already uses. Nothing is uploaded. No vendor catalog, no cloud, no per-seat data-sharing.
31
+
32
+ ## What it is, and what it isn't
33
+
34
+ P2Predict is **parametric price prediction**. It learns the fundamental pricing structure in your historical buying data and benchmarks any part against it, the ones you are about to buy and the ones you already do. Being precise about that is the whole point, so here is the honest scope.
35
+
36
+ **What it does**
37
+
38
+ - Learns from the prices you have actually paid and predicts what a similar part should cost.
39
+ - Attributes that predicted price to each spec and to the supplier, so you can see what is moving the number.
40
+ - Puts a calibrated likely-range on every estimate and flags where the data is too thin to trust.
41
+ - Improves as you give it more of your own purchase history.
42
+
43
+ **What it does not do**
44
+
45
+ - **It is not a should-cost tool.** It does not build a part up from raw material, labor, and machine time, and it cannot tell you a supplier's true cost or margin.
46
+ - It only knows what your data has shown it. Ask about a part unlike anything in your history and it will widen the range or tell you to get a quote rather than guess.
47
+ - The per-spec breakdown shows what is *associated* with price in your data. It is a read on your market, not a causal or engineering model of why a part costs what it does.
48
+ - It does not invent data. No relevant history, no model.
49
+
50
+ ## The conversations it changes
51
+
52
+ This is where P2Predict earns its keep. Every one of these is a real question your team can now answer in seconds, with a number and the confidence behind it.
53
+
54
+ ### "Is this quote fair?"
55
+
56
+ Your category manager drops the quote on the agent.
57
+
58
+ > **Category manager:** *"Supplier quotes $14.20 for this part. What should it cost?"*
59
+ >
60
+ > **P2Predict:** *"$12.40. Nine times in ten the real price lands between $10.80 and $13.90. This quote is running about 15% high."*
61
+
62
+ Your category manager now knows exactly where they can push back, with real data behind it.
63
+
64
+ ### When the supplier pushes back: "Are you sure that's the right price?"
65
+
66
+ This is where most negotiations stall. Now you have an answer. Ask for the breakdown.
67
+
68
+ > **Category manager:** *"Why $12.40? Break it down."*
69
+ >
70
+ > **P2Predict:** *"Supplier choice +$0.85, rush delivery +$1.20, tighter tolerance +$0.42, size +$0.40."*
71
+
72
+ Now you argue the components line by line: *"We agreed standard lead time. Take the $1.20 rush charge off and we're aligned."* A line item is hard to wave away.
73
+
74
+ ### "What if we switch supplier?"
75
+
76
+ Hold the spec fixed, swap the supplier, read the delta.
77
+
78
+ > **Category manager:** *"What happens if we move this 16-cell pack monitor from Supplier A to Supplier B?"*
79
+ >
80
+ > **P2Predict:** *"Down 37.7%, about $2.07 a unit, with the per-feature breakdown to back it up."*
81
+
82
+ More targeted RFQs, and a faster sourcing decision. That number is your lever in the room.
83
+
84
+ ### In the design review: "Is this feature worth it?"
85
+
86
+ Engineering proposes a tighter tolerance. Before it gets locked in, price it.
87
+
88
+ > **Engineer:** *"We want to go from ±0.1mm to ±0.05mm."*
89
+ >
90
+ > **Category manager to the agent:** *"What does that do to cost?"*
91
+ >
92
+ > **P2Predict:** *"+$0.42 a unit, +18%, likely range $0.30 to $0.55."*
93
+
94
+ Now the conversation is *"is 18% worth this requirement?"*, a priced trade-off the room can settle on numbers.
95
+
96
+ ### In the cost-down workshop: "What is the design paying for that it doesn't need?"
97
+
98
+ Walk in with every spec priced. Which features carry real cost, which premiums are negotiable, where the design is paying for something the application never uses. Backed by your own data, with a confidence level on every finding.
99
+
100
+ ### RFQ triage: "Which of these 200 lines deserve a call?"
101
+
102
+ Drop the whole RFQ on the agent. Every line gets a target and a range. The eight to fifteen lines that fall outside their range are the ones worth a phone call. The rest are routine. Your team spends the afternoon on what actually moves the number.
103
+
104
+ ## It tells you how much to trust the number
105
+
106
+ Most tools hand you a number and walk away. P2Predict hands you the number **and tells you how confident to be in it**, per part, in dollars. That honesty is the whole point: a confident-but-wrong benchmark loses you credibility the moment a supplier checks it.
107
+
108
+ ![Honest confidence ranges, per part](./case-studies/battery-management-ics/assets/intervals_comparison.png)
109
+
110
+ Three real parts, three different confidence ranges. The model is tight on the part it knows well and openly uncertain on the ones it doesn't. A narrow range means negotiate hard. A wide one means get a quote first. Your category manager always knows which.
111
+
112
+ - **A confidence range on every estimate.** "$12.40, and nine times in ten the real price lands between $10.80 and $13.90."
113
+ - **An honest map of where the model is strong and where it is thin.** P2Predict flags which parts of your category it can benchmark with confidence and which need a real quote, so nobody negotiates off a number the data can't support.
114
+ - **A reason for every number.** Every estimate breaks down into what each spec and the supplier contribute, so you argue the components line by line.
115
+
116
+ ## See what actually drives the price
117
+
118
+ Point P2Predict at a category and it shows you the levers. These charts come straight out of the [Battery Management ICs case study](case-studies/battery-management-ics/), built on public catalog data anyone can reproduce.
119
+
120
+ **Supplier choice is the biggest lever on the board.** Same single-cell chip, identical spec, sorted by who makes it:
121
+
122
+ ![Supplier premium on an identical part](./case-studies/battery-management-ics/assets/manufacturer_premium.png)
123
+
124
+ The premium supplier is priced at roughly four times the value option for the same part. That is a number you take into a negotiation, backed by your own data.
125
+
126
+ **Every estimate breaks down spec by spec.** Ask why a part is priced the way it is and you get the full breakdown:
127
+
128
+ ![Per-feature dollar breakdown for one part](./case-studies/battery-management-ics/assets/ev_bms_attribution.png)
129
+
130
+ Package size, supplier premium, multi-cell architecture: each one in dollars, each one adding up exactly to the predicted price. This is what lets your category manager say *"I know what I'm paying for, and here's the line I want to cut."*
131
+
132
+ ## How it fits your stack
133
+
134
+ **You don't use P2Predict; your agent does.** It speaks to **any AI agent** through a standard connector — Claude, GPT, or a local model — so your category managers never learn a new tool. They ask the assistant they already use, and it runs the analysis for them. This is agentic-first: there is no dashboard and no app, the interface is the agent you already have.
135
+
136
+ Everything runs **on your own machine**. Your purchasing data is your most sensitive commercial asset, so P2Predict never uploads it and no third party trains on it. Pair it with a local model to keep the whole loop offline, or with a cloud agent if you prefer; either way your raw spend stays put, with no data-residency conversation to have with legal.
137
+
138
+ It complements should-cost tools, it does not replace them. Bottom-up should-costing builds a part up from material, labor, and machine time to estimate what it *should cost to make*. P2Predict does not do that and is not trying to. It answers the other question every category manager actually asks: *what has the market charged us for parts like this, and what should we expect to pay for the next one?*
139
+
140
+ ## Proof on public data
141
+
142
+ Three worked case studies, each reproducible end to end on data anyone can download:
143
+
144
+ - **[Battery Management ICs](case-studies/battery-management-ics/):** the closest thing to a real procurement job. A small, realistic parts slice, a supplier-premium lever you can quote, and an honest read on where the model is strong and where it needs a real quote.
145
+ - **[Used vehicles](case-studies/used-cars/):** the easy-to-follow walkthrough on prices that span orders of magnitude.
146
+ - **[Aerospace fasteners](case-studies/aerospace-fasteners/):** the honesty story. How P2Predict shows you when the data itself sets the limit, so you stop chasing accuracy the data can't give.
147
+
148
+ Each one leads with results, shows where to trust them, and points to exactly where every number comes from.
149
+
150
+ ## Who built it
151
+
152
+ P2Predict is built and maintained by **[Ahmed K. Hafsi](https://ahmedhafsi.com)**, Senior Manager of Negotiation Excellence at Infineon, where he leads negotiation strategy across automotive, semiconductor, consumer, and chemicals categories in Asia-Pacific. He built and led Dyson's global Negotiation Excellence capability and advised on negotiation and applied game theory at TWS Partners in Munich and London. He trained as an engineer at the Karlsruhe Institute of Technology and works across three continents in four languages.
153
+
154
+ P2Predict comes out of that work: the tools a procurement team actually needs to walk into a negotiation knowing its number and its leverage. More on his approach to negotiation, pricing, and game theory at **[ahmedhafsi.com](https://ahmedhafsi.com)**.
155
+
156
+ ## Try it / set it up
157
+
158
+ - **Set it up with your agent:** see **[INSTALL.md](INSTALL.md)** to install, connect your AI assistant, and point it at your data.
159
+ - **How it works under the hood:** the models, the math, the full reference live in **[TECHNICAL.md](TECHNICAL.md)**.
160
+
161
+ ## Licensing
162
+
163
+ Source-available under the [PolyForm Noncommercial License 1.0.0](LICENSE).
164
+
165
+ - **Free for internal use:** use P2Predict inside your own organization at no cost.
166
+ - **Commercial use requires a license:** deploying for clients, embedding it in a paid service, or consulting engagements.
167
+
168
+ For a commercial license, a partnership, or to share a procurement dataset, reach out: **[ahmedhafsi.com/contact](https://ahmedhafsi.com/contact/)**.
169
+
170
+ © Ahmed K. Hafsi. P2Predict is a copyrighted work; all rights reserved except as granted under the license above.
@@ -0,0 +1,81 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "p2predict"
7
+ version = "0.9.0"
8
+ description = "Parametric price benchmarking for procurement and engineering — exact SHAP attribution, conformal likely-range intervals, what-if comparisons, all CLI- and agent-callable."
9
+ readme = "README.md"
10
+ license = "PolyForm-Noncommercial-1.0.0"
11
+ license-files = ["LICENSE"]
12
+ authors = [{name = "Ahmed Khalil Hafsi"}]
13
+ requires-python = ">=3.10"
14
+ keywords = [
15
+ "procurement",
16
+ "price-prediction",
17
+ "parametric-estimating",
18
+ "should-cost",
19
+ "shap",
20
+ "conformal-prediction",
21
+ "machine-learning",
22
+ "scikit-learn",
23
+ "xgboost",
24
+ "mcp",
25
+ ]
26
+ classifiers = [
27
+ "Development Status :: 4 - Beta",
28
+ "Intended Audience :: Developers",
29
+ "Intended Audience :: Financial and Insurance Industry",
30
+ "Intended Audience :: Science/Research",
31
+ "Operating System :: OS Independent",
32
+ "Programming Language :: Python :: 3",
33
+ "Programming Language :: Python :: 3.10",
34
+ "Programming Language :: Python :: 3.11",
35
+ "Programming Language :: Python :: 3.12",
36
+ "Topic :: Scientific/Engineering",
37
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
38
+ ]
39
+ dependencies = [
40
+ "click>=8.1",
41
+ "joblib>=1.2",
42
+ "matplotlib>=3.7",
43
+ "mpld3>=0.5",
44
+ "numpy>=1.24",
45
+ "pandas>=2.0,<3.0",
46
+ "rich>=13.3",
47
+ "scikit-learn>=1.5",
48
+ "scipy>=1.10",
49
+ "seaborn>=0.12",
50
+ "xgboost>=1.7",
51
+ "halo>=0.0.31",
52
+ "questionary>=1.10",
53
+ "shap>=0.44,<0.50",
54
+ ]
55
+
56
+ [project.optional-dependencies]
57
+ mcp = [
58
+ "mcp>=1.0",
59
+ ]
60
+ dev = [
61
+ "pytest>=7",
62
+ ]
63
+
64
+ [project.urls]
65
+ Homepage = "https://github.com/ahmed-khalil-hafsi/P2Predict"
66
+ Repository = "https://github.com/ahmed-khalil-hafsi/P2Predict"
67
+ Issues = "https://github.com/ahmed-khalil-hafsi/P2Predict/issues"
68
+ Changelog = "https://github.com/ahmed-khalil-hafsi/P2Predict/blob/main/CHANGELOG.md"
69
+ Roadmap = "https://github.com/ahmed-khalil-hafsi/P2Predict/blob/main/ROADMAP.md"
70
+
71
+ [project.scripts]
72
+ p2predict = "p2predict.cli.predict:main"
73
+ p2predict-train = "p2predict.cli.train:train"
74
+ p2predict-mcp = "p2predict.mcp.server:main"
75
+
76
+ [tool.setuptools.packages.find]
77
+ where = ["src"]
78
+ include = ["p2predict*"]
79
+
80
+ [tool.pytest.ini_options]
81
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+