Main Content

gather

Gather properties of machine learning model from GPU

    Description

    example

    gatheredMdl = gather(mdl) gathers all properties of the input regression or classification model mdl and returns the gathered model gatheredMdl. All properties of the output model are stored in the local workspace.

    Use gather to create a machine learning model with properties stored in the local workspace from a model fitted using data stored as a GPU array. For more details on GPU arrays, see gpuArray (Parallel Computing Toolbox).

    [gatheredMdl1,gatheredMdl2,...,gatheredMdln] = gather(mdl1,mdl2,...,mdln) gathers the properties of multiple models mdl1,mdl2,...,mdln and returns the corresponding gathered models gatheredMdl1,gatheredMdl2,...,gatheredMdln. The number of input arguments and output arguments must match.

    Examples

    collapse all

    Gather the properties of a linear regression model fitted with GPU array data.

    Load the carsmall data set. Create X as a numeric matrix that contains three car performance metrics. Create Y as a numeric vector that contains the corresponding miles per gallon.

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

    Convert the predictor X and response Y to gpuArray (Parallel Computing Toolbox) objects.

    X = gpuArray(X);
    Y = gpuArray(Y);

    Fit a linear regression model mdl by using fitlm.

    mdl = fitlm(X,Y);

    Display the coefficients of mdl and determine whether the estimated coefficient values are GPU arrays.

    mdl.Coefficients
    ans=4×4 table
                        Estimate        SE          tStat        pValue  
                       __________    _________    _________    __________
    
        (Intercept)        47.977       3.8785        12.37    4.8957e-21
        x1             -0.0065416    0.0011274      -5.8023    9.8742e-08
        x2              -0.042943     0.024313      -1.7663       0.08078
        x3              -0.011583      0.19333    -0.059913       0.95236
    
    
    isgpuarray(mdl.Coefficients.Estimate)
    ans = logical
       1
    
    

    Gather the properties of the linear regression model.

    gatheredMdl = gather(mdl);

    Display the coefficients of gatheredMdl and determine whether the estimated coefficient values are GPU arrays.

    gatheredMdl.Coefficients
    ans=4×4 table
                        Estimate        SE          tStat        pValue  
                       __________    _________    _________    __________
    
        (Intercept)        47.977       3.8785        12.37    4.8957e-21
        x1             -0.0065416    0.0011274      -5.8023    9.8742e-08
        x2              -0.042943     0.024313      -1.7663       0.08078
        x3              -0.011583      0.19333    -0.059913       0.95236
    
    
    isgpuarray(gatheredMdl.Coefficients.Estimate)
    ans = logical
       0
    
    

    Gather the properties of a linear regression model and a k-nearest neighbor classifier. Both models are fitted using GPU array data.

    Load the carsmall data set. Create X as a numeric matrix that contains three car performance metrics, and convert the predictor X to a gpuArray object.

    load carsmall
    X = [Weight,Horsepower,Acceleration];
    X = gpuArray(X);

    Fit a linear regression model of MPG (miles per gallon) as a function of the predictor X.

    mdlLinear = fitlm(X,MPG);

    Train a 3-nearest neighbor classifier using the predictor X and the classes Cylinders. Standardize the noncategorical predictor data.

    mdlKNN = fitcknn(X,Cylinders,'NumNeighbors',3,'Standardize',1);

    Gather the properties of the mdLinear and mdlKNN models.

    [gMdlLinear,gMdlKNN] = gather(mdlLinear,mdlKNN);

    Determine whether the p-value of the Durbin-Watson test for the regression model mdlLinear is a GPU array.

    isgpuarray(dwtest(mdlLinear))
    ans = logical
       1
    
    

    Determine whether the p-value of the Durbin-Watson test for the gathered regression model gMdlLinear is a GPU array.

    isgpuarray(dwtest(gMdlLinear))
    ans = logical
       0
    
    

    Determine whether the resubstitution loss of the classifier mdlKNN is a GPU array.

    isgpuarray(resubLoss(mdlKNN))
    ans = logical
       1
    
    

    Determine whether the resubstitution loss of the gathered classifier gMdlKNN is a GPU array.

    isgpuarray(resubLoss(gMdlKNN))
    ans = logical
       1
    
    

    Input Arguments

    collapse all

    Machine learning model fitted with GPU arrays, specified as a regression or classification model object, as given in the following table of supported models.

    Model Object NameModel DescriptionModel Creation Function
    LinearModelFull linear regression modelfitlm
    CompactLinearModelCompact linear regression modelLinearModel object function compact
    GeneralizedLinearModelFull generalized linear regression modelfitglm
    CompactGeneralizedLinearModelCompact generalized linear regression modelGeneralizedLinearModel object function compact
    ClassificationKNNk-nearest neighbor classification modelfitcknn

    If you want to create a compact model fitted with GPU arrays, the input argument mdl of compact must be a full model object fitted with GPU array input arguments.

    Extended Capabilities

    Introduced in R2020b