verstehen, wie diese lambda-Funktion funktioniert

Dachte ich, habe ich verstanden, wie lambda-Funktionen arbeiten, obwohl ich nicht selbst nutzen. Aber die lambda unten aus dieses tutorial völlig stümpfe mich:

import matplotlib.pyplot as plt
import numpy as np
import sklearn
import sklearn.datasets
import sklearn.linear_model
import matplotlib

Das war einfach. Mehr:

# Generate a dataset and plot it
np.random.seed(0)
X, y = sklearn.datasets.make_moons(200, noise=0.20)
plt.scatter(X[:,0], X[:,1], s=40, c=y, cmap=plt.cm.Spectral)
clf = sklearn.linear_model.LogisticRegressionCV()
clf.fit(X, y)

# Helper function to plot a decision boundary.
# If you don't fully understand this function don't worry, it just generates the contour plot below.

def plot_decision_boundary(pred_func):

    # Set min and max values and give it some padding
    x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
    y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
    h = 0.01

    # Generate a grid of points with distance h between them
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))

    # Predict the function value for the whole gid
    Z = pred_func(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.shape)

    # Plot the contour and training examples
    plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
    plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)

Nun die Zeile, die ich nicht verstehe:

plot_decision_boundary(lambda x: clf.predict(x))

Habe ich oft gelesen, wie lambdas arbeiten, aber ich weiß einfach nicht, wie die x hier übergeben die richtigen Werte vor. Wie ist die x zugeordnet, um die relevanten Werte?

InformationsquelleAutor Ada Stra | 2016-01-16
Schreibe einen Kommentar