Learning dynamically inspired invariant subspaces for Koopman and transfer operator approximation