Main Content

本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。



为了提高在中低维数据集上的准确度,可以使用 fitlm 拟合线性回归模型。

为了减少在高维数据集上的计算时间,可以使用 fitrlinear 拟合线性回归模型。


Regression LearnerTrain regression models to predict data using supervised machine learning


LinearModelLinear regression model
CompactLinearModelCompact linear regression model
RegressionLinearLinear regression model for high-dimensional data
RegressionPartitionedLinearCross-validated linear regression model for high-dimensional data



创建 LinearModel 对象

stepwiselmPerform stepwise regression

创建 CompactLinearModel 对象

compactCompact linear regression model


addTermsAdd terms to linear regression model
removeTermsRemove terms from linear regression model
stepImprove linear regression model by adding or removing terms


fevalPredict responses of linear regression model using one input for each predictor
predictPredict responses of linear regression model
randomSimulate responses with random noise for linear regression model


anovaAnalysis of variance for linear regression model
coefCIConfidence intervals of coefficient estimates of linear regression model
coefTestLinear hypothesis test on linear regression model coefficients
dwtestDurbin-Watson test with linear regression model object


plotScatter plot or added variable plot of linear regression model
plotAddedAdded variable plot of linear regression model
plotAdjustedResponseAdjusted response plot of linear regression model
plotDiagnosticsPlot observation diagnostics of linear regression model
plotEffectsPlot main effects of predictors in linear regression model
plotInteractionPlot interaction effects of two predictors in linear regression model
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
plotResidualsPlot residuals of linear regression model
plotSlicePlot of slices through fitted linear regression surface


fitrlinearFit linear regression model to high-dimensional data

使用 RegressionLinear 对象

predictPredict response of linear regression model
lossRegression loss for linear regression models
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
selectModelsSelect fitted regularized linear regression models

使用 RegressionPartitionedLinear 对象

kfoldLossRegression loss for observations not used in training
kfoldPredictPredict responses for observations not used for training


dwtestDurbin-Watson test with residual inputs
invpredInverse prediction
linhyptestLinear hypothesis test
plsregressPartial least-squares regression
regstatsRegression diagnostics
relieffRank importance of predictors using ReliefF or RReliefF algorithm
robustfitFit robust linear regression
stepwisefitFit linear regression model using stepwise regression


x2fxConvert predictor matrix to design matrix
dummyvarCreate dummy variables


robustdemoInteractive robust regression
rsmdemoInteractive response surface demonstration
rstoolInteractive response surface modeling
stepwiseInteractive stepwise regression



What Is a Linear Regression Model?

Regression models describe the relationship between a dependent variable and one or more independent variables.

Linear Regression

Fit a linear regression model and examine the result.

Stepwise Regression

In stepwise regression, predictors are automatically added to or trimmed from a model.

Reduce Outlier Effects Using Robust Regression

Fit a robust model that is less sensitive than ordinary least squares to large changes in small parts of the data.

Choose a Regression Function

Choose a regression function depending on the type of regression problem, and update legacy code using new fitting functions.

Summary of Output and Diagnostic Statistics

Evaluate a fitted model by using model properties and object functions.

Wilkinson Notation

Wilkinson notation provides a way to describe regression and repeated measures models without specifying coefficient values.


Linear Regression Workflow

Import and prepare data, fit a linear regression model, test and improve its quality, and share the model.

Interpret Linear Regression Results

Display and interpret linear regression output statistics.

Linear Regression with Interaction Effects

Construct and analyze a linear regression model with interaction effects and interpret the results.

Linear Regression Using Tables

This example shows how to perform linear and stepwise regression analyses using tables.

Linear Regression with Categorical Covariates

Perform a regression with categorical covariates using categorical arrays and fitlm.

Analyze Time Series Data

This example shows how to visualize and analyze time series data using a timeseries object and the regress function.

Train Linear Regression Model

Train linear regression model using fitlm to analyze in-memory data and out-of-memory data.


Partial Least Squares

Partial least squares (PLS) constructs new predictor variables as linear combinations of the original predictor variables, while considering the observed response values, leading to a parsimonious model with reliable predictive power.


此示例说明如何应用偏最小二乘回归 (PLSR) 和主成分回归 (PCR),并讨论这两种方法的有效性。当存在大量预测变量并且它们高度相关甚至共线时,PLSR 和 PCR 都可以作为建模响应变量的方法。这两种方法都将新的预测变量(称为成分)构建为原始预测变量的线性组合,但它们构建这些成分的方式不同。PCR 创建成分来解释在预测变量中观察到的变异性,而根本不考虑响应变量。而 PLSR 会考虑响应变量,因此常使模型能够拟合具有更少成分的响应变量。从实际应用上来说,这能否最终转化为更简约的模型要视情况而定。