/var/opt/nydus/ops/mysql/ai/ml/__pycache__
NameSizeModeActions
base.cpython-312.pyc47860644editdlrm
classifier.cpython-312.pyc75470644editdlrm
model.cpython-312.pyc305340644editdlrm
outlier.cpython-312.pyc80480644editdlrm
regressor.cpython-312.pyc54700644editdlrm
transformer.cpython-312.pyc61060644editdlrm
__init__.cpython-312.pyc7640644editdlrm
Edit: /var/opt/nydus/ops/mysql/ai/ml/__pycache__/outlier.cpython-312.pyc (8048B)
N jdZddlmZmZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZd Zd eeej(fd eeej(ffd ZGd de e Zy)zOutlier/anomaly detection utilities for MySQL Connector/Python. Provides a scikit-learn compatible wrapper using HeatWave to score anomalies. )OptionalUnionN) OutlierMixin) MyBaseMLModel)ML_TASK) copy_dict)MySQLConnectionAbstractgh㈵>probreturnc|tj|tdtz }tj|d|z z S)z Compute logit (logodds) for a probability, clipping to avoid numerical overflow. Args: prob: Scalar or array of probability values in (0,1). Returns: logit-transformed probabilities. )npclipEPSlog)r results D/opt/nydus/tmp/pip-target-a90h98xg/lib/python/mysql/ai/ml/outlier.py _get_logitsr0s2WWT3C (F 66&AJ' ((c DeZdZdZ d dedeedeedeefdZde e je jfd e jfd Zde e je jfd e jfd Zde e je jfd e jfd Zy)MyAnomalyDetectora MySQL HeatWave scikit-learn compatible anomaly/outlier detector. Flags samples as outliers when the probability of being an anomaly exceeds a user-tunable threshold. Includes helpers to obtain decision scores and anomaly probabilities for ranking. Args: db_connection (MySQLConnectionAbstract): Active MySQL DB connection. model_name (str, optional): Custom model name in the database. fit_extra_options (dict, optional): Extra options for fitting. score_extra_options (dict, optional): Extra options for scoring/prediction. Attributes: boundary: Decision threshold boundary in logit space. Derived from trained model's catalog info Methods: predict(X): Predict outlier/inlier labels. score_samples(X): Compute anomaly (normal class) logit scores. decision_function(X): Compute signed score above/below threshold for ranking. N db_connection model_namefit_extra_optionsscore_extra_optionsctj||tj||t ||_d|_y)a2 Initialize an anomaly detector instance with threshold and extra options. Args: db_connection: Active MySQL DB connection. model_name: Optional model name in DB. fit_extra_options: Optional extra fit options. score_extra_options: Optional extra scoring options. Raises: ValueError: If outlier_threshold is not in (0,1). DatabaseError: If a database connection issue occurs. If an operational error occurs during execution. )rrN)r__init__rANOMALY_DETECTIONrrboundary)selfrrrrs rrzMyAnomalyDetector.__init__Ws>,     % %!/  $--@#A )- rXr cTtj|j|dkddS)a Predict outlier/inlier binary labels for input samples. Args: X: Samples to predict on. Returns: ndarray: Values are -1 for outliers, +1 for inliers, as per scikit-learn convention. Raises: DatabaseError: If provided options are invalid or unsupported, or if the model is not initialized, i.e., fit or import has not been called If a database connection issue occurs. If an operational error occurs during execution. DatabaseError: If provided options are invalid or unsupported, or if the model is not initialized, i.e., fit or import has not been called If a database connection issue occurs. If an operational error occurs during execution. gr )rwheredecision_function)r r!s rpredictzMyAnomalyDetector.predictws'6xx..q1C7Q??rc|j|}|jU|j}| td|ddj dd}| tdt d|z |_||jz S)a Compute signed distance to the outlier threshold. Args: X: Samples to predict on. Returns: ndarray: Score > 0 means inlier, < 0 means outlier; |value| gives margin. Raises: DatabaseError: If provided options are invalid or unsupported, or if the model is not initialized, i.e., fit or import has not been called If a database connection issue occurs. If an operational error occurs during execution. ValueError: If the provided model info does not provide threshold Nz Model does not exist in catalog.model_metadatatraining_paramsanomaly_detection_thresholdzzTrained model is outdated and does not support threshold. Try retraining or using an existing, trained model with MyModel.g?) score_samplesrget_model_info ValueErrorgetr)r r! sample_scores model_info thresholds rr%z#MyAnomalyDetector.decision_functions.**1- == ,,.J! !CDD"#345FGKK-tI  W(i8DMt}},,rc|jj||j}t|dj dj S)aJ Compute normal probability logit score for each sample. Used for ranking, thresholding. Args: X: Samples to score. Returns: ndarray: Logit scores based on "normal" class probability. Raises: DatabaseError: If provided options are invalid or unsupported, or if the model is not initialized, i.e., fit or import has not been called If a database connection issue occurs. If an operational error occurs during execution. )options ml_resultsc|ddS)N probabilitiesnormal)xs rz1MyAnomalyDetector.score_samples..sQ/9r)_modelr&rrapplyto_numpy)r r!rs rr+zMyAnomalyDetector.score_samplessJ,$$Q0H0H$I < U9 : XZ  r)NNN)__name__ __module__ __qualname____doc__r rstrdictrrpd DataFramerndarrayr&r%r+r8rrrr>s6%),0.2 ...SM.$D> . &d^ .@@ rzz) *@ @:+- rzz) *+- +-Z rzz) *   rr)rAtypingrrnumpyrpandasrD sklearn.basermysql.ai.ml.basermysql.ai.ml.modelrmysql.ai.utilsrmysql.connector.abstractsr rfloatrFrrr8rrrPsh:#%*%$=  )eE2::-. )5 9J3K )_ |_ r