def draw_boundaries():
    data = datasets.load_iris().data[:, :
                                     2]  # we only take the first two features.
    label = np.array(datasets.load_iris().target,
                     dtype=int)  # Take classes names

    data = StandardScaler().fit_transform(data)  # Rescale data

    viz = DecisionViz(
        GaussianNB(),
        title="Gaussian",
        features=['Sepal Length', 'Sepal Width'],
        classes=['A', 'B', 'C']  # Determine dimension and no. of classes
    )
    viz.fit(data, label)  # Train data to draw
    viz.draw(data, label)  # Draw Data
    viz.show()
Exemple #2
0
from sklearn.model_selection import train_test_split as tts
from sklearn.preprocessing import StandardScaler
from sklearn import datasets
import pandas as pd
from sklearn.neighbors import KNeighborsClassifier
from yellowbrick.contrib.classifier import DecisionViz

iris = datasets.load_iris()

labels = pd.DataFrame(iris.target)
labels.columns = ['labels']
data = pd.DataFrame(iris.data)
data.columns = ['Sepal length', 'Sepal width', 'Petal length', 'Petal width']
data = pd.concat([data, labels], axis=1)
data_sp = data[['Sepal length', 'Sepal width', 'labels']]

X = StandardScaler().fit_transform(data_sp.drop(['labels'], axis=1))
X_train, X_test, y_train, y_test = tts(X,
                                       data_sp['labels'],
                                       test_size=.4,
                                       random_state=42)

viz = DecisionViz(KNeighborsClassifier(3),
                  title="Nearest Neighbors",
                  features=['Feature One', 'Feature Two'],
                  classes=["0", "1", "2"])

viz.fit(X_train, y_train)
viz.draw(X_test, y_test)
viz.show()