Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
8 changes: 7 additions & 1 deletion src/python/nimbusml/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2536,14 +2536,20 @@ def summary(self, verbose=0, **params):
"Model is not fitted. Train or load a model before "
"summary().")

# check if Field Aware FactorizationMachine exists in the steps
from .decomposition.factorizationmachinebinaryclassifier import FactorizationMachineBinaryClassifier
for step in self.steps:
if isinstance(step, FactorizationMachineBinaryClassifier):
raise TypeError("FieldAwareFactorizationMachine doesn't have summary function")

# check last step is predictor in case there are steps in pipeline
# importing here to break cycle import cycle dependency between
# pipeline and base_predictor
from .base_predictor import BasePredictor
if len(self.steps) > 0 and not isinstance(
self.last_node, BasePredictor):
raise ValueError(
"Summary is availabe only for predictor types, instead "
"Summary is available only for predictor types, instead "
"got " +
self.last_node.type)

Expand Down
18 changes: 17 additions & 1 deletion src/python/nimbusml/tests/model_summary/test_model_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,23 @@ def test_model_summary(self):
[OneHotVectorizer() << categorical_columns, learner])
train_stream = FileDataStream(train_file, schema=file_schema)
pipeline.fit(train_stream, label_column)
pipeline.summary()
# If Pipeline does contain FactorizationMachineBinaryClassifier,
# check for TypeError thrown by pipeline as
# FactorizationMachineBinaryClassifier does not support summary()
Comment thread
mstfbl marked this conversation as resolved.
Outdated
# Else, Pipeline does not contain FactorizationMachineBinaryClassifier,
# thus check for summary
containsFactorizationMachineBinaryClassifier = False
for step in pipeline.steps:
if isinstance(step, FactorizationMachineBinaryClassifier):
containsFactorizationMachineBinaryClassifier = True
if containsFactorizationMachineBinaryClassifier:
try:
pipeline.summary()
assert False
except TypeError:
assert True
else:
pipeline.summary()

@unittest.skip("No unsupported learners")
def test_model_summary_not_supported(self):
Expand Down