Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

模型的构建和评估

特征选择、特征工程、模型选择、超参数优化、交叉验证、残差诊断和绘图

在构建高质量回归模型时,选择正确的特征(或预测变量)、调整超参数(未与数据拟合的模型参数)以及通过残差诊断评估模型假设非常重要。

您可以先为超参数选择值,然后使用您选择的值对模型进行交叉验证,通过这样的迭代对超参数进行调整。这个过程会生成多个模型,其中估计的泛化误差最小的可能是最佳模型。例如,要调整 SVM 模型,可以选择一组框约束和核尺度,使用每对值对模型进行交叉验证,然后比较它们的 10 折交叉验证均方误差估计值。

要在训练回归模型之前对新函数进行工程处理,请使用 genrfeatures

要以交互方式构建和评估回归模型,请使用回归学习器

要自动选择具有调整后的超参数的模型,请使用 fitrauto。该函数尝试选择具有不同超参数值的回归模型类型,并返回预期表现良好的最终模型。当您不确定哪些回归模型类型最适合您的数据时,请使用 fitrauto

Statistics and Machine Learning Toolbox™ 中的某些非参数化回归函数通过贝叶斯优化、网格搜索或随机搜索提供自动超参数调整。实现贝叶斯优化的主函数 bayesopt 对于许多其他应用来说也足够灵活。有关详细信息,请参阅Bayesian Optimization Workflow

要解释回归模型,可以使用 limeshapleyplotPartialDependence

App

回归学习器使用有监督机器学习训练回归模型来预测数据

函数

全部展开

fsrftestUnivariate feature ranking for regression using F-tests (自 R2020a 起)
fsrmrmrRank features for regression using minimum redundancy maximum relevance (MRMR) algorithm (自 R2022a 起)
fsrncaFeature selection using neighborhood component analysis for regression
oobPermutedPredictorImportanceOut-of-bag predictor importance estimates for random forest of regression trees by permutation
partialDependenceCompute partial dependence (自 R2020b 起)
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predictorImportanceEstimates of predictor importance for regression tree
predictorImportanceEstimates of predictor importance for regression ensemble of decision trees
relieffRank importance of predictors using ReliefF or RReliefF algorithm
selectFeaturesSelect important features for NCA classification or regression (自 R2023b 起)
sequentialfsSequential feature selection using custom criterion
stepwiselmPerform stepwise regression
stepwiseglmCreate generalized linear regression model by stepwise regression
genrfeaturesPerform automated feature engineering for regression (自 R2021b 起)
describeDescribe generated features (自 R2021a 起)
transformTransform new data using generated features (自 R2021a 起)
fitrautoAutomatically select regression model with optimized hyperparameters (自 R2020b 起)
bayesoptSelect optimal machine learning hyperparameters using Bayesian optimization
hyperparametersVariable descriptions for optimizing a fit function
optimizableVariableVariable description for bayesopt or other optimizers

对于与时间无关的数据

crossvalEstimate loss using cross-validation
cvpartitionPartition data for cross-validation
repartitionRepartition data for cross-validation
testTest indices for cross-validation
trainingTraining indices for cross-validation

对于时间序列数据

tspartitionPartition time series data for cross-validation (自 R2022b 起)
testTest indices for time series cross-validation (自 R2022b 起)
trainingTraining indices for time series cross-validation (自 R2022b 起)

与模型无关的局部可解释性解释 (LIME)

limeLocal interpretable model-agnostic explanations (LIME) (自 R2020b 起)
fitFit simple model of local interpretable model-agnostic explanations (LIME) (自 R2020b 起)
plotPlot results of local interpretable model-agnostic explanations (LIME) (自 R2020b 起)

夏普利值

shapleyShapley values (自 R2021a 起)
fitCompute Shapley values for query points (自 R2021a 起)
plotPlot Shapley values using bar graphs (自 R2021a 起)

部分依赖

partialDependenceCompute partial dependence (自 R2020b 起)
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
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
plotResidualsPlot residuals of linear regression model
plotSlicePlot of slices through fitted linear regression surface
coefCIConfidence intervals of coefficient estimates of generalized linear regression model
coefTestLinear hypothesis test on generalized linear regression model coefficients
devianceTestAnalysis of deviance for generalized linear regression model
plotDiagnosticsPlot observation diagnostics of generalized linear regression model
plotResidualsPlot residuals of generalized linear regression model
plotSlicePlot of slices through fitted generalized linear regression surface
coefCIConfidence intervals of coefficient estimates of nonlinear regression model
coefTestLinear hypothesis test on nonlinear regression model coefficients
plotDiagnosticsPlot diagnostics of nonlinear regression model
plotSlicePlot of slices through fitted nonlinear regression surface
linhyptestLinear hypothesis test

对象

全部展开

FeatureSelectionNCARegressionFeature selection for regression using neighborhood component analysis (NCA)
FeatureTransformerGenerated feature transformations (自 R2021a 起)
BayesianOptimizationBayesian optimization results

主题

回归学习器工作流

特征选择

特征工程

  • Automated Feature Engineering for Regression
    Use genrfeatures to engineer new features before training a regression model. Before making predictions on new data, apply the same feature transformations to the new data set.

自动模型选择

超参数优化

模型解释

交叉验证

线性模型诊断

  • Interpret Linear Regression Results
    Display and interpret linear regression output statistics.
  • Linear Regression
    Fit a linear regression model and examine the result.
  • Linear Regression with Interaction Effects
    Construct and analyze a linear regression model with interaction effects and interpret the results.
  • Summary of Output and Diagnostic Statistics
    Evaluate a fitted model by using model properties and object functions.
  • F-statistic and t-statistic
    In linear regression, the F-statistic is the test statistic for the analysis of variance (ANOVA) approach to test the significance of the model or the components in the model. The t-statistic is useful for making inferences about the regression coefficients.
  • 决定系数(R 方)
    决定系数(R 方)表示线性回归模型中由自变量 X 解释的响应变量 y 的变化比例。
  • Coefficient Standard Errors and Confidence Intervals
    Estimated coefficient variances and covariances capture the precision of regression coefficient estimates.
  • Residuals
    Residuals are useful for detecting outlying y values and checking the linear regression assumptions with respect to the error term in the regression model.
  • Durbin-Watson Test
    The Durbin-Watson test assesses whether or not there is autocorrelation among the residuals of time series data.
  • Cook’s Distance
    Cook's distance is useful for identifying outliers in the X values (observations for predictor variables).
  • Hat Matrix and Leverage
    The hat matrix provides a measure of leverage.
  • Delete-1 Statistics
    Delete-1 change in covariance (CovRatio) identifies the observations that are influential in the regression fit.

广义线性模型诊断

  • Generalized Linear Models
    Generalized linear models use linear methods to describe a potentially nonlinear relationship between predictor terms and a response variable.

非线性模型诊断

  • Nonlinear Regression
    Parametric nonlinear models represent the relationship between a continuous response variable and one or more continuous predictor variables.