MTS
mts
The 'mts' module contains various methods of the MT system.
MSR(*, delta=0.0001, esp=1e-16)
Bases: RegressorMixin, BaseEstimator
MSR: Multiple Single Regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
float
|
Threshold for stopping repeated computations. |
1e-4
|
esp
|
float
|
A constant to avoid zero division. It is used in the calculation as
|
1e-16
|
Attributes:
| Name | Type | Description |
|---|---|---|
mean_X_ |
ndarray of shape(n_features, )
|
Mean values of each feature of the training data. |
mean_y_ |
float
|
Mean value of target values. |
coef_ |
ndarray of shape (n_features, )
|
Estimated coefficients for the MSR. |
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
ndarray of shape (n_features_in_, )
|
Names of features seen during the fit. Defined only if X has feature names that are all strings. |
References
前田誠. (2017). T 法 (1) の考え方を利用した新しい回帰手法の提案. 品質, 47(2), 185-194.
Methods:
| Name | Description |
|---|---|
fit |
Fit the model. |
predict |
Predict using the fitted model. |
Source code in src/mts/_msr.py
fit(X, y)
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Training data. |
required |
y
|
ndarray of shape (n_samples, )
|
Target values. Will be cast to X's dtype if necessary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
self |
object
|
Fitted model. |
Source code in src/mts/_msr.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
predict(X, y=None)
Predict using the fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray of shape (n_samples, )
|
Predicted values. |
Source code in src/mts/_msr.py
MT(*, method='mt', ddof=1, esp=1e-16, kind='specify', a=0.05, threshold=4.0, return_sqrt=False)
Bases: BaseEstimator
MT, MTA and Standardized-Variation-Pressure methods.
The MT, MTA and SVP methods are unsupervised learning methods used for pattern recognition in quality engineering. These methods learn the mean and standard deviation of each feature and the inverse correlation matrix of the training data, and compute MD values based on these values. The training data is called the unit space and usually contains only normal data. The MTA method learns an adjoint matrix instead of an inverse matrix to deal with multicolinearity. The SVP method does not require a correlation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
(mt, mta, svp)
|
Computation method. |
"mt"
|
ddof
|
int
|
It means the delta degrees of freedom. The divisor used in the is
|
1
|
esp
|
float
|
A constant to avoid zero division. It is used in the calculation as
|
1e-16
|
kind
|
(k, f, chi2, specify)
|
The distribution used to determine normal and abnormal thresholds. |
"k"
|
a
|
float
|
Right side significance level. Use to set the threshold when type is
set to |
0.05
|
threshold
|
float
|
Threshold to use when |
4.0
|
return_sqrt
|
bool
|
Return the square root of the MD value or not. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
mean_ |
ndarray of shape (n_features, )
|
Means of each feature of the training data. |
scale_ |
ndarray of shape (n_features, )
|
Standard deviation values of each feature of the training data. |
covariance_ |
ndarray of shape (n_features, n_features)
|
Correlation matrix, variance-covariance matrix, or identity matrix of the training data; correlation matrix if "method" is "mt", variance-covariance matrix if "method" is "mta", or identity matrix if "method" is "svp". |
precision_ |
ndarray of shape (n_features, n_features)
|
The inverse matrix or adjoint matrix of covariance_; if method is svp, then identity matrix. |
dist_ |
ndarray of shape(n_samples, )
|
Mahalanobis distances of the training set (on which the fit is called) observations. |
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
ndarray of shape (n_features_in_, )
|
Names of features seen during the fit. Defined only if X has feature names that are all strings. |
Methods:
| Name | Description |
|---|---|
fit |
Fit the model. |
predict |
Predict the labels of X according to the fitted model. |
fit_predict |
Perform Fit to X and Return Labels for X. |
mahalanobis |
Compute the Mahalanobis distances (MD values). |
score |
Return the ROCAUC to the given test data and labels. |
score_samples |
Compute the Mahalanobis distances (MD values). |
Source code in src/mts/_mt.py
fit(X, y=None)
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Training data. |
required |
y
|
None
|
Ignore |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
object
|
Fitted model. |
Source code in src/mts/_mt.py
predict(X, y=None)
Predict the labels of X according to the fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
labels |
ndarray of shape (n_samples, )
|
Returns 1 for anomalies/outliers and 0 for inliers. |
Source code in src/mts/_mt.py
fit_predict(X, y=None)
Perform Fit to X and Return Labels for X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Input data. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
labels |
ndarray of shape (n_samples, )
|
Returns 1 for anomalies/outliers and 0 for inliers. |
Source code in src/mts/_mt.py
mahalanobis(X)
Compute the Mahalanobis distances (MD values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MD |
ndarray of shape (n_samples, )
|
Mahalanobis distances (MD values). |
Source code in src/mts/_mt.py
score(X, y)
Return the ROCAUC to the given test data and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Test samples. |
required |
y
|
ndarray of shape (n_samples, )
|
True labels for X. 1 for anomalies/outliers and 0 for inliers. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
ROCAUC. |
Source code in src/mts/_mt.py
score_samples(X)
Compute the Mahalanobis distances (MD values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MD |
ndarray of shape (n_samples, )
|
MD values. |
Source code in src/mts/_mt.py
RT(*, ddof=1, esp=1e-16, threshold=4.0, return_sqrt=False)
Bases: BaseEstimator
RT method.
The RT method is an unsupervised learning method used for pattern recognition in quality engineering. The method learns the mean of each feature in unit space, the sensitivity and SN ratio of each sample, and the associated covariance matrix of the sensitivity and SN ratio, and computes MD values based on these values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ddof
|
int
|
It means the delta degrees of freedom. The divisor used in the is
|
1
|
esp
|
float
|
A constant to avoid zero division. It is used in the calculation as
|
1e-16
|
threshold
|
float
|
Threshold. A multiple of the standard deviation of the MD values in the unit space. If 4, threshold is 4 sigma. |
4.0
|
return_sqrt
|
bool
|
Return the square root of the MD values or not. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
mean_X_ |
ndarray of shape (n_features, )
|
Mean values of each feature of the training data. |
mean_Y_ |
ndarray of shape (2, )
|
Means of sensitivity and error variance reciprocals. Mean_Y_[0] |
covariance_ |
ndarray of shape (2, 2)
|
Variance-covariance matrix of sensitivity and error variance reciprocal. |
precision_ |
ndarray of shape (2, 2)
|
Adjoint matrix of |
dist_ |
ndarray of shape(n_samples, )
|
Mahalanobis distances of the training set (on which the fit is called) observations. |
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
ndarray of shape (n_features_in_, )
|
Names of features seen during the fit. Defined only if X has feature names that are all strings. |
Methods:
| Name | Description |
|---|---|
fit |
Fit the model. |
predict |
Predict the labels of X according to the fitted model. |
fit_predict |
Perform Fit to X and Return Labels for X. |
mahalanobis |
Compute the Mahalanobis distances (MD values). |
score |
Return the ROCAUC to the given test data and labels. |
score_samples |
Compute the Mahalanobis distances (MD values). |
Source code in src/mts/_rt.py
fit(X, y=None)
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Training data. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
object
|
Fitted model. |
Source code in src/mts/_rt.py
predict(X, y=None)
Predict the labels of X according to the fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
labels |
ndarray of shape (n_samples, )
|
Returns 1 for anomalies/outliers and 0 for inliers. |
Source code in src/mts/_rt.py
fit_predict(X, y=None)
Perform Fit to X and Return Labels for X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Input data. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
labels |
ndarray of shape (n_samples, )
|
Returns 1 for anomalies/outliers and 0 for inliers. |
Source code in src/mts/_rt.py
mahalanobis(X)
Compute the Mahalanobis distances (MD values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MD |
ndarray of shape (n_samples, )
|
Mahalanobis distances (MD values). |
Source code in src/mts/_rt.py
score(X, y)
Return the ROCAUC to the given test data and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Test samples. |
required |
y
|
ndarray of shape (n_samples, )
|
True labels for X. 1 for anomalies/outliers and 0 for inliers. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
ROCAUC. |
Source code in src/mts/_rt.py
score_samples(X)
Compute the Mahalanobis distances (MD values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MD |
ndarray of shape (n_samples, )
|
MD values. |
Source code in src/mts/_rt.py
T(*, tb=False, esp=1e-16, is_simplified=False)
Bases: RegressorMixin, BaseEstimator
T(1), T(2), Ta and Tb methods.
The T(1), T(2), Ta and Tb methods are supervised learning methods used for regression in quality engineering. The T(1) and T(2) methods divide the training data into unit space and signal data, and learn the mean from the unit space and the sensitivity and SN ratio from the signal data. The Ta method does not divide the training data into unit space and signal data, and learns the mean, sensitivity, and SN ratio from all the training data. The Tb method also learns from all training data, but for each element, the sample with the largest SN ratio is used as the mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tb
|
bool
|
Whether to compute as Tb method. If False, compute as T(1), T(2), and Ta methods. |
False
|
esp
|
float
|
A constant to avoid zero division. It is used in the calculation as
|
1e-16
|
is_simplified
|
bool
|
Compute the SN ratio using the simplified formula or not. The
simplified formula computes with |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
mean_X_ |
ndarray of shape (n_features, )
|
Mean values of each feature of the training data. |
mean_y_ |
float or ndarray of shape (n_features, )
|
Mean value of target values. |
n_ |
ndarray of shape (n_features, )
|
SN ratio between each feature and the target values. |
b_ |
ndarray of shape (n_features, )
|
Sensitivity between each feature and target values. |
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
ndarray of shape (n_features_in_, )
|
Names of features seen during the fit. Defined only if X has feature names that are all strings. |
Methods:
| Name | Description |
|---|---|
fit |
Fit the model. |
predict |
Predict using the fitted model. |
score |
Return the SN ratio of the integrated estimate. |
Source code in src/mts/_t.py
fit(X, y, *, us_idx=None)
Fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Training data. Includes unit space and signal data. |
required |
y
|
ndarray of shape (n_samples, )
|
Target values. Will be cast to X's dtype if necessary. |
required |
us_idx
|
array_like of shape (n_samples, ) or None
|
A binary array indicating which sample of the training data is the unit space (0 for the unit space, 1 for the signal data); if None, the training data is not divided into the unit space and the signal data, but is computed as the Ta method. It is ignored when the Tb method is computed. |
None.
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
object
|
Fitted model. |
Source code in src/mts/_t.py
predict(X, y=None)
Predict using the fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Samples. |
required |
y
|
None
|
Ignored. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray of shape (n_samples, )
|
Predict values. |
Source code in src/mts/_t.py
score(X, y)
Return the SN ratio of the integrated estimate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray of shape (n_samples, n_features)
|
Test samples. |
required |
y
|
ndarray of shape (n_samples, )
|
True values for X. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
n |
float
|
SN ratio of the integrated estimate. It is computed from M_True and M_Pred for the T(1), T(2) and Ta methods, and from y_True and y_Pred for the Tb method. |