✏️ 正在编辑: transformer.cpython-312.pyc
路径:
/var/opt/nydus/ops/mysql/ai/ml/__pycache__/transformer.cpython-312.pyc
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
� ��'j+ � �| � d Z ddlmZmZ ddlZddlZddlm Z ddl mZ ddlm Z ddlmZ ddlmZ G d � d ee � Zy)z�Generic transformer utilities for MySQL Connector/Python. Provides a scikit-learn compatible Transformer using HeatWave for fit/transform and scoring operations. � )�Optional�UnionN)�TransformerMixin)� MyBaseMLModel)�ML_TASK)� copy_dict)�MySQLConnectionAbstractc �( � e Zd ZdZej dddddfdedeeef dede e de e d e e d e e fd�Zdej d ej fd�Zdeej ej f deej ej f d efd�Zy)�MyGenericTransformera MySQL HeatWave scikit-learn compatible generic transformer. Can be used as the transformation step in an sklearn pipeline. Implements fit, transform, explain, and scoring capability, passing options for server-side transform logic. Args: db_connection (MySQLConnectionAbstract): Active MySQL connector database connection. task (str): ML task type for transformer (default: "classification"). score_metric (str): Scoring metric to request from backend (default: "balanced_accuracy"). model_name (str, optional): Custom name for the deployed model. fit_extra_options (dict, optional): Extra fit options. transform_extra_options (dict, optional): Extra options for transformations. score_extra_options (dict, optional): Extra options for scoring. Attributes: score_metric (str): Name of the backend metric to use for scoring (e.g. "balanced_accuracy"). score_extra_options (dict): Dictionary of optional scoring parameters; passed to backend score. transform_extra_options (dict): Dictionary of inference (/predict) parameters for the backend. fit_extra_options (dict): See MyBaseMLModel. _model (MyModel): Underlying interface for database model operations. Methods: fit(X, y): Fit the underlying model using the provided features/targets. transform(X): Transform features using the backend model. score(X, y): Score data using backend metric and options. �balanced_accuracyN� db_connection�task�score_metric� model_name�fit_extra_options�transform_extra_options�score_extra_optionsc � � t j | ||||�� || _ t |� | _ t |� | _ y)a� Initialize transformer with required and optional arguments. Args: db_connection: Active MySQL backend database connection. task: ML task type for transformer. score_metric: Requested backend scoring metric. model_name: Optional model name for storage. fit_extra_options: Optional extra options for fitting. transform_extra_options: Optional extra options for transformation/inference. score_extra_options: Optional extra scoring options. Raises: DatabaseError: If a database connection issue occurs. If an operational error occurs during execution. )r r N)r �__init__r r r r )�selfr r r r r r r s �H/opt/nydus/tmp/pip-target-k0fmikie/lib/python/mysql/ai/ml/transformer.pyr zMyGenericTransformer.__init__M sG � �6 ������!�/� � )���#,�-@�#A�� �'0�1H�'I��$� �X�returnc �P � | j j || j �� S )aP Transform input data to model predictions using the underlying helper. Args: X: DataFrame of features to predict/transform. Returns: pd.DataFrame: Results of transformation as returned by backend. 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)�_model�predictr )r r s r � transformzMyGenericTransformer.transformu s$ � �( �{�{�"�"�1�d�.J�.J�"�K�Kr �yc �h � | j j ||| j | j �� S )aK Score the transformed data using the backend scoring interface. Args: X: Transformed features. y: Target labels or data for scoring. Returns: float: Score based on backend metric. 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. r )r �scorer r )r r r! s r r# zMyGenericTransformer.score� s5 � �. �{�{� � � �q�$�#�#�T�-E�-E� !� � r )�__name__� __module__�__qualname__�__doc__r �CLASSIFICATIONr r �strr �dictr �pd� DataFramer �np�ndarray�floatr# � r r r r - s� � ��D %,�$:�$:�/�$(�,0�26�.2�&J�.�&J� �C��L�!�&J� � &J� �S�M�&J� $�D�>� &J� "*�$��&J� &�d�^�&J�PL����L� ���L�, �����r�z�z�)�*� � ����r�z�z�)�*� � � r r )r'