-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post postmodeling: A new hope #673
Open
nanounanue
wants to merge
17
commits into
master
Choose a base branch
from
post-postmodeling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
199ace6
New model interface based on sqlalchemy. Copied code as-is from the
nanounanue 62e25a8
Plots: ROC, prec_recall_n
nanounanue b4e8a20
Added __iter__ to model group
nanounanue b3aed88
Plots added: Rayid’s curve, Metric over time (for model groups) and ROC.
nanounanue e6ceb0d
Removed this folder
nanounanue 7ae9600
Removed redundant methods
nanounanue f82e22d
New README
nanounanue e6ffd47
Unit testing modified
nanounanue 5a55def
Update src/triage/component/postmodeling/README.org
jesteria 1596bb5
Update src/triage/component/postmodeling/__init__.py
jesteria ff19d0f
warning -> logging
nanounanue 5131af7
Trying to be more “fair” :)
nanounanue be544e1
Removed “functional programming imperative” style
nanounanue 8885c58
sessionmaker -> Session (see https://docs.sqlalchemy.org/en/13/orm/se…
nanounanue a5fd6e7
Removed transitioning files
nanounanue 6c8f89f
Removed “superfluous list construction”
nanounanue 3cda2e4
More superfluous lists construction removed (I really like the word “…
nanounanue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
src/tests/postmodeling_tests/test_model_group_evaluator.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from triage.component.postmodeling import Model, ModelGroup, get_model, get_model_group, session | ||
from triage.component.postmodeling.plots import plot_roc, plot_precision_recall_n, plot_metric_over_time | ||
from triage.component.postmodeling.crosstabs import run_crosstabs | ||
from tests.utils import sample_config, populate_source_data, assert_plot_figures_added | ||
from triage.experiments import SingleThreadedExperiment | ||
import pandas as pd | ||
import pytest | ||
import os | ||
|
||
@pytest.fixture(scope="module") | ||
def model(shared_db_engine, shared_project_storage): | ||
"""Returns an instantiated ModelEvaluator available at module scope""" | ||
populate_source_data(shared_db_engine) | ||
base_config = sample_config() | ||
# We need to have an ensemble model to test ModelEvaluator correctly | ||
# so we can't use the finished_experiment fixture""" | ||
base_config['grid_config'] = { | ||
'sklearn.ensemble.ExtraTreesClassifier': { | ||
'n_estimators': [10], | ||
'criterion': ['gini'], | ||
'max_depth': [1], | ||
'max_features': ['sqrt'], | ||
'min_samples_split': [2], | ||
} | ||
} | ||
SingleThreadedExperiment( | ||
base_config, | ||
db_engine=shared_db_engine, | ||
project_path=shared_project_storage.project_path | ||
).run() | ||
|
||
|
||
session = create_session(shared_db_engine) | ||
|
||
return get_model(1) | ||
|
||
@pytest.fixture(scope="module") | ||
def model_group(finished_experiment): | ||
os.environ["DATABASE_URL"] = finished_experiment.db_engine.url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than pollute the process's actual environment during test, this can patch it and undo the change:
|
||
|
||
return get_model_group(1) | ||
|
||
|
||
def test_plot_metric_over_time(model_group): | ||
with assert_plot_figures_added(): | ||
plot_metric_over_time(model_group, metric='precision', parameter='10_pct') | ||
|
||
|
||
def test_plot_precision_recall_n(model): | ||
with assert_plot_figures_added(): | ||
plot_precision_recall_n(model) | ||
|
||
def test_plot_ROC(model): | ||
with assert_plot_figures_added(): | ||
plot_ROC(model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#+TITLE: Post-modeling analysis | ||
|
||
* Introduction | ||
|
||
/Postmodeling/ is about exploring the model group in a point of time | ||
(i.e. a model) or over time. | ||
|
||
Choosing the right model for deployment and exploring its predictions | ||
and behavior in time is a pivotal task. =postmodeling= will help to | ||
answer some of this questions by exploring the outcomes of the model, | ||
and exploring /deeply/ into the model behavior across time and | ||
features. | ||
|
||
This library lays at the end of the =triage= pipeline and will use the | ||
output of *audition* and some of its selection rules as a main | ||
input. | ||
|
||
* What you can do? | ||
|
||
** Compare model groups | ||
|
||
*** Metric | ||
|
||
*** Overlaps | ||
|
||
** Display the model group over time | ||
|
||
*** Metric | ||
|
||
*** Top Features | ||
|
||
*** Top predicted entities | ||
|
||
** Drill in a model group in a specific time | ||
|
||
*** Top Features | ||
|
||
*** Score distribution | ||
|
||
*** /Crosstabs/ | ||
|
||
|
||
* New API | ||
|
||
We encapsulate the model groups from the database in two objects | ||
=ModelGroup= and =Model=. | ||
|
||
You could manipulate those objects using functions using functions: | ||
|
||
- =plot_XXXX(object, **kwargs)= for plotting, located in =plot.py=. The | ||
arguments for this set of functions are =model= or a =model_group= and | ||
they always return a =fig, ax= matplotlib objects so you can modify | ||
them on the fly and tailor them for your specific purposes. | ||
|
||
* Use | ||
|
||
*NOTE*: This module use the =triage='s /default/ (and recommended) way of specify the | ||
database connection: an environment variable =DATABASE_URL= or it will | ||
try to read the connection file from a =DATABASE_FILE=. | ||
|
||
If you are playing with this module in Jupyter notebooks, remember | ||
that you can set environment variables with =%env=. | ||
|
||
|
||
Most of the time you will need to import these: | ||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
from triage.component.postmodeling import get_model_group, get_model | ||
from triage.component.postmodeling.plots import plot_roc, plot_precision_recall_n, plot_metric_over_time | ||
#+END_SRC | ||
|
||
If you want to get a particular =ModelGroup= | ||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
mg = get_model_group(model_group_id=14) | ||
#+END_SRC | ||
|
||
If you want to plot the performance over time: | ||
|
||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
## mgs is a list of ModelGroups | ||
plot_metric_over_time(mgs, metric='precision', parameter='10_pct') | ||
#+END_SRC | ||
|
||
or an individual =Model= | ||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
m = get_model(model_id = 5) | ||
#+END_SRC | ||
|
||
|
||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
plot_precision_recall_n(m) | ||
#+END_SRC | ||
|
||
#+BEGIN_SRC jupyter-python :session postmodeling | ||
plot_ROC(m) | ||
#+END_SRC |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this line do anything? (i notice that you're not using
session
, at least.)