liveBook · Manning

Linprog

As explained in Statistics Every Programmer Needs

linprog is a SciPy function that solves linear programming problems by minimizing a linear objective subject to specified constraints.

linprog is a SciPy function for minimizing a linear objective under linear constraints. Negating priority scores lets it maximize feature value while respecting budgets and selection rules. section 8.2.2 section 8.2.3

A practical feature-selection formulation supplies:

  • Objective coefficients c, formed from negative value-to-effort ratios. section 8.2.3
  • Inequality constraints through A_ub and b_ub, including first-year and total-cost limits. section 8.2.2 section 8.2.6
  • Variable bounds representing feature selection as 0 or 1, plus rules requiring three to four features per epic. section 8.2.2 section 8.2.6

Feature portfolio optimization

Calling linprog with method='highs' returns success=True, a selection vector containing twelve selected features, and an optimized priority score of 17.6. section 8.2.6

>>> from dataclasses import dataclass
>>> @dataclass    #1
>>> class Feature:     #2
>>>     epic: str     #3
>>>     name: str    #4
>>>     cost_1yr: int     #5
>>>     total_cost: int     #6
>>>     value_points: int    #7
>>>     effort_points: int     #8
>>> features = [
>>>     Feature('Enhance Data Infrastructure',    #9
>>>        'Automated Data Cleaning Pipeline',    #10
>>>             50000, 80000, 16, 13),     #11
>>>     Feature('Enhance Data Infrastructure',
>>>             'Real-time Data Ingestion',
>>>             70000, 120000, 18, 14),
>>>     Feature('Enhance Data Infrastructure',
>>>             'Data Privacy and Compliance Tools',
>>>             80000, 130000, 19, 16),
>>>     Feature('Enhance Data Infrastructure',
>>>             'Real-time Data Monitoring and Alerts',
>>>             60000, 100000, 18, 13),

>>> # Other feature details not included 
>>> # for space considerations    #12

>>>     Feature('Advance Machine Learning and AI Capabilities',
>>>             'Customer Lifetime Value Prediction',
>>>             50000, 80000, 15, 10),
>>>     Feature('Advance Machine Learning and AI Capabilities',
>>>             'Time Series Forecasting',
>>>             55000, 90000, 16, 13),
>>>     Feature('Advance Machine Learning and AI Capabilities',
>>>             'Recommendation System for Cross-selling',
>>>             65000, 110000, 18, 12),
>>>     Feature('Advance Machine Learning and AI Capabilities',     #13
>>>        'Automated ML Model Selection and Tuning',     #14
>>>             70000, 115000, 20, 14)     #15
>>> ]

Browse the Feature data structure and sample records used to define costs, value, effort, and strategic grouping. section 8.2.2

>>> c = [-f.value_points / f.effort_points for f in features]

Browse the compact Python expression that constructs negated value-to-effort objective coefficients. section 8.2.3

>>> from scipy.optimize import linprog
>>> import numpy as np
>>> result = linprog(c, A_ub = A_ub, b_ub = b_ub,
>>>                  bounds = x_bounds, method = 'highs')

Browse the SciPy call that passes the objective, inequality constraints, bounds, and HiGHS method. section 8.2.6

How Statistics Every Programmer Needs covers it

How deep it goes
Explains objective construction, constraint matrices, bounds, solver invocation, and result checks without deriving solver internals.
Examples
Uses feature records, value-to-effort ratios, budget constraints, epic quotas, and a twelve-feature optimized portfolio.
What you can do after
Apply it via scipy.optimize.linprog to select features under linear constraints and evaluate solver success and chosen variables.
How it connects
Connects linear programming with objective functions, inequality constraints, binary decision variables, budgets, and resource allocation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.