o
    xig                     @   sj   d Z ddlmZ ddlZddlZddlmZmZ ddl	m
Z
 eded dd
dZdddZdddZdS )z;Define plots for regression models built with scikit-learn.    )simplefilterN)	calculateutils   )sharedignore)actioncategory	Regressorc                 C   sv   t d| d t| |||| t d t| || t d t| || t d t| || t d dS )a+  Generates all sklearn regressor plots supported by W&B.

    The following plots are generated:
        learning curve, summary metrics, residuals plot, outlier candidates.

    Should only be called with a fitted regressor (otherwise an error is thrown).

    Args:
        model: (regressor) Takes in a fitted regressor.
        X_train: (arr) Training set features.
        y_train: (arr) Training set labels.
        X_test: (arr) Test set features.
        y_test: (arr) Test set labels.
        model_name: (str) Model name. Defaults to 'Regressor'

    Returns:
        None: To see plots, go to your W&B run page then expand the 'media' tab
            under 'auto visualizations'.

    Example:
    ```python
    wandb.sklearn.plot_regressor(reg, X_train, X_test, y_train, y_test, "Ridge")
    ```
    z

Plotting .zLogged summary metrics.zLogged learning curve.zLogged outlier candidates.zLogged residuals.N)wandbtermlogr   summary_metricslearning_curveoutlier_candidates	residuals)modelX_trainX_testy_trainy_test
model_name r   \/home/ubuntu/.local/lib/python3.10/site-packages/wandb/integration/sklearn/plot/regressor.py	regressor   s   


r   c                 C   l   t j| ||d}t j| ||d}t | }|r0|r2|r4t|}t| ||}t	d|i dS dS dS dS )a  Measures a datapoint's influence on regression model via cook's distance.

    Instances with high influences could potentially be outliers.

    Should only be called with a fitted regressor (otherwise an error is thrown).

    Please note this function fits the model on the training set when called.

    Args:
        model: (regressor) Takes in a fitted regressor.
        X: (arr) Training set features.
        y: (arr) Training set labels.

    Returns:
        None: To see plots, go to your W&B run page then expand the 'media' tab
              under 'auto visualizations'.

    Example:
    ```python
    wandb.sklearn.plot_outlier_candidates(model, X, y)
    ```
    r   Xyr   N)
r   test_missing
test_typestest_fittednpasarrayr   r   r   log)r   r   r   
is_missingcorrect_types	is_fittedoutliers_chartr   r   r   r   8      

r   c                 C   r   )a  Measures and plots the regressor's predicted value against the residual.

    The marginal distribution of residuals is also calculated and plotted.

    Should only be called with a fitted regressor (otherwise an error is thrown).

    Please note this function fits variations of the model on the training set when called.

    Args:
        regressor: (regressor) Takes in a fitted regressor.
        X: (arr) Training set features.
        y: (arr) Training set labels.

    Returns:
        None: To see plots, go to your W&B run page then expand the 'media' tab
              under 'auto visualizations'.

    Example:
    ```python
    wandb.sklearn.plot_residuals(model, X, y)
    ```
    r   r   N)
r   r   r    r!   r"   r#   r   r   r   r$   )r   r   r   not_missingr&   r'   residuals_chartr   r   r   r   Z   r)   r   )r
   )NNN)__doc__warningsr   numpyr"   r   wandb.integration.sklearnr   r    r   FutureWarningr   r   r   r   r   r   r   <module>   s    

("