.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_classifier_dl85.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_classifier_dl85.py: ====================== Default DL85Classifier ====================== .. GENERATED FROM PYTHON SOURCE LINES 7-71 .. rst-class:: sphx-glr-script-out .. code-block:: none ###################################################################### # DL8.5 default classifier # ###################################################################### Model building... Model built. Duration of building = 0.0039 Confusion Matrix below [[ 9 25] [ 0 129]] Accuracy DL8.5 on training set = 0.8243 Accuracy DL8.5 on test set = 0.8466 ############################################################## # DL8.5 classifier : Manual cross-validation (5-fold) # ############################################################## Model building... Model built. Duration of building = 0.025 Average accuracy on training set = 0.8319 Average accuracy on test set = 0.8227 ############################################################## # DL8.5 classifier : Automatic cross-validation (5-fold) # ############################################################## Model building... Model built. Duration of building = 0.0275 Average accuracy on test set = 0.8239 | .. code-block:: default import numpy as np from sklearn.metrics import confusion_matrix from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score from sklearn.model_selection import KFold from sklearn.model_selection import cross_val_score import time from pydl85 import DL85Classifier dataset = np.genfromtxt("../datasets/anneal.txt", delimiter=' ') X, y = dataset[:, 1:], dataset[:, 0] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) print("######################################################################\n" "# DL8.5 default classifier #\n" "######################################################################") clf = DL85Classifier(max_depth=2, time_limit=600, desc=True) start = time.perf_counter() print("Model building...") clf.fit(X_train, y_train) duration = time.perf_counter() - start print("Model built. Duration of building =", round(duration, 4)) y_pred = clf.predict(X_test) print("Confusion Matrix below") print(confusion_matrix(y_test, y_pred)) print("Accuracy DL8.5 on training set =", round(clf.accuracy_, 4)) print("Accuracy DL8.5 on test set =", round(accuracy_score(y_test, y_pred), 4), "\n\n\n") print("##############################################################\n" "# DL8.5 classifier : Manual cross-validation (5-fold) #\n" "##############################################################") kf = KFold(n_splits=5, random_state=42, shuffle=True) training_accuracies = [] test_accuracies = [] start = time.perf_counter() print("Model building...") for train_index, test_index in kf.split(X): data_train = X[train_index] target_train = y[train_index] data_test = X[test_index] target_test = y[test_index] clf = DL85Classifier(max_depth=2, time_limit=600) clf.fit(data_train, target_train) preds = clf.predict(data_test) training_accuracies.append(clf.accuracy_) test_accuracies.append(accuracy_score(target_test, preds)) duration = time.perf_counter() - start print("Model built. Duration of building =", round(duration, 4)) print("Average accuracy on training set =", round(np.mean(training_accuracies), 4)) print("Average accuracy on test set =", round(np.mean(test_accuracies), 4), "\n\n\n") print("##############################################################\n" "# DL8.5 classifier : Automatic cross-validation (5-fold) #\n" "##############################################################") clf = DL85Classifier(max_depth=2, time_limit=600) start = time.perf_counter() print("Model building...") scores = cross_val_score(clf, X, y, cv=5) duration = time.perf_counter() - start print("Model built. Duration of building =", round(duration, 4)) print("Average accuracy on test set =", round(np.mean(scores), 4)) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.100 seconds) .. _sphx_glr_download_auto_examples_plot_classifier_dl85.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_classifier_dl85.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_classifier_dl85.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_