Commit 2d8afb80 authored by jakob-forstmann's avatar jakob-forstmann
Browse files

ignore graph creation during time measurement

parent 56a6386b
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ from time import time
h = .02  # step size in the mesh

start_time = time()
is_measuring = True 
names = ["Nearest Neighbors", "Linear SVM", "Kernel SVM",
         "Decision Tree", "Random Forest", "Neural Net",
         "Naive Bayes"]
@@ -48,7 +49,7 @@ datasets = [make_moons(noise=0.3, random_state=0),
            linearly_separable
            ]

figure = plt.figure(figsize=(27, 11))
figure = plt.figure(figsize=(27, 11)) #if not is_measuring else None
i = 1
# iterate over datasets
for ds_cnt, ds in enumerate(datasets):
@@ -69,6 +70,7 @@ for ds_cnt, ds in enumerate(datasets):
    ax = plt.subplot(len(datasets), len(classifiers) + 1, i)
    if ds_cnt == 0:
        ax.set_title("Input data")
    if not is_measuring:
    # Plot the training points
        ax.scatter(X_train[:, 0], X_train[:, 1], c=y_train, cmap=cm_bright,
                edgecolors='k')
@@ -94,6 +96,7 @@ for ds_cnt, ds in enumerate(datasets):
        else:
            Z = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]

        if not is_measuring:
            # Put the result into a color plot
            Z = Z.reshape(xx.shape)
            ax.contourf(xx, yy, Z, cmap=cm, alpha=.8)
@@ -120,5 +123,6 @@ for ds_cnt, ds in enumerate(datasets):
end_time = time()
time_elapsed = end_time-start_time
print(f"script ran for {time_elapsed} seconds")
if not is_measuring:
    plt.tight_layout()
    plt.show() # not needed in interactive Jupyter session
 No newline at end of file