Wie visualisieren Sie Ihre Machine-Learning-Projekte in Python?

Mar 07 2023
Die Visualisierung durch maschinelles Lernen kann Ihnen dabei helfen, die Modelle intuitiv darzustellen und zu verstehen. In diesem Artikel stelle ich Ihnen ein Paket zum Zeichnen Ihrer ML-Projekte vor – Yellowbrick.

Die Visualisierung durch maschinelles Lernen kann Ihnen dabei helfen, die Modelle intuitiv darzustellen und zu verstehen. In diesem Artikel stelle ich Ihnen ein Paket zum Zeichnen Ihrer ML-Projekte vor – Yellowbrick.

Wir müssen es installieren, bevor wir Folgendes verwenden können:

!pip install yellowbrick

import matplotlib.pyplot as plt
plt.figure(dpi=120)

from sklearn.linear_model import RidgeClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OrdinalEncoder, LabelEncoder

from yellowbrick.classifier import ROCAUC
from yellowbrick.datasets import load_game

# yellowbrick relies on sklearn and matplotlib

# Load data
X, y = load_game()

# Transformation
X = OrdinalEncoder().fit_transform(X)
y = LabelEncoder().fit_transform(y)

# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

# Build a model and draw the ROC
model = RidgeClassifier()
visualizer = ROCAUC(model, classes=["win", "loss", "draw"])

visualizer.fit(X_train, y_train)  
visualizer.score(X_test, y_test)  # Evaluation
visualizer.show()

      
                

2. PCA

plt.figure(dpi=120)

from yellowbrick.features import PCA
from yellowbrick.datasets import load_credit

X, y = load_credit()
classes = ['account in default', 'current with bills']

visualizer = PCA(scale=True, projection=3, classes=classes)
visualizer.fit_transform(X, y)
visualizer.show()

      
                

from sklearn.linear_model import Ridge

from yellowbrick.datasets import load_concrete
from yellowbrick.regressor import ResidualsPlot

X, y = load_concrete()

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = Ridge()
visualizer = ResidualsPlot(model, hist=False, qqplot=True)
visualizer.fit(X_train, y_train)
visualizer.score(X_test, y_test)
visualizer.show()

      
                

plt.figure(dpi=120)
from sklearn.linear_model import Lasso
from yellowbrick.datasets import load_bikeshare
from yellowbrick.regressor import prediction_error


X, y = load_bikeshare()
visualizer = prediction_error(Lasso(), X, y) # Only one line of code!

(1) Rang 1D

from yellowbrick.datasets import load_credit
from yellowbrick.features import Rank1D

X, y = load_credit()

visualizer = Rank1D(algorithm='shapiro')

visualizer.fit(X, y)        
visualizer.transform(X)        
visualizer.show()

      
                

from yellowbrick.datasets import load_credit
from yellowbrick.features import Rank2D

X, y = load_credit()

visualizer = Rank2D(algorithm='pearson')

visualizer.fit(X, y)          
visualizer.transform(X)        
visualizer.show()

      
                

from yellowbrick.features import ParallelCoordinates
from yellowbrick.datasets import load_occupancy

X, y = load_occupancy()

# Specify the features of interest and the classes of the target
features = [
    "temperature", "relative humidity", "light", "CO2", "humidity"
]
classes = ["unoccupied", "occupied"]

visualizer = ParallelCoordinates(
    classes=classes, features=features, sample=0.05, shuffle=True
)

visualizer.fit_transform(X, y)

visualizer.show()

      
                

from yellowbrick.datasets import load_occupancy
from yellowbrick.features import RadViz

X, y = load_occupancy()

# Specify the target classes
classes = ["unoccupied", "occupied"]

visualizer = RadViz(classes=classes)

visualizer.fit(X, y)          
visualizer.transform(X)        
visualizer.show()

      
                

from yellowbrick.datasets import load_credit
from yellowbrick.features import PCA

# Specify the features of interest and the target
X, y = load_credit()
classes = ['account in default', 'current with bills']

visualizer = PCA(scale=True, classes=classes)
visualizer.fit_transform(X, y)
visualizer.show()

      
                

<1> Diskretes Ziel

from yellowbrick.features import Manifold
from yellowbrick.datasets import load_occupancy

X, y = load_occupancy()
classes = ["unoccupied", "occupied"]

viz = Manifold(manifold="tsne", classes=classes)

viz.fit_transform(X, y) 
viz.show()

      
                

from yellowbrick.features import Manifold
from yellowbrick.datasets import load_concrete

X, y = load_concrete()

viz = Manifold(manifold="isomap", n_neighbors=10)

viz.fit_transform(X, y) 
viz.show()

      
                

from yellowbrick.datasets import load_concrete
from yellowbrick.features import JointPlotVisualizer

X, y = load_concrete()

visualizer = JointPlotVisualizer(columns="cement")

visualizer.fit_transform(X, y)   
visualizer.show()

      
                

# Referenz:https://www.scikit-yb.org/en/latest/index.htmlfür mehr visuls.