gdkrmr / dimRed

A Framework for Dimensionality Reduction in R
https://www.guido-kraemer.com/software/dimred/
GNU General Public License v3.0
73 stars 15 forks source link

prospective projections/predictions #1

Closed topepo closed 7 years ago

topepo commented 7 years ago

Can you add a functions or classes that will allow the model to be estimated from a data set and then applied to any other data set? This wouldn't work for every method (e.g. MDS) but would be extremely useful.

For example, with PCA:

set.seed(12)
for_mod <- sample(1:nrow(USArrests), 40)

pca_mod <- prcomp(~ Murder + Assault + Rape, data = USArrests[for_mod, ], scale = TRUE)

## now apply the projection onto any data set:
pca_mod_data   <- predict(pca_mod, USArrests[ for_mod, ])
pca_other_data <- predict(pca_mod, USArrests[-for_mod, ])

Thanks

gdkrmr commented 7 years ago

I just saw, that the feature is completely undocumented and hides in some examples. I will make a predict and inverse function for the next release, but for now you can use (for supported methods only):

emb <- embed(loadDataSet("Iris")[1:50], "PCA")
pred <- emb@apply(loadDataSet("Iris")[51:150])
emb@inverse(pred)
topepo commented 7 years ago

Excellent. I'm writing (another) feature pre-processor that includes signal extraction, so I'll keep an eye on your updates and will post questions here if they come up.

Thanks

gdkrmr commented 7 years ago

just pushed the predict and inverse functions, they are documented with the dimRedResults class