featureSelectionClassificationChi2Component
Pipeline component for performing feature selection using chi-square tests
Since R2026a
Description
featureSelectionClassificationChi2Component is a pipeline
component that performs feature selection using chi-square tests. The pipeline component uses
the functionality of the fscchi2 function
during the learn phase to identify the important predictors in the data. During the run phase,
the component selects the same predictors from a new data set.
Creation
Syntax
Description
creates a pipeline component for feature selection using chi-square tests. Use the
component when creating a pipeline for classification.component = featureSelectionClassificationChi2Component
sets writable Properties using one or more
name-value arguments. For example, component = featureSelectionClassificationChi2Component(Name=Value)NumFeatures=10 specifies to select
10 important features.
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 "W" to the Inputs
component property, and a third input tag 3 to the InputTags
component property.
Example: c =
featureSelectionClassificationChi2Component(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.
Number of features (predictors) to select, specified as a positive integer scalar.
If you do not specify the NumFeatures or RelativeScoreThreshold value, the software selects all features. You
cannot specify both NumFeatures and
RelativeScoreThreshold.
Example: c =
featureSelectionClassificationChi2Component(NumFeatures=5)
Example: c.NumFeatures = 10
Data Types: single | double
Relative score threshold for selecting features, specified as a numeric scalar in the range (0,1].
When the maximum feature (predictor) score is a finite value smax, the software selects a feature with score s if s/smax is greater than or equal to the
RelativeScoreThresholdvalue.When the maximum feature score is infinite, the software selects each feature with an
Infscore.
If you do not specify the NumFeatures
or RelativeScoreThreshold value, the software selects all
features. You cannot specify both NumFeatures and
RelativeScoreThreshold.
Example: c =
featureSelectionClassificationChi2Component(RelativeScoreThreshold=0.5)
Example: c.RelativeScoreThreshold = 0.75
Data Types: single | double
Number of bins for binning continuous features (predictors), specified as a positive integer scalar.
Example: c =
featureSelectionClassificationChi2Component(NumBins=20)
Example: c.NumBins = 10
Data Types: single | double
Prior probabilities for each class, specified as a value in this table.
| Value | Description |
|---|---|
"empirical" | The class prior probabilities are the class relative frequencies in the
second input argument of learn used by the
component. |
"uniform" | All class prior probabilities are equal to 1/K, where K is the number of classes. |
| numeric vector | A vector with one scalar value for each class. Each element is a class
prior probability. The component normalizes the elements such that they sum to
1. |
| structure array | 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 =
featureSelectionClassificationChi2Component(Prior="uniform")
Example: c.Prior = "empirical"
Data Types: single | double | char | string | struct
Indicator to use missing values in the features (predictors), specified as either
true to use the values for feature ranking and selection, or
false to discard the values. For more information, see UseMissing.
Example: c =
featureSelectionClassificationChi2Component(UseMissing=true)
Example: c.UseMissing = false
Data Types: logical
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 =
featureSelectionClassificationChi2Component(Name="FeatureSelector")
Example: c.Name = "Chi2Selector"
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 "W"
to Inputs.
Example: c =
featureSelectionClassificationChi2Component(Inputs=["Data1","Data2"])
Example: c.Inputs = ["X1","Y1"]
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 =
featureSelectionClassificationChi2Component(Outputs=["newX","importance"])
Example: c.Outputs = ["X","S"]
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 =
featureSelectionClassificationChi2Component(InputTags=[1
0])
Example: c.InputTags = [1 2]
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 = featureSelectionClassificationChi2Component(OutputTags=[1
0])
Example: c.OutputTags = [1 NaN]
Data Types: single | double
This property is read-only.
Indicator for the 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.
Names of the features selected by the component, returned as a string array. The
features correspond to columns in the first data argument of
learn.
Data Types: string
This property is read-only.
Names of the variables used by the component to select features, returned as a
string array. The variables correspond to columns in the first data argument of
learn.
Data Types: string
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 pipeline component that performs feature selection using chi-square tests in a classification workflow. Specify to select 3 features.
component = featureSelectionClassificationChi2Component(NumFeatures=3)
component =
featureSelectionClassificationChi2Component with properties:
Name: "FeatureSelectionClassificationChi2"
Inputs: ["X" "Y"]
InputTags: [1 2]
Outputs: ["XSelected" "Scores"]
OutputTags: [1 NaN]
Learnables (HasLearned = false)
SelectedVariables: []
UsedVariables: []
Structural Parameters (locked)
UseWeights: 0
Learn Parameters (unlocked)
NumFeatures: 3
Show all parameterscomponent is a
featureSelectionClassificationChi2Component object that contains two
learnables: SelectedVariables and UsedVariables.
The properties remain empty until you pass data to the component during the learn
phase.
Read the fisheriris data set into a table. Store the predictor
and response data in the tables X and Y,
respectively.
fisheriris = readtable("fisheriris.csv");
X = fisheriris(:,1:end-1);
Y = fisheriris(:,end);Use the learn object function to select features from the
predictor data X.
component = learn(component,X,Y)
component =
featureSelectionClassificationChi2Component with properties:
Name: "FeatureSelectionClassificationChi2"
Inputs: ["X" "Y"]
InputTags: [1 2]
Outputs: ["XSelected" "Scores"]
OutputTags: [1 NaN]
Learnables (HasLearned = true)
SelectedVariables: ["PetalWidth" "PetalLength" "SepalLength"]
UsedVariables: ["SepalLength" "SepalWidth" "PetalLength" "PetalWidth"]
Structural Parameters (locked)
UseWeights: 0
Learn Parameters (locked)
NumFeatures: 3
Show all parametersThe SelectedVariables and UsedVariables
properties are nonempty, and the HasLearned property is set to
true.
Find the names of the selected features.
names = component.SelectedVariables
names =
1×3 string array
"PetalWidth" "PetalLength" "SepalLength"Version History
Introduced in R2026a
See Also
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)