Exemplo n.º 1
0
def test_feature_scoring_with_nan():
	road_scope = emat.Scope(emat.package_file('model','tests','road_test_bogus.yaml'))
	road_test = PythonCoreModel(_Road_Capacity_Investment_with_Bogus_Output, scope=road_scope)
	road_test_design = road_test.design_experiments(n_samples=5000, sampler='lhs')
	road_test_results = road_test.run_experiments(design=road_test_design)
	fs = feature_scores(road_scope, road_test_results, random_state=234)
	assert isinstance(fs, pd.io.formats.style.Styler)
	stable_df("./road_test_feature_scores_bogus_1.pkl.gz", fs.data)
Exemplo n.º 2
0
def test_feature_scoring_and_prim():
	road_scope = emat.Scope(emat.package_file('model','tests','road_test.yaml'))
	road_test = PythonCoreModel(Road_Capacity_Investment, scope=road_scope)
	road_test_design = road_test.design_experiments(n_samples=5000, sampler='lhs')
	road_test_results = road_test.run_experiments(design=road_test_design)
	fs = feature_scores(road_scope, road_test_results, random_state=123)
	assert isinstance(fs, pd.io.formats.style.Styler)
	stable_df("./road_test_feature_scores_1.pkl.gz", fs.data)

	prim1 = road_test_results.prim(target="net_benefits >= 0")
	pbox1 = prim1.find_box()

	assert pbox1._cur_box == 64
	ts1 = prim1.tradeoff_selector()
	assert len(ts1.data) == 1
	assert ts1.data[0]['x'] == approx(np.asarray([
		1., 1., 1., 1., 1.,
		0.99928315, 0.99856631, 0.99784946, 0.99569892, 0.99283154,
		0.98924731, 0.98351254, 0.97921147, 0.97491039, 0.96702509,
		0.95555556, 0.94982079, 0.94336918, 0.92903226, 0.91182796,
		0.89749104, 0.87598566, 0.85304659, 0.83942652, 0.83225806,
		0.82078853, 0.79713262, 0.77706093, 0.76415771, 0.75483871,
		0.74480287, 0.73261649, 0.71827957, 0.70394265, 0.68100358,
		0.65663082, 0.63225806, 0.61003584, 0.59569892, 0.57992832,
		0.55770609, 0.54193548, 0.52759857, 0.51111111, 0.49892473,
		0.48960573, 0.4781362, 0.45878136, 0.44229391, 0.42365591,
		0.409319, 0.39498208, 0.38064516, 0.36487455, 0.34767025,
		0.33261649, 0.31756272, 0.30322581, 0.28888889, 0.27741935,
		0.26379928, 0.25089606, 0.23942652, 0.22795699, 0.2172043]))
	pbox1.select(40)
	assert pbox1._cur_box == 40
	assert ts1.data[0]['marker']['symbol'] == approx(np.asarray([
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))

	ebox1_40 = pbox1.to_emat_box()
	assert ebox1_40.coverage == approx(0.5577060931899641)
	assert ebox1_40.density == approx(0.8356605800214822)
	assert ebox1_40.mass == approx(0.1862)
	from emat import Bounds
	assert ebox1_40.thresholds == {'beta': Bounds(lowerbound=3.597806324946271, upperbound=None),
	                               'input_flow': Bounds(lowerbound=125, upperbound=None),
	                               'value_of_time': Bounds(lowerbound=0.07705746291056698, upperbound=None),
	                               'expand_capacity': Bounds(lowerbound=None, upperbound=95.01870815358643)}
	pbox1.splom()
	pbox1.hmm()
Exemplo n.º 3
0
# And then we will design and run some experiments to generate data used for
# feature scoring.

# %%
from emat import PythonCoreModel
demo_model = PythonCoreModel(demo, scope=demo_scope)
experiments = demo_model.design_experiments(n_samples=5000)
experiment_results = demo_model.run_experiments(experiments)

# %% [markdown]
# The :func:`feature_scores` method from the `emat.analysis` subpackage allows for
# feature scoring based on the implementation found in the EMA Workbench.

# %%
from emat.analysis import feature_scores
fs = feature_scores(demo_scope, experiment_results)
fs

# %% [raw] raw_mimetype="text/restructuredtext"
# Note that the :func:`feature_scores` depend on the *scope* (to identify what are input features
# and what are outputs) and the *experiment_results*, but not on the model itself.  
#
# We can plot each of these input parameters using the `display_experiments` method,
# which can help visualize the underlying data and exactly how *B* is the most important
# feature for this example.

# %%
from emat.analysis import display_experiments
fig = display_experiments(demo_scope, experiment_results, render=False, return_figures=True)['Y']
fig.update_layout(
    xaxis_title_text =f"A (Feature Score = {fs.data.loc['Y','A']:.3f})",
Exemplo n.º 4
0
# And then we will design and run some experiments to generate data used for
# feature scoring.

# %%
from emat import PythonCoreModel
demo_model = PythonCoreModel(demo, scope=demo_scope)
experiments = demo_model.design_experiments(n_samples=5000)
experiment_results = demo_model.run_experiments(experiments)

# %% [markdown]
# The `feature_scores` method from the `emat.analysis` subpackage allows for
# feature scoring based on the implementation found in the EMA Workbench.

# %%
from emat.analysis import feature_scores
fs = feature_scores(demo_scope, experiment_results, return_type='dataframe')
fs

# %% [markdown]
# Note that the `feature_scores` depend on the *scope* (to identify what are input features
# and what are outputs) and the *experiment_results*, but not on the model itself.
#
# We can plot each of these input parameters using the `display_experiments` method,
# which can help visualize the underlying data and exactly how *B* is the most important
# feature for this example.

# %%
from emat.analysis import display_experiments
fig = display_experiments(demo_scope,
                          experiment_results,
                          render=False,