classificationLinearComponent
Pipeline component for binary classification of high-dimensional data using linear model
Since R2026a
Description
classificationLinearComponent is a pipeline component that creates a linear
model for binary classification. The pipeline component uses the functionality of the
fitclinear function during the learn phase to train the linear classification
model. The component uses the functionality of the predict and loss functions during the run phase to perform
classification.
Creation
Syntax
Description
creates a pipeline component for a linear model for binary classification.component = classificationLinearComponent
sets writable Properties using one or more
name-value arguments. For example, you can specify the type of linear classification
model, the technique used to minimize the objective function, and the learning
rate.component = classificationLinearComponent(Name=Value)
Properties
Structural Parameters
The software sets structural parameters when you create the component. You cannot modify structural parameters after creating the component.
This property is read-only after the component is created.
Observation weights flag, specified as 0 (false)
or 1 (true). If UseWeights is
true, the component adds a third input "Weights" to the
Inputs component property, and a third input tag
3 to the InputTags component
property.
Example: c = classificationLinearComponent(UseWeights=1)
Data Types: logical
Learn Parameters
The software sets learn parameters when you create the component. You can modify learn
parameters using dot notation any time before you use the learn object
function. Any unset learn parameters use the corresponding default values.
Maximal number of batches to process, specified as a positive integer. When the
component processes BatchLimit batches, optimization terminates.
If you specify BatchLimit, the component uses the argument that
results in processing the fewest observations, either BatchLimit
or PassLimit.
This property is valid only when Solver is
"sgd" or "asgd".
If you specify multiple solvers and use the average stochastic gradient descent
(ASGD) to get an initial approximation for the next solver, the default value is
ceil(1e6/. Otherwise, the component passes through the data
BatchSize)PassLimit times by default.
Example: c =
classificationLinearComponent(BatchLimit=100)
Example: c.BatchLimit = 500
Data Types: single | double
Mini-batch size, specified as a positive integer. At each iteration, the component
estimates the subgradient using BatchSize observations from the
first data argument of learn.
This property is valid only when Solver is
"sgd" or "asgd".
The default value is 10 if the first data argument of
learn is a numeric matrix. If the first data argument is a
sparse matrix, the component uses the value
max([10,ceil(sqrt(ff))]), where
ff=numel(X)/nnx(X) and X is the first data
argument of learn.
Example: c =
classificationLinearComponent(BatchSize=100)
Example: c.BatchSize = 50
Data Types: single | double
Initial linear coefficient estimates, specified as a
p-dimensional numeric vector or a
p-by-L numeric matrix. p is
the number of predictor variables after dummy variables are created for categorical
variables, and L is the number of regularization-strength values in
Lambda.
The component optimizes the objective function L times.
If you specify a p-dimensional vector, the component uses
Betaas the initial value for the first optimization. For each subsequent optimization, the component uses the estimate from the previous optimization as the initial value.If you specify a p-by-L matrix, at iteration j, the component uses
Beta(:,j)as the initial value.
When Solver is
"dual", the component ignores Beta.
Data Types: single | double
Relative tolerance on the linear coefficients and the bias term (intercept), specified as a nonnegative scalar.
Let , that is, the vector of the coefficients and the bias term at optimization iteration t. If , then optimization terminates.
When Solver is
"dual" and you also specify DeltaGradientTolerance, optimization terminates when the component
satisfies either stopping criterion. When Solver is
"bfgs", "lbfgs", or
"sparsa" and you also specify GradientTolerance, optimization terminates when the component satisfies
either stopping criterion.
If the component converges for the last solver specified in
Solver, then optimization terminates. Otherwise, the component
uses the next solver specified in Solver.
Example: c =
classificationLinearComponent(BetaTolerance=1e-6)
Example: c.BetaTolerance = 1e-5
Data Types: single | double
Initial intercept estimate, specified as a numeric scalar or an
L-dimensional numeric vector. L is the number
of regularization-strength values in Lambda.
The component optimizes the objective function L times.
If you specify a scalar, the component uses
Biasas the initial value for the first optimization. For each subsequent iteration, the component uses the estimate from the previous optimization as the initial value.If you specify an L-dimensional vector, at iteration j, the component uses
Bias(j)as the initial value.
The default value of Bias depends on the value of Learner.
If
Learneris"logistic", then let gj be1if the jth element of the second data argument oflearnis the positive class, and-1otherwise.Biasis the weighted average of g.If
Learneris"svm", thenBiasis0.
Example: c =
classificationLinearComponent(Bias=0.5)
Example: c.Bias = 0
Data Types: single | double
Misclassification cost, specified as a square matrix or a structure.
If
Costis a square matrix,Cost(i,j)is the cost of classifying a point into classjif its true class isi.If
Costis a structureS, it has two fields:S.ClassificationCosts, which contains the cost matrix; andS.ClassNames, which contains the group names and defines the class order of the rows and columns of the cost matrix.
The default is Cost(i,j)=1 if i~=j, and
Cost(i,j)=0 if i=j.
Example: c = classificationLinearComponent(Cost=[0 1; 2
0])
Example: c.Cost = [0 2; 1 0]
Data Types: single | double | struct
Gradient-difference tolerance between the upper and lower pool Karush-Kuhn-Tucker (KKT)
complementarity conditions, specified as a nonnegative scalar. If the
magnitude of the KKT violators is less than DeltaGradientTolerance,
optimization terminates.
If the component converges for the last solver specified in Solver,
optimization terminates. Otherwise, the component uses the next solver specified in
Solver.
This property is valid only when Solver is
"dual".
Example: c =
classificationLinearComponent(DeltaGradientTolerance=1e-2)
Example: c.DeltaGradientTolerance = 0.1
Data Types: single | double
Linear model intercept inclusion flag, specified as 1
(true) or 0 (false).
If you specify FitBias as true, the
component includes the bias term b in the linear model and
estimates the bias term. Otherwise, the component sets b =
0 during estimation.
Example: c =
classificationLinearComponent(FitBias=false)
Example: c.FitBias = true
Data Types: logical
Absolute gradient tolerance, specified as a nonnegative scalar.
Let be the gradient vector of the objective function with respect to the coefficients and bias term at optimization iteration t. If , then optimization terminates.
If you also specify BetaTolerance, then optimization terminates when the software satisfies
either stopping criterion.
This property is valid only when Solver is
"bfgs", "lbfgs", or
"sparsa".
Example: c =
classificationLinearComponent(GradientTolerance=1e-7)
Example: c.GradientTolerance = 1e-5
Data Types: single | double
Size of the history buffer for the Hessian approximation, specified as a positive
integer. At each iteration, the component composes the Hessian using statistics from
the latest HessianHistorySize iterations.
This property is valid only when Solver is
"bfgs" or "lbfgs".
Example: c =
classificationLinearComponent(HessianHistorySize=10)
Example: c.HessianHistorySize = 20
Data Types: single | double
Maximal number of optimization iterations, specified as a positive integer.
This property is valid only when Solver is
"bfgs", "lbfgs", or
"sparsa".
Example: c =
classificationLinearComponent(IterationLimit=500)
Example: c.IterationLimit = 700
Data Types: single | double
Regularization term strength, specified as "auto", a
nonnegative scalar, or a vector of nonnegative values.
If you specify "auto", the value of Lambda
is 1/n, where n is the number of observations in
the first data argument of learn.
If you specify a vector of nonnegative values, the component sequentially
optimizes the objective function for each distinct value in
Lambda in ascending order and computes coefficient estimates
for each specified regularization strength, as follows:
The component uses the previous coefficient estimate as the initial estimate for the next optimization iteration unless
Solveris"sgd"or"asgd"andRegularizationis"lasso".If
Regularizationis"lasso", any coefficient estimate of0retains its value when the component optimizes the objective function using subsequent values inLambda.
Example: c =
classificationLinearComponent(Lambda=10.^(-(10:-2:2)))
Example: c.Lambda = "auto"
Data Types: single | double | char | string
Linear classification model type, specified as "svm" or
"logistic".
If you specify "svm", the component uses a support vector
machine algorithm for linear classification. If you specify
"logistic", the component uses a logistic regression algorithm
for linear classification.
Example: c =
classificationLinearComponent(Learner="logistic")
Example: c.Learner = "svm"
Data Types: char | string
Learning rate, specified as a positive scalar. LearnRate
controls the optimization step size by scaling the subgradient.
This property is valid only when Solver is
"sgd" or "asgd".
If Regularization is "lassso",
LearnRate is constant for all iterations.
If Regularization is "ridge",
LearnRate specifies the initial learning rate
γ0. The component determines the learning
rate for iteration t, γt, using
By default, LearnRate is
1./sqrt(1+max((sum(X.^2,2)))), where X is the
first input value used by learn.
Example: c =
classificationLinearComponent(LearnRate=0.01)
Example: c.LearnRate = 0.1
Data Types: single | double
Data to process before the next convergence check, specified as a positive integer.
If
Solveris"sgd"or"asgd",NumCheckConvergencespecifies the number of batches to process before the next convergence check. By default, the component checks for convergence about 10 times per pass through the entire data set.If
Solveris"dual",NumCheckConvergencespecifies the number of passes through the entire data set to process before the next convergence check. By default, the component passes through the data set five times.
Example: c =
classificationLinearComponent(NumCheckConvergence=100)
Example: c.NumCheckConvergence = 10
Data Types: single | double
Flag to decrease the learning rate when the component detects divergence,
specified as 1 (true) or 0
(false).
If OptimizeLearnRate is true, the
component starts optimizing using LearnRate
as the learning rate. If the value of the objective function increases, the component
restarts and uses half of LearnRate as the learning rate. This
process continues until the objective function decreases.
This property is valid only when Solver is
"sgd" or "asgd".
Example: c =
classificationLinearComponent(OptimizeLearnRate=false)
Example: c.OptimizeLearnRate = true
Data Types: logical
Maximal number of passes through the data, specified as a positive integer. When
the component passes through the data PassLimit times,
optimization terminates.
If you specify BatchLimit,
the component uses the argument that results in processing the fewest observations,
either BatchLimit or PassLimit.
When Solver is
"sgd" or "asgd", the default value is
1. When Solver is "dual",
the default value is 10.
Example: c =
classificationLinearComponent(PassLimit=5)
Example: c.PassLimit = 10
Data Types: single | double
Flag to fit the linear model intercept after optimization, specified as
0 (false) or 1
(true).
When PostFitBias is false, the component
estimates the bias term and coefficients during optimization. Otherwise, after
optimization, the component estimates the bias terms, coefficients, and classification
scores before refitting the bias term.
This property is valid only when FitBias is
true.
Example: c =
classificationLinearComponent(PostFitBias=true)
Example: c.PostFitBias = false
Data Types: logical
Prior probabilities for each class, specified as a value in this table.
| Value | Description |
|---|---|
"empirical" | The class prior probabilities are the class relative frequencies. The class relative
frequencies are determined by the second data argument of
learn. |
"uniform" | All class prior probabilities are equal to 1/K, where K is the number of classes. |
| numeric vector | A numeric vector with one value for each class. Each element is a class prior probability.
The component normalizes the elements such that they sum to
1. |
| structure | A structure
|
If you set UseWeights to true, the component
renormalizes the weights to add up to the value of the prior probability in
the respective class.
Example: c = classificationLinearComponent(Prior="uniform")
Example: c.Prior = "empirical"
Data Types: single | double | char | string | struct
Complexity penalty type, specified as "lasso" or
"ridge". The component composes the objective function for
minimization from the sum of the average loss function and the specified
regularization term.
| Value | Description |
|---|---|
"lasso" | Lasso (L1) penalty: |
"ridge" | Ridge (L2) penalty: |
To specify the regularization term strength (λ), use Lambda. The
component excludes the bias term from the regularization penalty.
If Solver is
"sparsa", the default value of Regularization
is "lasso". Otherwise, the default is
"ridge".
Example: c =
classificationLinearComponent(Regularization="lasso")
Example: c.Regularization = "ridge"
Data Types: char | string
Objective function minimization technique, specified as a character vector or string scalar, a string array, or a cell array of character vectors with values from this table.
| Value | Description | Restrictions |
|---|---|---|
"sgd" | Stochastic gradient descent (SGD) | None |
"asgd" | Average stochastic gradient descent (ASGD) | None |
"dual" | Dual SGD for support vector machine (SVM) | Regularization must be "ridge" and Learner must be "svm". |
"bfgs" | Broyden–Fletcher–Goldfarb–Shanno quasi-Newton algorithm (BFGS) | Regularization must be
"ridge". |
"lbfgs" | Limited-memory BFGS (LBFGS) | Regularization must be
"ridge". |
"sparsa" | Sparse reconstruction by separable approximation (SpaRSA) | Regularization must be
"lasso". |
If you specify multiple solvers, then, for each value in Lambda, the
component uses the solutions of the previous solver as a warm start for the next
solver.
The default value of Solver depends on other property values
and the number of predictor variables.
If
Regularizationis"ridge"and the first data argument oflearncontains 100 or fewer predictor variables, thenSolveris"bfgs".If
Learneris"svm",Regularizationis"ridge", and the first data argument oflearncontains more than 100 predictor variables, thenSolveris"dual".If
Regularizationis"lasso"and the first data argument oflearncontains 100 or fewer predictor variables, thenSolveris"sparsa".Otherwise, the default solver is
"sgd".
For more information on selecting solvers, see Solver.
Example: c =
classificationLinearComponent(Solver=["sgd","lbfgs"])
Example: c.Solver = "sparsa"
Data Types: char | string | cell
Number of mini-batches between the lasso truncation runs, specified as a positive integer.
This property is valid only when Solver is
"sgd" or "asgd" and Regularization is "lasso".
After a truncation run, the component applies a soft threshold to the linear
coefficients. That is, after processing k =
TruncationPeriod mini-batches, the component truncates the
estimated coefficient j using
When
Solveris"sgd", is the estimate of coefficient j after the component processes k mini-batches. γt is the learning rate at iteration t. λ is the value ofLambda.When
Solveris"asgd", is the averaged estimate coefficient j after the component processes k mini-batches.
Example: c =
classificationLinearComponent(TruncationPeriod=100)
Example: c.TruncationPeriod = 50
Data Types: single | double
Run Parameters
The software sets run parameters when you create the component. You can modify the run parameters using dot notation at any time. Any unset run parameters use the corresponding default values.
Loss function, specified as a built-in loss function name or a function handle.
This table lists the available built-in loss functions.
| Value | Description |
|---|---|
"binodeviance" | Binomial deviance |
"classifcost" | Observed misclassification cost |
"classiferror" | Misclassified rate in decimal |
"exponential" | Exponential loss |
"hinge" | Hinge loss |
"logit" | Logistic loss |
"mincost" | Minimal expected misclassification cost (for classification scores that are posterior probabilities) |
"quadratic" | Quadratic loss |
To specify a custom loss function, use function handle notation. For more
information on custom loss functions, see LossFun.
Example: c =
classificationLinearComponent(LossFun="classifcost")
Example: c.LossFun = "hinge"
Data Types: char | string | function_handle
Score transformation, specified as a built-in function name or a function handle.
This table summarizes the available built-in score transform functions.
| Value | Description |
|---|---|
"doublelogit" | 1/(1 + e–2x) |
"invlogit" | log(x / (1 – x)) |
"ismax" | Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0 |
"logit" | 1/(1 + e–x) |
"none" or "identity" | x (no transformation) |
"sign" | –1 for x < 0 0 for x = 0 1 for x > 0 |
"symmetric" | 2x – 1 |
"symmetricismax" | Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1 |
"symmetriclogit" | 2/(1 + e–x) – 1 |
To specify a custom score transform function, use function handle notation. The function must accept a matrix containing the original scores and return a matrix of the same size containing the transformed scores.
Example: c = classificationLinearComponent(ScoreTransform="logit")
Example: c.ScoreTransform = "symmetric"
Data Types: char | string | function_handle
Component Properties
The software sets component properties when you create the component. You can modify the
component properties (excluding HasLearnables and
HasLearned) using dot notation at any time. You cannot modify the
HasLearnables and HasLearned properties
directly.
Component identifier, specified as a character vector or string scalar.
Example: c =
classificationLinearComponent(Name="Linear")
Example: c.Name = "LinearClassifier"
Data Types: char | string
Names of the input ports, specified as a character vector, string array, or cell
array of character vectors. If UseWeights is true, the component adds the input port
"Weights" to Inputs.
Example: c =
classificationLinearComponent(Inputs=["X","Y"])
Example: c.Inputs = ["In1","In2"]
Data Types: char | string | cell
Names of the output ports, specified as a character vector, string array, or cell array of character vectors.
Example: c =
classificationLinearComponent(Outputs=["Class","ClassScore","LossVal"])
Example: c.Outputs = ["X","Y","Z"]
Data Types: char | string | cell
Tags that enable the automatic connection of the component inputs with other
components or pipelines, specified as a nonnegative integer vector. If you specify
InputTags, the number of tags must match the number of inputs
in Inputs. If
UseWeights is true, the component adds a third input
tag to InputTags.
Example: c = classificationLinearComponent(InputTags=[1
0])
Example: c.InputTags = [0 1]
Data Types: single | double
Tags that enable the automatic connection of the component outputs with other
components or pipelines, specified as a nonnegative integer vector. If you specify
OutputTags, the number of tags must match the number of outputs
in Outputs.
Example: c = classificationLinearComponent(OutputTags=[1 0
4])
Example: c.OutputTags=[1 2 0]
Data Types: single | double
This property is read-only.
Indicator for learnables, returned as 1
(true). A value of 1 indicates that the
component contains Learnables.
Data Types: logical
This property is read-only.
Indicator showing the learning status of the component, returned as
0 (false) or 1
(true). A value of 1 indicates that the
learn object function has been applied to the component, and
the Learnables are nonempty.
Data Types: logical
Learnables
The software sets learnables when you use the learn object
function. You cannot modify learnables directly.
This property is read-only.
Trained model, returned as a ClassificationLinear model object.
Object Functions
learn | Initialize and evaluate pipeline or component |
run | Execute pipeline or component for inference after learning |
reset | Reset pipeline or component |
series | Connect components in series to create pipeline |
parallel | Connect components or pipelines in parallel to create pipeline |
view | View diagram of pipeline inputs, outputs, components, and connections |
Examples
Create a classificationLinearComponent pipeline component.
component = classificationLinearComponent
component =
classificationLinearComponent with properties:
Name: "ClassificationLinear"
Inputs: ["Predictors" "Response"]
InputTags: [1 2]
Outputs: ["Predictions" "Scores" "Loss"]
OutputTags: [1 0 0]
Learnables (HasLearned = false)
TrainedModel: []
Structural Parameters (locked)
UseWeights: 0
Show all parameters
component is a classificationLinearComponent
object that contains one learnable, TrainedModel. This property
remains empty until you pass data to the component during the learn phase.
To use a logistic linear classification model, set the Learner
property of the component to "logistic".
component.Learner = "logistic";Load the ionosphere data set and save the data in two tables.
load ionosphere
X = array2table(X);
Y = array2table(Y);Train the classificationLinearComponent object using the
learn object function.
component = learn(component,X,Y)
component =
classificationLinearComponent with properties:
Name: "ClassificationLinear"
Inputs: ["Predictors" "Response"]
InputTags: [1 2]
Outputs: ["Predictions" "Scores" "Loss"]
OutputTags: [1 0 0]
Learnables (HasLearned = true)
TrainedModel: [1×1 ClassificationLinear]
Structural Parameters (locked)
UseWeights: 0
Learn Parameters (locked)
Learner: 'logistic'
Show all parameters
Note that the HasLearned property is set to
true, which indicates that the software trained the linear model
TrainedModel. You can use component to
classify new data using the run function.
Version History
Introduced in R2026a
See Also
fitclinear | predict | loss
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)