Let's say I have a simple pipeline:
Then this whole thing in a tuned model with corresponding machine mtm.
How can I access the trained on-hot-encoder machine in there and apply it on new data (transform)?
OneHotEncoder + Lasso, I'd like to show a stem plot of the amplitude of the coefficients with the name of the relevant features associated. Some of these features are OHE and so are not simply names(X) but rather names(transform(XXX, X)) if that makes sense.
On the side, given here all I want are these new names, maybe there should be a functionality to do that.
How can I access the trained on-hot-encoder machine in there and apply it on new data (transform)?
In principle you could do this but it's a hack. But your use-case could be addressed, as you suggest, in some other ways. Here are two:
(i) To just get the names, we could simply add the new names generated by OneHotEncoder (:State__CA, Stata__NJ, State__NY, dow__Monday, dow_Tuesday, and so forth) to its training report. Since the report of each machine trained in the pipeline is accessible in the report of the pipeline, you now have access to these names.
(ii) Any supervised model (in this case Lasso) that generates some kind of scores for individual features - let's call this a feature ranking - adds the ranking to it's report. Long ago, in a galaxy far, far away, RidgeRegressor actually did this.
I think we aim to do both - (i) to make the information available right now, and (ii) because the names and rankings are then bound unambiguously together in one place. (Here's one place where demanding tabular input is actually an advantage, for otherwise we couldn't do this.)
Is this clear? Your thoughts?
BTW, in the case of (ii) we should write some boilerplate code to make this easier for the manifold of models that will support this.
Why not just make a pipeline like I did in here: https://github.com/caseykneale/ChemometricsTools.jl/blob/master/src/Transformations.jl ?
@tlienart Update: (i) above is already implemented.
Great, I need to write another tutorial or two on pipelines showing how this can work
@tlienart
julia> X, y = @load_ames
julia> mach = fit!(machine(OneHotEncoder(), X))
julia> report(mach)
(features_to_be_encoded = Symbol[:Condition2, :MSZoning, :Street, :HouseStyle, :RoofStyle, :BsmtCond, :Functional, :PavedDrive, :MoSold, :ExterCond … :LotShape, :LotConfig, :Electrical, :SaleCondition, :Foundation, :GarageFinish, :GarageQual, :BldgType, :BsmtExposure, :RoofMatl],
new_features = Symbol[:MSSubClass____120, :MSSubClass____160, :MSSubClass____180, :MSSubClass____190, :MSSubClass____20, :MSSubClass____30, :MSSubClass____40, :MSSubClass____45, :MSSubClass____50, :MSSubClass____60 … :SaleType__ConLw, :SaleType__New, :SaleType__Oth, :SaleType__WD, :SaleCondition__Abnorml, :SaleCondition__AdjLand, :SaleCondition__Alloca, :SaleCondition__Family, :SaleCondition__Normal, :SaleCondition__Partial],)
julia> report(m).new_features
331-element Array{Symbol,1}:
:MSSubClass____120
:MSSubClass____160
:MSSubClass____180
:MSSubClass____190
:MSSubClass____20
:MSSubClass____30
:MSSubClass____40
:MSSubClass____45
:MSSubClass____50
:MSSubClass____60
:MSSubClass____70
:MSSubClass____75
:MSSubClass____80
:MSSubClass____85
:MSSubClass____90
â‹®
:SaleType__COD
:SaleType__CWD
:SaleType__Con
:SaleType__ConLD
:SaleType__ConLI
:SaleType__ConLw
:SaleType__New
:SaleType__Oth
:SaleType__WD
:SaleCondition__Abnorml
:SaleCondition__AdjLand
:SaleCondition__Alloca
:SaleCondition__Family
:SaleCondition__Normal
:SaleCondition__Partial