mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Update docs
This commit is contained in:
@@ -59,7 +59,9 @@
|
||||
|
||||
<!-- Main title -->
|
||||
|
||||
<a class="navbar-brand" href="..">MIPLearn</a>
|
||||
|
||||
<a class="navbar-brand" href="..">MIPLearn</a>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Expanded navigation -->
|
||||
@@ -152,12 +154,11 @@
|
||||
<h2 id="customizing-solver-parameters">Customizing solver parameters</h2>
|
||||
<h3 id="selecting-the-internal-mip-solver">Selecting the internal MIP solver</h3>
|
||||
<p>By default, <code>LearningSolver</code> uses <a href="https://www.gurobi.com/">Gurobi</a> as its internal MIP solver. Another supported solver is <a href="https://www.ibm.com/products/ilog-cplex-optimization-studio">IBM ILOG CPLEX</a>. To switch between solvers, use the <code>solver</code> constructor argument, as shown below. It is also possible to specify a time limit (in seconds) and a relative MIP gap tolerance.</p>
|
||||
<pre><code class="python">from miplearn import LearningSolver
|
||||
<pre><code class="language-python">from miplearn import LearningSolver
|
||||
solver = LearningSolver(solver="cplex",
|
||||
time_limit=300,
|
||||
gap_tolerance=1e-3)
|
||||
</code></pre>
|
||||
|
||||
<h2 id="customizing-solver-components">Customizing solver components</h2>
|
||||
<p><code>LearningSolver</code> is composed by a number of individual machine-learning components, each targeting a different part of the solution process. Each component can be individually enabled, disabled or customized. The following components are enabled by default:</p>
|
||||
<ul>
|
||||
@@ -171,7 +172,7 @@ solver = LearningSolver(solver="cplex",
|
||||
</ul>
|
||||
<h3 id="selecting-components">Selecting components</h3>
|
||||
<p>To create a <code>LearningSolver</code> with a specific set of components, the <code>components</code> constructor argument may be used, as the next example shows:</p>
|
||||
<pre><code class="python"># Create a solver without any components
|
||||
<pre><code class="language-python"># Create a solver without any components
|
||||
solver1 = LearningSolver(components=[])
|
||||
|
||||
# Create a solver with only two components
|
||||
@@ -180,15 +181,13 @@ solver2 = LearningSolver(components=[
|
||||
PrimalSolutionComponent(...),
|
||||
])
|
||||
</code></pre>
|
||||
|
||||
<p>It is also possible to add components to an existing solver using the <code>solver.add</code> method, as shown below. If the solver already holds another component of that type, the new component will replace the previous one.</p>
|
||||
<pre><code class="python"># Create solver with default components
|
||||
<pre><code class="language-python"># Create solver with default components
|
||||
solver = LearningSolver()
|
||||
|
||||
# Replace the default LazyConstraintComponent by one with custom parameters
|
||||
solver.add(LazyConstraintComponent(...))
|
||||
</code></pre>
|
||||
|
||||
<h3 id="adjusting-component-aggressiveness">Adjusting component aggressiveness</h3>
|
||||
<p>The aggressiveness of classification components (such as <code>PrimalSolutionComponent</code> and <code>LazyConstraintComponent</code>) can
|
||||
be adjusted through the <code>threshold</code> constructor argument. Internally, these components ask the ML models how confident
|
||||
@@ -199,13 +198,12 @@ while raising a component's threshold makes it more conservative. </p>
|
||||
to achieve a minimum desired true positive rate (also known as precision). The example below shows how to initialize
|
||||
a <code>PrimalSolutionComponent</code> which achieves 95% precision, possibly at the cost of a lower recall. To make the component
|
||||
more aggressive, this precision may be lowered.</p>
|
||||
<pre><code class="python">PrimalSolutionComponent(threshold=MinPrecisionThreshold(0.95))
|
||||
<pre><code class="language-python">PrimalSolutionComponent(threshold=MinPrecisionThreshold(0.95))
|
||||
</code></pre>
|
||||
|
||||
<h3 id="evaluating-component-performance">Evaluating component performance</h3>
|
||||
<p>MIPLearn allows solver components to be modified, trained and evaluated in isolation. In the following example, we build and
|
||||
fit <code>PrimalSolutionComponent</code> outside the solver, then evaluate its performance.</p>
|
||||
<pre><code class="python">from miplearn import PrimalSolutionComponent
|
||||
<pre><code class="language-python">from miplearn import PrimalSolutionComponent
|
||||
|
||||
# User-provided set of previously-solved instances
|
||||
train_instances = [...]
|
||||
@@ -217,14 +215,12 @@ comp.fit(train_instances[:100])
|
||||
# Evaluate performance on an additional set of training instances
|
||||
ev = comp.evaluate(train_instances[100:150])
|
||||
</code></pre>
|
||||
|
||||
<p>The method <code>evaluate</code> returns a dictionary with performance evaluation statistics for each training instance provided,
|
||||
and for each type of prediction the component makes. To obtain a summary across all instances, pandas may be used, as below:</p>
|
||||
<pre><code class="python">import pandas as pd
|
||||
<pre><code class="language-python">import pandas as pd
|
||||
pd.DataFrame(ev["Fix one"]).mean(axis=1)
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="text">Predicted positive 3.120000
|
||||
<pre><code class="language-text">Predicted positive 3.120000
|
||||
Predicted negative 196.880000
|
||||
Condition positive 62.500000
|
||||
Condition negative 137.500000
|
||||
@@ -246,10 +242,9 @@ False positive (%) 0.030000
|
||||
False negative (%) 29.720000
|
||||
dtype: float64
|
||||
</code></pre>
|
||||
|
||||
<p>Regression components (such as <code>ObjectiveValueComponent</code>) can also be trained and evaluated similarly,
|
||||
as the next example shows:</p>
|
||||
<pre><code class="python">from miplearn import ObjectiveValueComponent
|
||||
<pre><code class="language-python">from miplearn import ObjectiveValueComponent
|
||||
comp = ObjectiveValueComponent()
|
||||
comp.fit(train_instances[:100])
|
||||
ev = comp.evaluate(train_instances[100:150])
|
||||
@@ -257,8 +252,7 @@ ev = comp.evaluate(train_instances[100:150])
|
||||
import pandas as pd
|
||||
pd.DataFrame(ev).mean(axis=1)
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="text">Mean squared error 7001.977827
|
||||
<pre><code class="language-text">Mean squared error 7001.977827
|
||||
Explained variance 0.519790
|
||||
Max error 242.375804
|
||||
Mean absolute error 65.843924
|
||||
@@ -266,7 +260,6 @@ R2 0.517612
|
||||
Median absolute error 65.843924
|
||||
dtype: float64
|
||||
</code></pre>
|
||||
|
||||
<h3 id="using-customized-ml-classifiers-and-regressors">Using customized ML classifiers and regressors</h3>
|
||||
<p>By default, given a training set of instantes, MIPLearn trains a fixed set of ML classifiers and regressors, then
|
||||
selects the best one based on cross-validation performance. Alternatively, the user may specify which ML model a component
|
||||
@@ -281,7 +274,7 @@ predictors. This is a known limitation, which will be addressed in a future vers
|
||||
</div>
|
||||
<p>The example below shows how to construct a <code>PrimalSolutionComponent</code> which internally uses
|
||||
sklearn's <code>KNeighborsClassifiers</code>. Any other sklearn classifier or pipeline can be used. </p>
|
||||
<pre><code class="python">from miplearn import PrimalSolutionComponent
|
||||
<pre><code class="language-python">from miplearn import PrimalSolutionComponent
|
||||
from sklearn.neighbors import KNeighborsClassifier
|
||||
|
||||
comp = PrimalSolutionComponent(classifier=KNeighborsClassifier(n_neighbors=5))
|
||||
@@ -291,18 +284,22 @@ comp.fit(train_instances)
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="col-md-12 text-center">
|
||||
|
||||
<hr>
|
||||
<p>
|
||||
<small>Copyright © 2020, UChicago Argonne, LLC. All Rights Reserved.</small><br>
|
||||
|
||||
<small>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.</small>
|
||||
</p>
|
||||
|
||||
<footer class="col-md-12 text-center">
|
||||
|
||||
|
||||
<hr>
|
||||
<p>
|
||||
<small>Copyright © 2020, UChicago Argonne, LLC. All Rights Reserved.</small><br>
|
||||
|
||||
<small>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.</small>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
||||
<script src="../js/bootstrap-3.0.3.min.js"></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user