def _reduce_ncomps(self, ncomps):
        """

        Generate a new model with a smaller set of components.

        :param int ncomps: Number of ordered first N components from the original model to be kept.
        Must be smaller than the ncomps value of the original model.
        :return ChemometricsPLS object with reduced number of components.
        :rtype: ChemometricsPLS
        :raise ValueError: If number of components desired is larger than original number of components
        :raise AttributeError: If model is not fitted.
        """
        try:
            if ncomps > self.ncomps:
                raise ValueError('Fit a new model with more components instead')
            if self._isfitted is False:
                raise AttributeError('Model not Fitted')

            newmodel = deepcopy(self)
            newmodel._ncomps = ncomps

            newmodel.modelParameters = None
            newmodel.cvParameters = None
            newmodel.loadings_p = self.loadings_p[:, 0:ncomps]
            newmodel.weights_w = self.weights_w[:, 0:ncomps]
            newmodel.weights_c = self.weights_c[:, 0:ncomps]
            newmodel.loadings_q = self.loadings_q[:, 0:ncomps]
            newmodel.rotations_ws = self.rotations_ws[:, 0:ncomps]
            newmodel.rotations_cs = self.rotations_cs[:, 0:ncomps]
            newmodel.scores_t = None
            newmodel.scores_u = None
            newmodel.b_t = self.b_t[0:ncomps, 0:ncomps]
            newmodel.b_u = self.b_u[0:ncomps, 0:ncomps]

            # These have to be recalculated from the rotations
            newmodel.beta_coeffs = np.dot(newmodel.rotations_ws, newmodel.loadings_q.T)

            # NOTE: this "destroys" the internal state of the classifier apart from the PLS components,
            # but this is only meant to be used inside the fit object and for the VIP calculation.
            return newmodel
        except ValueError as verr:
            raise verr
        except AttributeError as atter:
            raise atter
def _reduce_ncomps ( self , ncomps ) : try : if ncomps > self . ncomps : raise ValueError ( 'Fit a new model with more components instead' ) if self . _isfitted is False : raise AttributeError ( 'Model not Fitted' ) newmodel = deepcopy ( self ) newmodel . _ncomps = ncomps newmodel . modelParameters = None newmodel . cvParameters = None newmodel . loadings_p = self . loadings_p [ : , 0 : ncomps ] newmodel . weights_w = self . weights_w [ : , 0 : ncomps ] newmodel . weights_c = self . weights_c [ : , 0 : ncomps ] newmodel . loadings_q = self . loadings_q [ : , 0 : ncomps ] newmodel . rotations_ws = self . rotations_ws [ : , 0 : ncomps ] newmodel . rotations_cs = self . rotations_cs [ : , 0 : ncomps ] newmodel . scores_t = None newmodel . scores_u = None newmodel . b_t = self . b_t [ 0 : ncomps , 0 : ncomps ] newmodel . b_u = self . b_u [ 0 : ncomps , 0 : ncomps ] newmodel . beta_coeffs = np . dot ( newmodel . rotations_ws , newmodel . loadings_q . T ) return newmodel except ValueError as verr : raise verr except AttributeError as atter : raise atter
Generate a new model with a smaller set of components.

        :param int ncomps: Number of ordered first N components from the original model to be kept.
        Must be smaller than the ncomps value of the original model.
        :return ChemometricsPLS object with reduced number of components.
        :rtype: ChemometricsPLS
        :raise ValueError: If number of components desired is larger than original number of components
        :raise AttributeError: If model is not fitted.