Main Content

RegressionPartitionedQuantileModel

Cross-validated quantile model for regression

Since R2025a

    Description

    RegressionPartitionedQuantileModel is a set of quantile regression models trained on cross-validated folds. You can estimate the quality of the object by using one or more kfold functions: kfoldPredict, kfoldLoss, and kfoldfun.

    Every kfold object function uses models trained on training-fold (in-fold) observations to predict the response for validation-fold (out-of-fold) observations. For example, suppose you cross-validate using five folds. The software randomly assigns each observation into five groups of equal size (roughly). The training fold contains four of the groups (roughly 4/5 of the data), and the validation fold contains the other group (roughly 1/5 of the data). In this case, cross-validation proceeds as follows:

    1. The software trains the first model (stored in CVMdl.Trained{1}) by using the observations in the last four groups, and reserves the observations in the first group for validation.

    2. The software trains the second model (stored in CVMdl.Trained{2}) by using the observations in the first group and the last three groups. The software reserves the observations in the second group for validation.

    3. The software proceeds in a similar manner for the third, fourth, and fifth models.

    If you validate by using kfoldPredict, the software computes predictions for the observations in group i by using model i. In short, the software estimates a response for every observation by using the model trained without that observation.

    Creation

    You can create a RegressionPartitionedQuantileModel object in two ways:

    • Create a cross-validated model from a quantile regression model object by using the crossval object function.

    • Create a cross-validated model by using the fitrqlinear or fitrqnet function and specifying one of the name-value arguments CrossVal, CVPartition, Holdout, KFold, or Leaveout.

    Properties

    expand all

    Cross-Validation Properties

    This property is read-only.

    Cross-validated model name, returned as 'QuantileLinear' or 'QuantileNeuralNetwork'.

    Data Types: char

    This property is read-only.

    Number of cross-validated folds, returned as a positive integer.

    Data Types: double

    This property is read-only.

    Cross-validation parameter values, returned as an EnsembleParams object. The parameter values correspond to the values of the name-value arguments used to cross-validate the quantile regression model. ModelParameters does not contain estimated parameters.

    You can access the properties of ModelParameters using dot notation.

    This property is read-only.

    Data partition indicating how the software splits the data into cross-validation folds, returned as a cvpartition model.

    This property is read-only.

    Compact models trained on cross-validation folds, returned as a cell array of CompactRegressionQuantileLinear or CompactRegressionQuantileNeuralNetwork model objects. Trained has k cells, where k is the number of folds.

    Data Types: cell

    Other Regression Quantile Properties

    This property is read-only.

    Quantiles used to train the quantile regression model, returned as a vector of values in the range [0,1].

    Data Types: double

    This property is read-only.

    Predictor variable names, returned as a cell array of character vectors. The order of the elements of PredictorNames corresponds to the order in which the predictor names appear in the training data.

    Data Types: cell

    This property is read-only.

    Categorical predictor indices, returned as a vector of positive integers. Assuming that the predictor data contains observations in rows, CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. If none of the predictors are categorical, then this property is empty ([]).

    Data Types: double

    This property is read-only.

    Number of observations in the training data stored in X and Y, returned as a positive numeric scalar.

    Data Types: double

    This property is read-only.

    Response variable name, returned as a character vector.

    Data Types: char

    Response transformation function, specified as "none" or a function handle. ResponseTransform describes how the software transforms raw response values.

    For a MATLAB® function or a function that you define, enter its function handle. For example, you can enter Mdl.ResponseTransform = @function, where function accepts a numeric vector of the original responses and returns a numeric vector of the same size containing the transformed responses.

    Data Types: char | string | function_handle

    This property is read-only.

    Observation weights, returned as an n-by-1 numeric vector. n is the number of observations (NumObservations).

    The software normalizes the observation weights so that the elements of W sum to 1.

    Data Types: single | double

    This property is read-only.

    Unstandardized predictors used to cross-validate the model, returned as a numeric matrix or a table. X retains its original orientation, with observations in rows or columns depending on the value of the ObservationsIn name-value argument in the call to the fitting function.

    Data Types: single | double | table

    This property is read-only.

    Response values used to cross-validate the model, returned as a numeric vector. Each row of Y represents the response value of the corresponding observation in X.

    Data Types: single | double

    Object Functions

    kfoldLossLoss for cross-validated partitioned quantile regression model
    kfoldPredictPredict responses for observations in cross-validated quantile regression model
    kfoldfunCross-validate function for quantile regression

    Examples

    collapse all

    Cross-validate a quantile linear regression model using the default 10-fold cross-validation.

    Load the carbig data set, which contains measurements of cars made in the 1970s and early 1980s. Create a matrix X containing the predictor variables Acceleration, Displacement, Horsepower, and Weight. Store the response variable MPG in the variable Y.

    load carbig
    X = [Acceleration,Displacement,Horsepower,Weight];
    Y = MPG;

    Delete rows of X and Y where either array has missing values.

    R = rmmissing([X Y]);
    X = R(:,1:end-1);
    Y = R(:,end);

    Train a quantile linear regression model. Specify to use the 0.25, 0.50, and 0.75 quantiles (that is, the lower quartile, median, and upper quartile). To improve the model fit, change the beta tolerance to 1e-6 instead of the default value 1e-4, and use a ridge (L2) regularization term of 1.

    Mdl = fitrqlinear(X,Y,Quantiles=[0.25,0.50,0.75], ...
        BetaTolerance=1e-6,Lambda=1)
    Mdl = 
      RegressionQuantileLinear
                 ResponseName: 'Y'
        CategoricalPredictors: []
            ResponseTransform: 'none'
                         Beta: [4×3 double]
                         Bias: [17.0306 22.5291 29.0044]
                    Quantiles: [0.2500 0.5000 0.7500]
    
    
      Properties, Methods
    
    

    Mdl is a trained RegressionQuantileLinear model object.

    Cross-validate the classifier using 10-fold cross-validation. During cross-validation, the software completes these steps:

    1. Randomly partition the data into ten sets of equal size.

    2. Train a quantile linear regression model on nine of the sets.

    3. Repeat steps 1 and 2, ten times. The software leaves out one partition each time and trains on the other nine partitions.

    4. Combine generalization statistics for each fold.

    CVMdl = crossval(Mdl)
    CVMdl = 
      RegressionPartitionedQuantileModel
        CrossValidatedModel: 'QuantileLinear'
             PredictorNames: {'x1'  'x2'  'x3'  'x4'}
               ResponseName: 'Y'
            NumObservations: 392
                      KFold: 10
                  Partition: [1×1 cvpartition]
          ResponseTransform: 'none'
                  Quantiles: [0.2500 0.5000 0.7500]
    
    
      Properties, Methods
    
    

    CVMdl is a RegressionPartitionedQuantileModel object.

    Display the first model in CVMdl.Trained.

    FirstModel = CVMdl.Trained{1}
    FirstModel = 
      CompactRegressionQuantileLinear
               PredictorNames: {'x1'  'x2'  'x3'  'x4'}
                 ResponseName: 'Y'
        CategoricalPredictors: []
            ResponseTransform: 'none'
                         Beta: [4×3 double]
                         Bias: [17.0004 22.5029 29.0247]
                    Quantiles: [0.2500 0.5000 0.7500]
    
    
      Properties, Methods
    
    

    FirstModel is the first of the ten trained models contained in CVMdl. The trained models are all CompactRegressionQuantileLinear objects.

    After creating a cross-validated quantile regression model object, you can estimate the generalized quantile loss by passing the model to kfoldLoss.

    Version History

    Introduced in R2025a