@@ -402,15 +402,13 @@ end
402
402
403
403
# ## Methods to extend a pipeline learning network
404
404
405
- # The "front" of a pipeline network, as we grow it, consists of a
406
- # "predict" and a "transform" node. Once the pipeline is complete
407
- # (after a series of `extend` operations - see below) the "transform"
408
- # node is what is used to deliver the output of `transform(pipe)` in
409
- # the exported model, and the "predict" node is what will be used to
410
- # deliver the output of `predict(pipe). Both nodes can be changed by
411
- # `extend` but only the "active" node is propagated. Initially
412
- # "transform" is active and "predict" only becomes active when a
413
- # supervised model is encountered; this change is permanent.
405
+ # The "front" of a pipeline network, as we grow it, consists of a "predict" and a
406
+ # "transform" node. Once the pipeline is complete (after a series of `extend` operations -
407
+ # see below) the "transform" node is what is used to deliver the output of
408
+ # `transform(pipe, ...)` in the exported model, and the "predict" node is what will be
409
+ # used to deliver the output of `predict(pipe, ...). Both nodes can be changed by `extend`
410
+ # but only the "active" node is propagated. Initially "transform" is active and "predict"
411
+ # only becomes active when a supervised model is encountered; this change is permanent.
414
412
# https://github.com/JuliaAI/MLJClusteringInterface.jl/issues/10
415
413
416
414
abstract type ActiveNodeOperation end
587
585
# component, only its `abstract_type`. See comment at top of page.
588
586
589
587
MMI. supports_training_losses (pipe:: SupervisedPipeline ) =
590
- MMI. supports_training_losses (getproperty (pipe, supervised_component_name (pipe)))
588
+ MMI. supports_training_losses (supervised_component (pipe))
589
+
590
+ MMI. reports_feature_importances (pipe:: SupervisedPipeline ) =
591
+ MMI. reports_feature_importances (supervised_component (pipe))
591
592
592
593
# This trait cannot be defined at the level of types (see previous comment):
593
594
function MMI. iteration_parameter (pipe:: SupervisedPipeline )
@@ -618,3 +619,18 @@ function MMI.training_losses(pipe::SupervisedPipeline, pipe_report)
618
619
report = getproperty (pipe_report, supervised_name)
619
620
return training_losses (supervised, report)
620
621
end
622
+
623
+
624
+ # ## Feature importances
625
+
626
+ function feature_importances (pipe:: SupervisedPipeline , fitresult, report)
627
+ # locate the machine associated with the supervised component:
628
+ supervised_name = MLJBase. supervised_component_name (pipe)
629
+ predict_node = fitresult. interface. predict
630
+ mach = only (MLJBase. machines_given_model (predict_node)[supervised_name])
631
+
632
+ # To extract the feature_importances, we can't do `feature_importances(mach)` because
633
+ # `mach.model` is just a symbol; instead we do:
634
+ supervised = MLJBase. supervised_component (pipe)
635
+ return feature_importances (supervised, mach. fitresult, mach. report[:fit ])
636
+ end
0 commit comments