Beispiel #1
0
def draw(clf, ds: DataSet, step):
    X = ds.get_X()
    y = ds.get_y()
    x_min, y_min = np.amin(X, 0)
    x_max, y_max = np.amax(X, 0)
    xx, yy = np.meshgrid(np.arange(x_min, x_max, step),
                         np.arange(y_min, y_max, step))

    grid = np.c_[xx.ravel(), yy.ravel()]

    predict_z = np.array(pm_predict(clf.predict_single, grid,
                                    name='predict')).reshape(xx.shape)

    x0, y0 = X[y == -1].T
    x1, y1 = X[y == 1].T

    X_sup = X[clf.support_indices]
    x_sup, y_sup = X_sup.T

    def plot(_predict_z):
        plt.figure(figsize=(10, 10))
        plt.pcolormesh(xx,
                       yy,
                       _predict_z,
                       cmap=plt.get_cmap('seismic'),
                       shading='auto')
        plt.scatter(x0, y0, color='red', s=100)
        plt.scatter(x1, y1, color='blue', s=100)

        plt.scatter(x_sup, y_sup, color='white', marker='x', s=60)
        plt.show()

    plot(predict_z)
Beispiel #2
0
def choose_best(ds: DataSet):
    gs = GridSearchCV(estimator=SMO(),
                      param_grid=GRID,
                      cv=4,
                      scoring='accuracy',
                      verbose=1,
                      n_jobs=-1)

    gs.fit(ds.get_X(), ds.get_y())
    draw_metrics(gs.cv_results_)
    print(f'Got best score {gs.best_score_} with params {gs.best_params_}')
    return gs.best_params_