hyb
2025-11-07 cadac0a99d87c53805a07f3b4ca7fd11e524fe4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
Ë
Wñúhïãó̗dZddlmZmZddlZddlZddlm    Z    ddl
m Z ddl m Z ddlmZddlmZd    Zd
eeej(fd eeej(ffd „ZGd „de e    «Zy)zOutlier/anomaly detection utilities for MySQL Connector/Python.
 
Provides a scikit-learn compatible wrapper using HeatWave to score anomalies.
é)ÚOptionalÚUnionN)Ú OutlierMixin)Ú MyBaseMLModel)ÚML_TASK)Ú    copy_dict)ÚMySQLConnectionAbstractgñh㈵øä>ÚprobÚreturncó|—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.
    é)ÚnpÚclipÚEPSÚlog)r
Úresults  úFH:\Change_password\venv_build\Lib\site-packages\mysql/ai/ml/outlier.pyÚ _get_logitsr0s2€ôW‰WTœ3 ¤C¡Ó (€FÜ 6‰6&˜A ™JÑ'Ó (Ð(óc
óD—eZdZdZ            d dedeedeedeefd„Zde    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_nameÚfit_extra_optionsÚscore_extra_optionscó‚—tj||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__rÚANOMALY_DETECTIONrrÚboundary)Úselfrrrrs     rrzMyAnomalyDetector.__init__Ws>€ô,    ×ÑØ Ø Ü × %Ñ %Ø!Ø/õ     
ô$-Ð-@Ó#AˆÔ Ø)-ˆ rÚXr cóT—tj|j|«dkdd«S)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.
        géÿÿÿÿr )rÚwhereÚdecision_function)r r!s  rÚpredictzMyAnomalyDetector.predictws'€ô6x‰x˜×.Ñ.¨qÓ1°CÑ7¸¸QÓ?Ð?rcó—|j|«}|j€U|j«}|€ td«‚|ddj    dd«}|€ td«‚t 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_metadataÚtraining_paramsÚanomaly_detection_thresholdzzTrained model is outdated and does not support threshold. Try retraining or using an existing, trained model with MyModel.gð?)Ú score_samplesrÚget_model_infoÚ
ValueErrorÚgetr)r r!Ú sample_scoresÚ
model_infoÚ    thresholds     rr%z#MyAnomalyDetector.decision_function”s›€ð.×*Ñ*¨1Ó-ˆ à =‰=Ð  Ø×,Ñ,Ó.ˆJØÐ!Ü Ð!CÓDÐDà"Ð#3Ñ4Ð5FÑG×KÑKØ-¨tóˆIðРܠðWóðô(¨¨i©Ó8ˆDŒMà˜tŸ}™}Ñ,Ð,rcó¨—|jj||j¬«}t|dj    d„«j ««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Ú probabilitiesÚnormal©)Úxs rú<lambda>z1MyAnomalyDetector.score_samples.<locals>.<lambda>Ûs€˜Q˜Ñ/°Ñ9€r)Ú_modelr&rrÚapplyÚto_numpy)r r!rs   rr+zMyAnomalyDetector.score_samplesÁsJ€ð,—‘×$Ñ$ Q°×0HÑ0HÐ$ÓIˆäØ <Ñ  ß ‰UÑ9Ó :ß ‰X‹Zó
ð    
r)NNN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r    rÚstrÚdictrrÚpdÚ    DataFramerÚndarrayr&r%r+r8rrrr>sՄñð6%)Ø,0Ø.2ñ .à.ð.ð˜S‘Mð.ð$ D™>ð    .ð
& d™^ó .ð@@à —‘˜rŸz™zÐ)Ñ *ð@ð
‰ó@ð:+-à —‘˜rŸz™zÐ)Ñ *ð+-ð
‰ó+-ðZ
à —‘˜rŸz™zÐ)Ñ *ð
ð
‰ô
rr)rAÚtypingrrÚnumpyrÚpandasrDÚ sklearn.baserÚmysql.ai.ml.baserÚmysql.ai.ml.modelrÚmysql.ai.utilsrÚmysql.connector.abstractsr    rÚfloatrFrrr8rrú<module>rPshðñ:÷#ãÛÝ%å*Ý%Ý$å=à
€ð )e˜E 2§:¡:Ð-Ñ.ð )°5¸ÀÇ
Á
Ð9JÑ3Kó )ô_
˜  |õ_
r