DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.3k stars 559 forks source link

Fixes #498 Modifies ModelVisualizers to wrap Pipeline objects #1245

Closed lwgray closed 2 years ago

lwgray commented 2 years ago

Make estimator attribute a property so that it can be examined if it …

This PR fixes #498 which requested that the model visualizer be modified to be able to wrap pipeline objects.

I have made the following changes:

  1. Made estimator attribute a property that sets the estimator to the final_estimator if pipeline object is detected. This that the final_estimator is not a transformer.

Sample Code and Plot

from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split as tts

from yellowbrick.classifier import ConfusionMatrix

iris = load_iris()
X = iris.data
y = iris.target
classes = iris.target_names

X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2)

model = Pipeline([
    ('minmax', MinMaxScaler()), 
    ('tree', LogisticRegression(multi_class="auto", solver="liblinear")), 
]) 

iris_cm = ConfusionMatrix(
    model, classes=classes,
    label_encoder={0: 'setosa', 1: 'versicolor', 2: 'virginica'}
)

iris_cm.fit(X_train, y_train)
iris_cm.score(X_test, y_test)
iris_cm.show()

image

TODOs and questions

Still to do:

CHECKLIST

codecov[bot] commented 2 years ago

Codecov Report

Merging #1245 (50f17be) into develop (e339ce2) will decrease coverage by 0.03%. The diff coverage is 76.92%.

@@             Coverage Diff             @@
##           develop    #1245      +/-   ##
===========================================
- Coverage    90.57%   90.54%   -0.04%     
===========================================
  Files           92       92              
  Lines         5209     5222      +13     
===========================================
+ Hits          4718     4728      +10     
- Misses         491      494       +3     
Impacted Files Coverage Δ
yellowbrick/base.py 91.17% <76.92%> (-1.19%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e339ce2...50f17be. Read the comment docs.