From 554ec03c32771c7bea622d2463d2a197c654034e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Sat, 27 Jun 2020 18:29:40 +0200 Subject: [PATCH] Get only 3 sets for best split Fix flaky test in Splitter_test --- .gitignore | 4 +- notebooks/features.ipynb | 174 ++++++++++++++++++++++++++--------- stree/Strees.py | 6 +- stree/tests/Splitter_test.py | 51 +++++----- 4 files changed, 159 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index d50268a..3870f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,6 @@ dmypy.json .idea .vscode -.pre-commit-config.yaml \ No newline at end of file +.pre-commit-config.yaml + +**.csv \ No newline at end of file diff --git a/notebooks/features.ipynb b/notebooks/features.ipynb index c7d0611..811fcdd 100644 --- a/notebooks/features.ipynb +++ b/notebooks/features.ipynb @@ -47,7 +47,9 @@ { "cell_type": "code", "execution_count": 3, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import os\n", @@ -59,12 +61,14 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "Fraud: 0.173% 492\nValid: 99.827% 284315\nX.shape (1492, 28) y.shape (1492,)\nFraud: 33.244% 496\nValid: 66.756% 996\n" + "text": "Fraud: 0.173% 492\nValid: 99.827% 284315\nX.shape (5492, 28) y.shape (5492,)\nFraud: 9.068% 498\nValid: 90.932% 4994\n[0.09131113 0.09131113 0.09131113 0.09131113] [0.08919903 0.08919903 0.08919903 0.08919903]\n" } ], "source": [ @@ -94,22 +98,29 @@ " print(\"X.shape\", X.shape, \" y.shape\", y.shape)\n", " print(\"Fraud: {0:.3f}% {1}\".format(len(y[y == 1])*100/X.shape[0], len(y[y == 1])))\n", " print(\"Valid: {0:.3f}% {1}\".format(len(y[y == 0]) * 100 / X.shape[0], len(y[y == 0])))\n", - " Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, train_size=0.7, shuffle=True, random_state=random_state, stratify=y)\n", + " Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, train_size=0.7, shuffle=True, random_state=random_state)\n", " return Xtrain, Xtest, ytrain, ytest\n", "\n", - "# data = load_creditcard(-5000) # Take all true samples + 5000 of the others\n", + "data = load_creditcard(-5000) # Take all true samples with up to 5000 of the others\n", "# data = load_creditcard(5000) # Take the first 5000 samples\n", - "data = load_creditcard(-1000) # Take all the samples\n", + "# data = load_creditcard(-1000) # Take 1000 samples\n", "\n", "Xtrain = data[0]\n", "Xtest = data[1]\n", "ytrain = data[2]\n", "ytest = data[3]\n", + "_, data = np.unique(ytrain, return_counts=True)\n", + "wtrain = (data[1] / np.sum(data), data[0] / np.sum(data))\n", + "_, data = np.unique(ytest, return_counts=True)\n", + "wtest = (data[1] / np.sum(data), data[0] / np.sum(data))\n", "# Set weights inverse to its count class in dataset\n", - "weights = np.ones(Xtrain.shape[0],) * 1.00244\n", - "weights[ytrain==1] = 1.99755\n", - "weights_test = np.ones(Xtest.shape[0],) * 1.00244\n", - "weights_test[ytest==1] = 1.99755 " + "weights = np.ones(Xtrain.shape[0],)\n", + "weights[ytrain==0] = wtrain[0]\n", + "weights[ytrain==1] = wtrain[1]\n", + "weights_test = np.ones(Xtest.shape[0],)\n", + "weights_test[ytest==0] = wtest[0]\n", + "weights_test[ytest==1] = wtest[1]\n", + "print(weights[:4], weights_test[:4])" ] }, { @@ -123,19 +134,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Test smple_weights\n", + "## Test simple_weights\n", "Compute accuracy with weights in samples. The weights are set based on the inverse of the number of samples of each class" ] }, { "cell_type": "code", "execution_count": 5, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "Accuracy of Train without weights 0.9808429118773946\nAccuracy of Train with weights 0.9904214559386973\nAccuracy of Tests without weights 0.9441964285714286\nAccuracy of Tests with weights 0.9375\n" + "text": "Accuracy of Train without weights 0.9901144640998959\nAccuracy of Train with weights 0.9924557752341311\nAccuracy of Tests without weights 0.9872572815533981\nAccuracy of Tests with weights 0.9824029126213593\n" } ], "source": [ @@ -157,12 +170,14 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "Time: 0.13s\tKernel: linear\tAccuracy_train: 0.9693486590038314\tAccuracy_test: 0.9598214285714286\nTime: 0.09s\tKernel: rbf\tAccuracy_train: 0.9923371647509579\tAccuracy_test: 0.953125\nTime: 0.09s\tKernel: poly\tAccuracy_train: 0.9913793103448276\tAccuracy_test: 0.9375\n" + "text": "Time: 10.77s\tKernel: linear\tAccuracy_train: 0.986732570239334\tAccuracy_test: 0.9860436893203883\nTime: 1.56s\tKernel: rbf\tAccuracy_train: 0.9945369406867846\tAccuracy_test: 0.9896844660194175\nTime: 1.23s\tKernel: poly\tAccuracy_train: 0.9942767950052029\tAccuracy_test: 0.9860436893203883\n" } ], "source": [ @@ -185,19 +200,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { - "tags": [ - "outputPrepend" - ] + "tags": [] }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": "************** C=0.001 ****************************\nClassifier's accuracy (train): 0.9588\nClassifier's accuracy (test) : 0.9487\nroot feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0374\nroot - Down - Down, - Leaf class=1 belief= 0.984076 impurity=0.0313 counts=(array([0, 1]), array([ 5, 309]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up, - Leaf class=0 belief= 0.947874 impurity=0.0988 counts=(array([0, 1]), array([691, 38]))\n\n**************************************************\n************** C=0.01 ****************************\nClassifier's accuracy (train): 0.9588\nClassifier's accuracy (test) : 0.9531\nroot feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0192\nroot - Down - Down, - Leaf class=1 belief= 0.993506 impurity=0.0129 counts=(array([0, 1]), array([ 2, 306]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up, - Leaf class=0 belief= 0.944218 impurity=0.1053 counts=(array([0, 1]), array([694, 41]))\n\n**************************************************\n************** C=1 ****************************\nClassifier's accuracy (train): 0.9665\nClassifier's accuracy (test) : 0.9643\nroot feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0189\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([312]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([3]))\nroot - Up, - Leaf class=0 belief= 0.951989 impurity=0.0914 counts=(array([0, 1]), array([694, 35]))\n\n**************************************************\n************** C=5 ****************************\nClassifier's accuracy (train): 0.9665\nClassifier's accuracy (test) : 0.9621\nroot feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0250\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([312]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([4]))\nroot - Up, - Leaf class=0 belief= 0.951923 impurity=0.0915 counts=(array([0, 1]), array([693, 35]))\n\n**************************************************\n************** C=17 ****************************\nClassifier's accuracy (train): 0.9703\nClassifier's accuracy (test) : 0.9665\nroot feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0367\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([315]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([6]))\nroot - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0846\nroot - Up - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([1]))\nroot - Up - Up, - Leaf class=0 belief= 0.957064 impurity=0.0822 counts=(array([0, 1]), array([691, 31]))\n\n**************************************************\n0.4375 secs\n" - } - ], + "outputs": [], "source": [ "t = time.time()\n", "for C in (.001, .01, 1, 5, 17):\n", @@ -221,13 +228,15 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": {}, + "execution_count": 9, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0367\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([315]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([6]))\nroot - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0846\nroot - Up - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([1]))\nroot - Up - Up, - Leaf class=0 belief= 0.957064 impurity=0.0822 counts=(array([0, 1]), array([691, 31]))\n" + "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.1659\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0139\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([270]))\nroot - Down - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.2311\nroot - Down - Up - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([13]))\nroot - Down - Up - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([2]))\nroot - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0375\nroot - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.5000\nroot - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([1]))\nroot - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0370\nroot - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.3200\nroot - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([4]))\nroot - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0348\nroot - Up - Up - Up - Down, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([3]))\nroot - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0349\nroot - Up - Up - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4688\nroot - Up - Up - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([10]))\nroot - Up - Up - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([6]))\nroot - Up - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0296\nroot - Up - Up - Up - Up - Up - Down, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([9]))\nroot - Up - Up - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0296\nroot - Up - Up - Up - Up - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4800\nroot - Up - Up - Up - Up - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([3]))\nroot - Up - Up - Up - Up - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([2]))\nroot - Up - Up - Up - Up - Up - Up - Up, - Leaf class=0 belief= 0.985791 impurity=0.0280 counts=(array([0, 1]), array([3469, 50]))\n" } ], "source": [ @@ -238,13 +247,15 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, + "execution_count": 10, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0367\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([315]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([6]))\nroot - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0846\nroot - Up - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([1]))\nroot - Up - Up, - Leaf class=0 belief= 0.957064 impurity=0.0822 counts=(array([0, 1]), array([691, 31]))\n" + "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.1659\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0139\nroot - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([270]))\nroot - Down - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.2311\nroot - Down - Up - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([13]))\nroot - Down - Up - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([2]))\nroot - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0375\nroot - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.5000\nroot - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([1]))\nroot - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0370\nroot - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.3200\nroot - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([4]))\nroot - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0348\nroot - Up - Up - Up - Down, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([3]))\nroot - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0349\nroot - Up - Up - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4688\nroot - Up - Up - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([10]))\nroot - Up - Up - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([6]))\nroot - Up - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0296\nroot - Up - Up - Up - Up - Up - Down, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([9]))\nroot - Up - Up - Up - Up - Up - Up feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.0296\nroot - Up - Up - Up - Up - Up - Up - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4800\nroot - Up - Up - Up - Up - Up - Up - Down - Down, - Leaf class=1 belief= 1.000000 impurity=0.0000 counts=(array([1]), array([3]))\nroot - Up - Up - Up - Up - Up - Up - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([2]))\nroot - Up - Up - Up - Up - Up - Up - Up, - Leaf class=0 belief= 0.985791 impurity=0.0280 counts=(array([0, 1]), array([3469, 50]))\n" } ], "source": [ @@ -262,13 +273,15 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, + "execution_count": 11, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "1 functools.partial(, 'Stree')\n2 functools.partial(, 'Stree')\n3 functools.partial(, 'Stree')\n4 functools.partial(, 'Stree')\n5 functools.partial(, 'Stree')\n6 functools.partial(, 'Stree')\n7 functools.partial(, 'Stree')\n8 functools.partial(, 'Stree')\n9 functools.partial(, 'Stree')\n10 functools.partial(, 'Stree', readonly_memmap=True)\n11 functools.partial(, 'Stree')\n12 functools.partial(, 'Stree')\n13 functools.partial(, 'Stree')\n14 functools.partial(, 'Stree')\n15 functools.partial(, 'Stree')\n16 functools.partial(, 'Stree')\n17 functools.partial(, 'Stree')\n18 functools.partial(, 'Stree')\n19 functools.partial(, 'Stree')\n20 functools.partial(, 'Stree')\n21 functools.partial(, 'Stree')\n22 functools.partial(, 'Stree')\n23 functools.partial(, 'Stree')\n24 functools.partial(, 'Stree', readonly_memmap=True)\n25 functools.partial(, 'Stree', readonly_memmap=True, X_dtype='float32')\n26 functools.partial(, 'Stree')\n27 functools.partial(, 'Stree')\n28 functools.partial(, 'Stree')\n29 functools.partial(, 'Stree')\n30 functools.partial(, 'Stree')\n31 functools.partial(, 'Stree')\n32 functools.partial(, 'Stree')\n33 functools.partial(, 'Stree')\n34 functools.partial(, 'Stree')\n35 functools.partial(, 'Stree')\n36 functools.partial(, 'Stree')\n37 functools.partial(, 'Stree')\n38 functools.partial(, 'Stree')\n39 functools.partial(, 'Stree')\n40 functools.partial(, 'Stree')\n41 functools.partial(, 'Stree')\n42 functools.partial(, 'Stree')\n43 functools.partial(, 'Stree')\n" + "text": "1 functools.partial(, 'Stree')\n2 functools.partial(, 'Stree')\n3 functools.partial(, 'Stree')\n4 functools.partial(, 'Stree')\n5 functools.partial(, 'Stree')\n6 functools.partial(, 'Stree')\n7 functools.partial(, 'Stree')\n8 functools.partial(, 'Stree')\n9 functools.partial(, 'Stree')\n10 functools.partial(, 'Stree', readonly_memmap=True)\n11 functools.partial(, 'Stree')\n12 functools.partial(, 'Stree')\n13 functools.partial(, 'Stree')\n14 functools.partial(, 'Stree')\n15 functools.partial(, 'Stree')\n16 functools.partial(, 'Stree')\n17 functools.partial(, 'Stree')\n18 functools.partial(, 'Stree')\n19 functools.partial(, 'Stree')\n20 functools.partial(, 'Stree')\n21 functools.partial(, 'Stree')\n22 functools.partial(, 'Stree')\n23 functools.partial(, 'Stree')\n24 functools.partial(, 'Stree', readonly_memmap=True)\n25 functools.partial(, 'Stree', readonly_memmap=True, X_dtype='float32')\n26 functools.partial(, 'Stree')\n27 functools.partial(, 'Stree')\n28 functools.partial(, 'Stree')\n29 functools.partial(, 'Stree')\n30 functools.partial(, 'Stree')\n31 functools.partial(, 'Stree')\n32 functools.partial(, 'Stree')\n33 functools.partial(, 'Stree')\n34 functools.partial(, 'Stree')\n35 functools.partial(, 'Stree')\n36 functools.partial(, 'Stree')\n37 functools.partial(, 'Stree')\n38 functools.partial(, 'Stree')\n39 functools.partial(, 'Stree')\n40 functools.partial(, 'Stree')\n41 functools.partial(, 'Stree')\n42 functools.partial(, 'Stree')\n43 functools.partial(, 'Stree')\n" } ], "source": [ @@ -283,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -300,13 +313,15 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": {}, + "execution_count": 13, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "== Not Weighted ===\nSVC train score ..: 0.9578544061302682\nSTree train score : 0.960727969348659\nSVC test score ...: 0.9508928571428571\nSTree test score .: 0.9553571428571429\n==== Weighted =====\nSVC train score ..: 0.9636015325670498\nSTree train score : 0.9626436781609196\nSVC test score ...: 0.9553571428571429\nSTree test score .: 0.9553571428571429\n*SVC test score ..: 0.9447820728419238\n*STree test score : 0.9447820728419238\n" + "text": "== Not Weighted ===\nSVC train score ..: 0.9820499479708636\nSTree train score : 0.9830905306971904\nSVC test score ...: 0.9842233009708737\nSTree test score .: 0.9848300970873787\n==== Weighted =====\nSVC train score ..: 0.9768470343392299\nSTree train score : 0.9758064516129032\nSVC test score ...: 0.975121359223301\nSTree test score .: 0.9781553398058253\n*SVC test score ..: 0.9433869483836175\n*STree test score : 0.9542572525345916\n" } ], "source": [ @@ -332,13 +347,15 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, + "execution_count": 14, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.4438\nroot - Down, - Leaf class=1 belief= 0.978261 impurity=0.0425 counts=(array([0, 1]), array([ 7, 315]))\nroot - Up, - Leaf class=0 belief= 0.955679 impurity=0.0847 counts=(array([0, 1]), array([690, 32]))\n\n" + "text": "root feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.1659\nroot - Down feaures=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27) impurity=0.2701\nroot - Down - Down, - Leaf class=1 belief= 0.841270 impurity=0.2671 counts=(array([0, 1]), array([ 60, 318]))\nroot - Down - Up, - Leaf class=0 belief= 1.000000 impurity=0.0000 counts=(array([0]), array([1]))\nroot - Up, - Leaf class=0 belief= 0.990476 impurity=0.0189 counts=(array([0, 1]), array([3432, 33]))\n\n" } ], "source": [ @@ -354,13 +371,35 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": {}, + "execution_count": 15, + "metadata": { + "tags": [] + }, "outputs": [ { "output_type": "stream", "name": "stdout", - "text": "****************************************\nmax_features None = 28\nTrain score : 0.9664750957854407\nTest score .: 0.9642857142857143\nTook 0.09 seconds\n****************************************\nmax_features auto = 5\nTrain score : 0.9511494252873564\nTest score .: 0.9441964285714286\nTook 0.37 seconds\n****************************************\nmax_features log2 = 4\nTrain score : 0.935823754789272\nTest score .: 0.9330357142857143\nTook 0.10 seconds\n****************************************\nmax_features 7 = 7\nTrain score : 0.9568965517241379\nTest score .: 0.9397321428571429\nTook 3.36 seconds\n****************************************\nmax_features 0.5 = 14\nTrain score : 0.960727969348659\nTest score .: 0.9486607142857143\nTook 112.42 seconds\n****************************************\nmax_features 0.1 = 2\nTrain score : 0.8793103448275862\nTest score .: 0.8839285714285714\nTook 0.06 seconds\n****************************************\nmax_features 0.7 = 19\nTrain score : 0.9655172413793104\nTest score .: 0.9553571428571429\nTook 10.59 seconds\n" + "text": "****************************************\nmax_features None = 28\nTrain score : 0.9846514047866806\nTest score .: 0.9860436893203883\nTook 5.03 seconds\n****************************************\nmax_features auto = 5\nTrain score : 0.9802289281997919\nTest score .: 0.9824029126213593\nTook 2.20 seconds\n****************************************\nmax_features log2 = 4\nTrain score : 0.9765868886576483\nTest score .: 0.9769417475728155\nTook 0.91 seconds\n****************************************\nmax_features 7 = 7\nTrain score : 0.9768470343392299\nTest score .: 0.9781553398058253\nTook 4.55 seconds\n****************************************\n" + }, + { + "output_type": "error", + "ename": "KeyboardInterrupt", + "evalue": "", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m~/.virtualenvs/general/lib/python3.7/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_code\u001b[0;34m(self, code_obj, result, async_)\u001b[0m\n\u001b[1;32m 3330\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3331\u001b[0;31m \u001b[0mexec\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcode_obj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muser_global_ns\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muser_ns\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3332\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mclf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mStree\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrandom_state\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_features\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmax_features\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mclf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mXtrain\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mytrain\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"max_features {max_features} = {clf.max_features_}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Code/stree/stree/Strees.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[1;32m 470\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax_features_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_initialize_max_features\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 471\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtree_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"root\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 472\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_build_predictor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Code/stree/stree/Strees.py\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(self, X, y, sample_weight, depth, title)\u001b[0m\n\u001b[1;32m 542\u001b[0m )\n\u001b[0;32m--> 543\u001b[0;31m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_up\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_U\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_u\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msw_u\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdepth\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtitle\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\" - Up\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 544\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_down\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_D\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_d\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msw_d\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdepth\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtitle\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\" - Down\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Code/stree/stree/Strees.py\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(self, X, y, sample_weight, depth, title)\u001b[0m\n\u001b[1;32m 514\u001b[0m \u001b[0mclf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_build_clf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 515\u001b[0;31m \u001b[0mXs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfeatures\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplitter_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_subspace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax_features_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 516\u001b[0m \u001b[0;31m# solve WARNING: class label 0 specified in weight is not found\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Code/stree/stree/Strees.py\u001b[0m in \u001b[0;36mget_subspace\u001b[0;34m(self, dataset, labels, max_features)\u001b[0m\n\u001b[1;32m 271\u001b[0m \"\"\"\n\u001b[0;32m--> 272\u001b[0;31m \u001b[0mindices\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_subspaces_set\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_features\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 273\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindices\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindices\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Code/stree/stree/Strees.py\u001b[0m in \u001b[0;36m_get_subspaces_set\u001b[0;34m(self, dataset, labels, max_features)\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0mfeatures\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 254\u001b[0;31m \u001b[0mfeatures_sets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcombinations\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfeatures\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_features\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 255\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfeatures_sets\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] } ], "source": [ @@ -375,6 +414,49 @@ " print(f\"Took {time.time() - now:.2f} seconds\")" ] }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "tags": [ + "outputPrepend" + ] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "(6, 10, 14), (6, 10, 15), (6, 10, 16), (6, 10, 17), (6, 10, 18), (6, 10, 19), (6, 10, 20), (6, 10, 21), (6, 10, 22), (6, 10, 23), (6, 10, 24), (6, 10, 25), (6, 10, 26), (6, 10, 27), (6, 11, 12), (6, 11, 13), (6, 11, 14), (6, 11, 15), (6, 11, 16), (6, 11, 17), (6, 11, 18), (6, 11, 19), (6, 11, 20), (6, 11, 21), (6, 11, 22), (6, 11, 23), (6, 11, 24), (6, 11, 25), (6, 11, 26), (6, 11, 27), (6, 12, 13), (6, 12, 14), (6, 12, 15), (6, 12, 16), (6, 12, 17), (6, 12, 18), (6, 12, 19), (6, 12, 20), (6, 12, 21), (6, 12, 22), (6, 12, 23), (6, 12, 24), (6, 12, 25), (6, 12, 26), (6, 12, 27), (6, 13, 14), (6, 13, 15), (6, 13, 16), (6, 13, 17), (6, 13, 18), (6, 13, 19), (6, 13, 20), (6, 13, 21), (6, 13, 22), (6, 13, 23), (6, 13, 24), (6, 13, 25), (6, 13, 26), (6, 13, 27), (6, 14, 15), (6, 14, 16), (6, 14, 17), (6, 14, 18), (6, 14, 19), (6, 14, 20), (6, 14, 21), (6, 14, 22), (6, 14, 23), (6, 14, 24), (6, 14, 25), (6, 14, 26), (6, 14, 27), (6, 15, 16), (6, 15, 17), (6, 15, 18), (6, 15, 19), (6, 15, 20), (6, 15, 21), (6, 15, 22), (6, 15, 23), (6, 15, 24), (6, 15, 25), (6, 15, 26), (6, 15, 27), (6, 16, 17), (6, 16, 18), (6, 16, 19), (6, 16, 20), (6, 16, 21), (6, 16, 22), (6, 16, 23), (6, 16, 24), (6, 16, 25), (6, 16, 26), (6, 16, 27), (6, 17, 18), (6, 17, 19), (6, 17, 20), (6, 17, 21), (6, 17, 22), (6, 17, 23), (6, 17, 24), (6, 17, 25), (6, 17, 26), (6, 17, 27), (6, 18, 19), (6, 18, 20), (6, 18, 21), (6, 18, 22), (6, 18, 23), (6, 18, 24), (6, 18, 25), (6, 18, 26), (6, 18, 27), (6, 19, 20), (6, 19, 21), (6, 19, 22), (6, 19, 23), (6, 19, 24), (6, 19, 25), (6, 19, 26), (6, 19, 27), (6, 20, 21), (6, 20, 22), (6, 20, 23), (6, 20, 24), (6, 20, 25), (6, 20, 26), (6, 20, 27), (6, 21, 22), (6, 21, 23), (6, 21, 24), (6, 21, 25), (6, 21, 26), (6, 21, 27), (6, 22, 23), (6, 22, 24), (6, 22, 25), (6, 22, 26), (6, 22, 27), (6, 23, 24), (6, 23, 25), (6, 23, 26), (6, 23, 27), (6, 24, 25), (6, 24, 26), (6, 24, 27), (6, 25, 26), (6, 25, 27), (6, 26, 27), (7, 8, 9), (7, 8, 10), (7, 8, 11), (7, 8, 12), (7, 8, 13), (7, 8, 14), (7, 8, 15), (7, 8, 16), (7, 8, 17), (7, 8, 18), (7, 8, 19), (7, 8, 20), (7, 8, 21), (7, 8, 22), (7, 8, 23), (7, 8, 24), (7, 8, 25), (7, 8, 26), (7, 8, 27), (7, 9, 10), (7, 9, 11), (7, 9, 12), (7, 9, 13), (7, 9, 14), (7, 9, 15), (7, 9, 16), (7, 9, 17), (7, 9, 18), (7, 9, 19), (7, 9, 20), (7, 9, 21), (7, 9, 22), (7, 9, 23), (7, 9, 24), (7, 9, 25), (7, 9, 26), (7, 9, 27), (7, 10, 11), (7, 10, 12), (7, 10, 13), (7, 10, 14), (7, 10, 15), (7, 10, 16), (7, 10, 17), (7, 10, 18), (7, 10, 19), (7, 10, 20), (7, 10, 21), (7, 10, 22), (7, 10, 23), (7, 10, 24), (7, 10, 25), (7, 10, 26), (7, 10, 27), (7, 11, 12), (7, 11, 13), (7, 11, 14), (7, 11, 15), (7, 11, 16), (7, 11, 17), (7, 11, 18), (7, 11, 19), (7, 11, 20), (7, 11, 21), (7, 11, 22), (7, 11, 23), (7, 11, 24), (7, 11, 25), (7, 11, 26), (7, 11, 27), (7, 12, 13), (7, 12, 14), (7, 12, 15), (7, 12, 16), (7, 12, 17), (7, 12, 18), (7, 12, 19), (7, 12, 20), (7, 12, 21), (7, 12, 22), (7, 12, 23), (7, 12, 24), (7, 12, 25), (7, 12, 26), (7, 12, 27), (7, 13, 14), (7, 13, 15), (7, 13, 16), (7, 13, 17), (7, 13, 18), (7, 13, 19), (7, 13, 20), (7, 13, 21), (7, 13, 22), (7, 13, 23), (7, 13, 24), (7, 13, 25), (7, 13, 26), (7, 13, 27), (7, 14, 15), (7, 14, 16), (7, 14, 17), (7, 14, 18), (7, 14, 19), (7, 14, 20), (7, 14, 21), (7, 14, 22), (7, 14, 23), (7, 14, 24), (7, 14, 25), (7, 14, 26), (7, 14, 27), (7, 15, 16), (7, 15, 17), (7, 15, 18), (7, 15, 19), (7, 15, 20), (7, 15, 21), (7, 15, 22), (7, 15, 23), (7, 15, 24), (7, 15, 25), (7, 15, 26), (7, 15, 27), (7, 16, 17), (7, 16, 18), (7, 16, 19), (7, 16, 20), (7, 16, 21), (7, 16, 22), (7, 16, 23), (7, 16, 24), (7, 16, 25), (7, 16, 26), (7, 16, 27), (7, 17, 18), (7, 17, 19), (7, 17, 20), (7, 17, 21), (7, 17, 22), (7, 17, 23), (7, 17, 24), (7, 17, 25), (7, 17, 26), (7, 17, 27), (7, 18, 19), (7, 18, 20), (7, 18, 21), (7, 18, 22), (7, 18, 23), (7, 18, 24), (7, 18, 25), (7, 18, 26), (7, 18, 27), (7, 19, 20), (7, 19, 21), (7, 19, 22), (7, 19, 23), (7, 19, 24), (7, 19, 25), (7, 19, 26), (7, 19, 27), (7, 20, 21), (7, 20, 22), (7, 20, 23), (7, 20, 24), (7, 20, 25), (7, 20, 26), (7, 20, 27), (7, 21, 22), (7, 21, 23), (7, 21, 24), (7, 21, 25), (7, 21, 26), (7, 21, 27), (7, 22, 23), (7, 22, 24), (7, 22, 25), (7, 22, 26), (7, 22, 27), (7, 23, 24), (7, 23, 25), (7, 23, 26), (7, 23, 27), (7, 24, 25), (7, 24, 26), (7, 24, 27), (7, 25, 26), (7, 25, 27), (7, 26, 27), (8, 9, 10), (8, 9, 11), (8, 9, 12), (8, 9, 13), (8, 9, 14), (8, 9, 15), (8, 9, 16), (8, 9, 17), (8, 9, 18), (8, 9, 19), (8, 9, 20), (8, 9, 21), (8, 9, 22), (8, 9, 23), (8, 9, 24), (8, 9, 25), (8, 9, 26), (8, 9, 27), (8, 10, 11), (8, 10, 12), (8, 10, 13), (8, 10, 14), (8, 10, 15), (8, 10, 16), (8, 10, 17), (8, 10, 18), (8, 10, 19), (8, 10, 20), (8, 10, 21), (8, 10, 22), (8, 10, 23), (8, 10, 24), (8, 10, 25), (8, 10, 26), (8, 10, 27), (8, 11, 12), (8, 11, 13), (8, 11, 14), (8, 11, 15), (8, 11, 16), (8, 11, 17), (8, 11, 18), (8, 11, 19), (8, 11, 20), (8, 11, 21), (8, 11, 22), (8, 11, 23), (8, 11, 24), (8, 11, 25), (8, 11, 26), (8, 11, 27), (8, 12, 13), (8, 12, 14), (8, 12, 15), (8, 12, 16), (8, 12, 17), (8, 12, 18), (8, 12, 19), (8, 12, 20), (8, 12, 21), (8, 12, 22), (8, 12, 23), (8, 12, 24), (8, 12, 25), (8, 12, 26), (8, 12, 27), (8, 13, 14), (8, 13, 15), (8, 13, 16), (8, 13, 17), (8, 13, 18), (8, 13, 19), (8, 13, 20), (8, 13, 21), (8, 13, 22), (8, 13, 23), (8, 13, 24), (8, 13, 25), (8, 13, 26), (8, 13, 27), (8, 14, 15), (8, 14, 16), (8, 14, 17), (8, 14, 18), (8, 14, 19), (8, 14, 20), (8, 14, 21), (8, 14, 22), (8, 14, 23), (8, 14, 24), (8, 14, 25), (8, 14, 26), (8, 14, 27), (8, 15, 16), (8, 15, 17), (8, 15, 18), (8, 15, 19), (8, 15, 20), (8, 15, 21), (8, 15, 22), (8, 15, 23), (8, 15, 24), (8, 15, 25), (8, 15, 26), (8, 15, 27), (8, 16, 17), (8, 16, 18), (8, 16, 19), (8, 16, 20), (8, 16, 21), (8, 16, 22), (8, 16, 23), (8, 16, 24), (8, 16, 25), (8, 16, 26), (8, 16, 27), (8, 17, 18), (8, 17, 19), (8, 17, 20), (8, 17, 21), (8, 17, 22), (8, 17, 23), (8, 17, 24), (8, 17, 25), (8, 17, 26), (8, 17, 27), (8, 18, 19), (8, 18, 20), (8, 18, 21), (8, 18, 22), (8, 18, 23), (8, 18, 24), (8, 18, 25), (8, 18, 26), (8, 18, 27), (8, 19, 20), (8, 19, 21), (8, 19, 22), (8, 19, 23), (8, 19, 24), (8, 19, 25), (8, 19, 26), (8, 19, 27), (8, 20, 21), (8, 20, 22), (8, 20, 23), (8, 20, 24), (8, 20, 25), (8, 20, 26), (8, 20, 27), (8, 21, 22), (8, 21, 23), (8, 21, 24), (8, 21, 25), (8, 21, 26), (8, 21, 27), (8, 22, 23), (8, 22, 24), (8, 22, 25), (8, 22, 26), (8, 22, 27), (8, 23, 24), (8, 23, 25), (8, 23, 26), (8, 23, 27), (8, 24, 25), (8, 24, 26), (8, 24, 27), (8, 25, 26), (8, 25, 27), (8, 26, 27), (9, 10, 11), (9, 10, 12), (9, 10, 13), (9, 10, 14), (9, 10, 15), (9, 10, 16), (9, 10, 17), (9, 10, 18), (9, 10, 19), (9, 10, 20), (9, 10, 21), (9, 10, 22), (9, 10, 23), (9, 10, 24), (9, 10, 25), (9, 10, 26), (9, 10, 27), (9, 11, 12), (9, 11, 13), (9, 11, 14), (9, 11, 15), (9, 11, 16), (9, 11, 17), (9, 11, 18), (9, 11, 19), (9, 11, 20), (9, 11, 21), (9, 11, 22), (9, 11, 23), (9, 11, 24), (9, 11, 25), (9, 11, 26), (9, 11, 27), (9, 12, 13), (9, 12, 14), (9, 12, 15), (9, 12, 16), (9, 12, 17), (9, 12, 18), (9, 12, 19), (9, 12, 20), (9, 12, 21), (9, 12, 22), (9, 12, 23), (9, 12, 24), (9, 12, 25), (9, 12, 26), (9, 12, 27), (9, 13, 14), (9, 13, 15), (9, 13, 16), (9, 13, 17), (9, 13, 18), (9, 13, 19), (9, 13, 20), (9, 13, 21), (9, 13, 22), (9, 13, 23), (9, 13, 24), (9, 13, 25), (9, 13, 26), (9, 13, 27), (9, 14, 15), (9, 14, 16), (9, 14, 17), (9, 14, 18), (9, 14, 19), (9, 14, 20), (9, 14, 21), (9, 14, 22), (9, 14, 23), (9, 14, 24), (9, 14, 25), (9, 14, 26), (9, 14, 27), (9, 15, 16), (9, 15, 17), (9, 15, 18), (9, 15, 19), (9, 15, 20), (9, 15, 21), (9, 15, 22), (9, 15, 23), (9, 15, 24), (9, 15, 25), (9, 15, 26), (9, 15, 27), (9, 16, 17), (9, 16, 18), (9, 16, 19), (9, 16, 20), (9, 16, 21), (9, 16, 22), (9, 16, 23), (9, 16, 24), (9, 16, 25), (9, 16, 26), (9, 16, 27), (9, 17, 18), (9, 17, 19), (9, 17, 20), (9, 17, 21), (9, 17, 22), (9, 17, 23), (9, 17, 24), (9, 17, 25), (9, 17, 26), (9, 17, 27), (9, 18, 19), (9, 18, 20), (9, 18, 21), (9, 18, 22), (9, 18, 23), (9, 18, 24), (9, 18, 25), (9, 18, 26), (9, 18, 27), (9, 19, 20), (9, 19, 21), (9, 19, 22), (9, 19, 23), (9, 19, 24), (9, 19, 25), (9, 19, 26), (9, 19, 27), (9, 20, 21), (9, 20, 22), (9, 20, 23), (9, 20, 24), (9, 20, 25), (9, 20, 26), (9, 20, 27), (9, 21, 22), (9, 21, 23), (9, 21, 24), (9, 21, 25), (9, 21, 26), (9, 21, 27), (9, 22, 23), (9, 22, 24), (9, 22, 25), (9, 22, 26), (9, 22, 27), (9, 23, 24), (9, 23, 25), (9, 23, 26), (9, 23, 27), (9, 24, 25), (9, 24, 26), (9, 24, 27), (9, 25, 26), (9, 25, 27), (9, 26, 27), (10, 11, 12), (10, 11, 13), (10, 11, 14), (10, 11, 15), (10, 11, 16), (10, 11, 17), (10, 11, 18), (10, 11, 19), (10, 11, 20), (10, 11, 21), (10, 11, 22), (10, 11, 23), (10, 11, 24), (10, 11, 25), (10, 11, 26), (10, 11, 27), (10, 12, 13), (10, 12, 14), (10, 12, 15), (10, 12, 16), (10, 12, 17), (10, 12, 18), (10, 12, 19), (10, 12, 20), (10, 12, 21), (10, 12, 22), (10, 12, 23), (10, 12, 24), (10, 12, 25), (10, 12, 26), (10, 12, 27), (10, 13, 14), (10, 13, 15), (10, 13, 16), (10, 13, 17), (10, 13, 18), (10, 13, 19), (10, 13, 20), (10, 13, 21), (10, 13, 22), (10, 13, 23), (10, 13, 24), (10, 13, 25), (10, 13, 26), (10, 13, 27), (10, 14, 15), (10, 14, 16), (10, 14, 17), (10, 14, 18), (10, 14, 19), (10, 14, 20), (10, 14, 21), (10, 14, 22), (10, 14, 23), (10, 14, 24), (10, 14, 25), (10, 14, 26), (10, 14, 27), (10, 15, 16), (10, 15, 17), (10, 15, 18), (10, 15, 19), (10, 15, 20), (10, 15, 21), (10, 15, 22), (10, 15, 23), (10, 15, 24), (10, 15, 25), (10, 15, 26), (10, 15, 27), (10, 16, 17), (10, 16, 18), (10, 16, 19), (10, 16, 20), (10, 16, 21), (10, 16, 22), (10, 16, 23), (10, 16, 24), (10, 16, 25), (10, 16, 26), (10, 16, 27), (10, 17, 18), (10, 17, 19), (10, 17, 20), (10, 17, 21), (10, 17, 22), (10, 17, 23), (10, 17, 24), (10, 17, 25), (10, 17, 26), (10, 17, 27), (10, 18, 19), (10, 18, 20), (10, 18, 21), (10, 18, 22), (10, 18, 23), (10, 18, 24), (10, 18, 25), (10, 18, 26), (10, 18, 27), (10, 19, 20), (10, 19, 21), (10, 19, 22), (10, 19, 23), (10, 19, 24), (10, 19, 25), (10, 19, 26), (10, 19, 27), (10, 20, 21), (10, 20, 22), (10, 20, 23), (10, 20, 24), (10, 20, 25), (10, 20, 26), (10, 20, 27), (10, 21, 22), (10, 21, 23), (10, 21, 24), (10, 21, 25), (10, 21, 26), (10, 21, 27), (10, 22, 23), (10, 22, 24), (10, 22, 25), (10, 22, 26), (10, 22, 27), (10, 23, 24), (10, 23, 25), (10, 23, 26), (10, 23, 27), (10, 24, 25), (10, 24, 26), (10, 24, 27), (10, 25, 26), (10, 25, 27), (10, 26, 27), (11, 12, 13), (11, 12, 14), (11, 12, 15), (11, 12, 16), (11, 12, 17), (11, 12, 18), (11, 12, 19), (11, 12, 20), (11, 12, 21), (11, 12, 22), (11, 12, 23), (11, 12, 24), (11, 12, 25), (11, 12, 26), (11, 12, 27), (11, 13, 14), (11, 13, 15), (11, 13, 16), (11, 13, 17), (11, 13, 18), (11, 13, 19), (11, 13, 20), (11, 13, 21), (11, 13, 22), (11, 13, 23), (11, 13, 24), (11, 13, 25), (11, 13, 26), (11, 13, 27), (11, 14, 15), (11, 14, 16), (11, 14, 17), (11, 14, 18), (11, 14, 19), (11, 14, 20), (11, 14, 21), (11, 14, 22), (11, 14, 23), (11, 14, 24), (11, 14, 25), (11, 14, 26), (11, 14, 27), (11, 15, 16), (11, 15, 17), (11, 15, 18), (11, 15, 19), (11, 15, 20), (11, 15, 21), (11, 15, 22), (11, 15, 23), (11, 15, 24), (11, 15, 25), (11, 15, 26), (11, 15, 27), (11, 16, 17), (11, 16, 18), (11, 16, 19), (11, 16, 20), (11, 16, 21), (11, 16, 22), (11, 16, 23), (11, 16, 24), (11, 16, 25), (11, 16, 26), (11, 16, 27), (11, 17, 18), (11, 17, 19), (11, 17, 20), (11, 17, 21), (11, 17, 22), (11, 17, 23), (11, 17, 24), (11, 17, 25), (11, 17, 26), (11, 17, 27), (11, 18, 19), (11, 18, 20), (11, 18, 21), (11, 18, 22), (11, 18, 23), (11, 18, 24), (11, 18, 25), (11, 18, 26), (11, 18, 27), (11, 19, 20), (11, 19, 21), (11, 19, 22), (11, 19, 23), (11, 19, 24), (11, 19, 25), (11, 19, 26), (11, 19, 27), (11, 20, 21), (11, 20, 22), (11, 20, 23), (11, 20, 24), (11, 20, 25), (11, 20, 26), (11, 20, 27), (11, 21, 22), (11, 21, 23), (11, 21, 24), (11, 21, 25), (11, 21, 26), (11, 21, 27), (11, 22, 23), (11, 22, 24), (11, 22, 25), (11, 22, 26), (11, 22, 27), (11, 23, 24), (11, 23, 25), (11, 23, 26), (11, 23, 27), (11, 24, 25), (11, 24, 26), (11, 24, 27), (11, 25, 26), (11, 25, 27), (11, 26, 27), (12, 13, 14), (12, 13, 15), (12, 13, 16), (12, 13, 17), (12, 13, 18), (12, 13, 19), (12, 13, 20), (12, 13, 21), (12, 13, 22), (12, 13, 23), (12, 13, 24), (12, 13, 25), (12, 13, 26), (12, 13, 27), (12, 14, 15), (12, 14, 16), (12, 14, 17), (12, 14, 18), (12, 14, 19), (12, 14, 20), (12, 14, 21), (12, 14, 22), (12, 14, 23), (12, 14, 24), (12, 14, 25), (12, 14, 26), (12, 14, 27), (12, 15, 16), (12, 15, 17), (12, 15, 18), (12, 15, 19), (12, 15, 20), (12, 15, 21), (12, 15, 22), (12, 15, 23), (12, 15, 24), (12, 15, 25), (12, 15, 26), (12, 15, 27), (12, 16, 17), (12, 16, 18), (12, 16, 19), (12, 16, 20), (12, 16, 21), (12, 16, 22), (12, 16, 23), (12, 16, 24), (12, 16, 25), (12, 16, 26), (12, 16, 27), (12, 17, 18), (12, 17, 19), (12, 17, 20), (12, 17, 21), (12, 17, 22), (12, 17, 23), (12, 17, 24), (12, 17, 25), (12, 17, 26), (12, 17, 27), (12, 18, 19), (12, 18, 20), (12, 18, 21), (12, 18, 22), (12, 18, 23), (12, 18, 24), (12, 18, 25), (12, 18, 26), (12, 18, 27), (12, 19, 20), (12, 19, 21), (12, 19, 22), (12, 19, 23), (12, 19, 24), (12, 19, 25), (12, 19, 26), (12, 19, 27), (12, 20, 21), (12, 20, 22), (12, 20, 23), (12, 20, 24), (12, 20, 25), (12, 20, 26), (12, 20, 27), (12, 21, 22), (12, 21, 23), (12, 21, 24), (12, 21, 25), (12, 21, 26), (12, 21, 27), (12, 22, 23), (12, 22, 24), (12, 22, 25), (12, 22, 26), (12, 22, 27), (12, 23, 24), (12, 23, 25), (12, 23, 26), (12, 23, 27), (12, 24, 25), (12, 24, 26), (12, 24, 27), (12, 25, 26), (12, 25, 27), (12, 26, 27), (13, 14, 15), (13, 14, 16), (13, 14, 17), (13, 14, 18), (13, 14, 19), (13, 14, 20), (13, 14, 21), (13, 14, 22), (13, 14, 23), (13, 14, 24), (13, 14, 25), (13, 14, 26), (13, 14, 27), (13, 15, 16), (13, 15, 17), (13, 15, 18), (13, 15, 19), (13, 15, 20), (13, 15, 21), (13, 15, 22), (13, 15, 23), (13, 15, 24), (13, 15, 25), (13, 15, 26), (13, 15, 27), (13, 16, 17), (13, 16, 18), (13, 16, 19), (13, 16, 20), (13, 16, 21), (13, 16, 22), (13, 16, 23), (13, 16, 24), (13, 16, 25), (13, 16, 26), (13, 16, 27), (13, 17, 18), (13, 17, 19), (13, 17, 20), (13, 17, 21), (13, 17, 22), (13, 17, 23), (13, 17, 24), (13, 17, 25), (13, 17, 26), (13, 17, 27), (13, 18, 19), (13, 18, 20), (13, 18, 21), (13, 18, 22), (13, 18, 23), (13, 18, 24), (13, 18, 25), (13, 18, 26), (13, 18, 27), (13, 19, 20), (13, 19, 21), (13, 19, 22), (13, 19, 23), (13, 19, 24), (13, 19, 25), (13, 19, 26), (13, 19, 27), (13, 20, 21), (13, 20, 22), (13, 20, 23), (13, 20, 24), (13, 20, 25), (13, 20, 26), (13, 20, 27), (13, 21, 22), (13, 21, 23), (13, 21, 24), (13, 21, 25), (13, 21, 26), (13, 21, 27), (13, 22, 23), (13, 22, 24), (13, 22, 25), (13, 22, 26), (13, 22, 27), (13, 23, 24), (13, 23, 25), (13, 23, 26), (13, 23, 27), (13, 24, 25), (13, 24, 26), (13, 24, 27), (13, 25, 26), (13, 25, 27), (13, 26, 27), (14, 15, 16), (14, 15, 17), (14, 15, 18), (14, 15, 19), (14, 15, 20), (14, 15, 21), (14, 15, 22), (14, 15, 23), (14, 15, 24), (14, 15, 25), (14, 15, 26), (14, 15, 27), (14, 16, 17), (14, 16, 18), (14, 16, 19), (14, 16, 20), (14, 16, 21), (14, 16, 22), (14, 16, 23), (14, 16, 24), (14, 16, 25), (14, 16, 26), (14, 16, 27), (14, 17, 18), (14, 17, 19), (14, 17, 20), (14, 17, 21), (14, 17, 22), (14, 17, 23), (14, 17, 24), (14, 17, 25), (14, 17, 26), (14, 17, 27), (14, 18, 19), (14, 18, 20), (14, 18, 21), (14, 18, 22), (14, 18, 23), (14, 18, 24), (14, 18, 25), (14, 18, 26), (14, 18, 27), (14, 19, 20), (14, 19, 21), (14, 19, 22), (14, 19, 23), (14, 19, 24), (14, 19, 25), (14, 19, 26), (14, 19, 27), (14, 20, 21), (14, 20, 22), (14, 20, 23), (14, 20, 24), (14, 20, 25), (14, 20, 26), (14, 20, 27), (14, 21, 22), (14, 21, 23), (14, 21, 24), (14, 21, 25), (14, 21, 26), (14, 21, 27), (14, 22, 23), (14, 22, 24), (14, 22, 25), (14, 22, 26), (14, 22, 27), (14, 23, 24), (14, 23, 25), (14, 23, 26), (14, 23, 27), (14, 24, 25), (14, 24, 26), (14, 24, 27), (14, 25, 26), (14, 25, 27), (14, 26, 27), (15, 16, 17), (15, 16, 18), (15, 16, 19), (15, 16, 20), (15, 16, 21), (15, 16, 22), (15, 16, 23), (15, 16, 24), (15, 16, 25), (15, 16, 26), (15, 16, 27), (15, 17, 18), (15, 17, 19), (15, 17, 20), (15, 17, 21), (15, 17, 22), (15, 17, 23), (15, 17, 24), (15, 17, 25), (15, 17, 26), (15, 17, 27), (15, 18, 19), (15, 18, 20), (15, 18, 21), (15, 18, 22), (15, 18, 23), (15, 18, 24), (15, 18, 25), (15, 18, 26), (15, 18, 27), (15, 19, 20), (15, 19, 21), (15, 19, 22), (15, 19, 23), (15, 19, 24), (15, 19, 25), (15, 19, 26), (15, 19, 27), (15, 20, 21), (15, 20, 22), (15, 20, 23), (15, 20, 24), (15, 20, 25), (15, 20, 26), (15, 20, 27), (15, 21, 22), (15, 21, 23), (15, 21, 24), (15, 21, 25), (15, 21, 26), (15, 21, 27), (15, 22, 23), (15, 22, 24), (15, 22, 25), (15, 22, 26), (15, 22, 27), (15, 23, 24), (15, 23, 25), (15, 23, 26), (15, 23, 27), (15, 24, 25), (15, 24, 26), (15, 24, 27), (15, 25, 26), (15, 25, 27), (15, 26, 27), (16, 17, 18), (16, 17, 19), (16, 17, 20), (16, 17, 21), (16, 17, 22), (16, 17, 23), (16, 17, 24), (16, 17, 25), (16, 17, 26), (16, 17, 27), (16, 18, 19), (16, 18, 20), (16, 18, 21), (16, 18, 22), (16, 18, 23), (16, 18, 24), (16, 18, 25), (16, 18, 26), (16, 18, 27), (16, 19, 20), (16, 19, 21), (16, 19, 22), (16, 19, 23), (16, 19, 24), (16, 19, 25), (16, 19, 26), (16, 19, 27), (16, 20, 21), (16, 20, 22), (16, 20, 23), (16, 20, 24), (16, 20, 25), (16, 20, 26), (16, 20, 27), (16, 21, 22), (16, 21, 23), (16, 21, 24), (16, 21, 25), (16, 21, 26), (16, 21, 27), (16, 22, 23), (16, 22, 24), (16, 22, 25), (16, 22, 26), (16, 22, 27), (16, 23, 24), (16, 23, 25), (16, 23, 26), (16, 23, 27), (16, 24, 25), (16, 24, 26), (16, 24, 27), (16, 25, 26), (16, 25, 27), (16, 26, 27), (17, 18, 19), (17, 18, 20), (17, 18, 21), (17, 18, 22), (17, 18, 23), (17, 18, 24), (17, 18, 25), (17, 18, 26), (17, 18, 27), (17, 19, 20), (17, 19, 21), (17, 19, 22), (17, 19, 23), (17, 19, 24), (17, 19, 25), (17, 19, 26), (17, 19, 27), (17, 20, 21), (17, 20, 22), (17, 20, 23), (17, 20, 24), (17, 20, 25), (17, 20, 26), (17, 20, 27), (17, 21, 22), (17, 21, 23), (17, 21, 24), (17, 21, 25), (17, 21, 26), (17, 21, 27), (17, 22, 23), (17, 22, 24), (17, 22, 25), (17, 22, 26), (17, 22, 27), (17, 23, 24), (17, 23, 25), (17, 23, 26), (17, 23, 27), (17, 24, 25), (17, 24, 26), (17, 24, 27), (17, 25, 26), (17, 25, 27), (17, 26, 27), (18, 19, 20), (18, 19, 21), (18, 19, 22), (18, 19, 23), (18, 19, 24), (18, 19, 25), (18, 19, 26), (18, 19, 27), (18, 20, 21), (18, 20, 22), (18, 20, 23), (18, 20, 24), (18, 20, 25), (18, 20, 26), (18, 20, 27), (18, 21, 22), (18, 21, 23), (18, 21, 24), (18, 21, 25), (18, 21, 26), (18, 21, 27), (18, 22, 23), (18, 22, 24), (18, 22, 25), (18, 22, 26), (18, 22, 27), (18, 23, 24), (18, 23, 25), (18, 23, 26), (18, 23, 27), (18, 24, 25), (18, 24, 26), (18, 24, 27), (18, 25, 26), (18, 25, 27), (18, 26, 27), (19, 20, 21), (19, 20, 22), (19, 20, 23), (19, 20, 24), (19, 20, 25), (19, 20, 26), (19, 20, 27), (19, 21, 22), (19, 21, 23), (19, 21, 24), (19, 21, 25), (19, 21, 26), (19, 21, 27), (19, 22, 23), (19, 22, 24), (19, 22, 25), (19, 22, 26), (19, 22, 27), (19, 23, 24), (19, 23, 25), (19, 23, 26), (19, 23, 27), (19, 24, 25), (19, 24, 26), (19, 24, 27), (19, 25, 26), (19, 25, 27), (19, 26, 27), (20, 21, 22), (20, 21, 23), (20, 21, 24), (20, 21, 25), (20, 21, 26), (20, 21, 27), (20, 22, 23), (20, 22, 24), (20, 22, 25), (20, 22, 26), (20, 22, 27), (20, 23, 24), (20, 23, 25), (20, 23, 26), (20, 23, 27), (20, 24, 25), (20, 24, 26), (20, 24, 27), (20, 25, 26), (20, 25, 27), (20, 26, 27), (21, 22, 23), (21, 22, 24), (21, 22, 25), (21, 22, 26), (21, 22, 27), (21, 23, 24), (21, 23, 25), (21, 23, 26), (21, 23, 27), (21, 24, 25), (21, 24, 26), (21, 24, 27), (21, 25, 26), (21, 25, 27), (21, 26, 27), (22, 23, 24), (22, 23, 25), (22, 23, 26), (22, 23, 27), (22, 24, 25), (22, 24, 26), (22, 24, 27), (22, 25, 26), (22, 25, 27), (22, 26, 27), (23, 24, 25), (23, 24, 26), (23, 24, 27), (23, 25, 26), (23, 25, 27), (23, 26, 27), (24, 25, 26), (24, 25, 27), (24, 26, 27), (25, 26, 27)]\n" + } + ], + "source": [ + "from itertools import combinations\n", + "max_features=3\n", + "features = range(Xtrain.shape[1])\n", + "features_sets = list(combinations(features, max_features))\n", + "print(features_sets)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "[(3, 7, 10), (1, 7, 24), (7, 12, 26)]\n" + } + ], + "source": [ + "import random\n", + "if len(features_sets) > 3:\n", + " features_sets = random.sample(features_sets, 3)\n", + "print(features_sets)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -387,7 +469,7 @@ "kernelspec": { "display_name": "Python 3.7.6 64-bit ('general': venv)", "language": "python", - "name": "python37664bitgeneralvenvfbd0a23e74cf4e778460f5ffc6761f39" + "name": "python37664bitgeneralvenve3128601eb614c5da59c5055670b6040" }, "language_info": { "codemirror_mode": { diff --git a/stree/Strees.py b/stree/Strees.py index 9baebae..c67308e 100644 --- a/stree/Strees.py +++ b/stree/Strees.py @@ -218,7 +218,7 @@ class Splitter: imp_dn = self.criterion_function(labels_dn) samples = card_up + card_dn if samples == 0: - return 0 + return 0.0 else: result = ( imp_prev @@ -244,7 +244,6 @@ class Splitter: if gain > max_gain: max_gain = gain selected = feature_set - return selected if selected is not None else feature_set def _get_subspaces_set( @@ -257,6 +256,9 @@ class Splitter: index = random.randint(0, len(features_sets) - 1) return features_sets[index] else: + # get only 3 sets at most + if len(features_sets) > 3: + features_sets = random.sample(features_sets, 3) return self._select_best_set(dataset, labels, features_sets) else: return features_sets[0] diff --git a/stree/tests/Splitter_test.py b/stree/tests/Splitter_test.py index 1dcdbbd..d38b3bf 100644 --- a/stree/tests/Splitter_test.py +++ b/stree/tests/Splitter_test.py @@ -1,11 +1,11 @@ import os import unittest +import random import numpy as np -from sklearn.svm import LinearSVC - +from sklearn.svm import SVC +from sklearn.datasets import load_wine from stree import Splitter -from .utils import load_dataset class Splitter_test(unittest.TestCase): @@ -15,7 +15,7 @@ class Splitter_test(unittest.TestCase): @staticmethod def build( - clf=LinearSVC(), + clf=SVC, min_samples_split=0, splitter_type="random", criterion="gini", @@ -23,7 +23,7 @@ class Splitter_test(unittest.TestCase): random_state=None, ): return Splitter( - clf=clf, + clf=clf(random_state=random_state, kernel="rbf"), min_samples_split=min_samples_split, splitter_type=splitter_type, criterion=criterion, @@ -43,7 +43,7 @@ class Splitter_test(unittest.TestCase): with self.assertRaises(ValueError): self.build(criteria="duck") with self.assertRaises(ValueError): - self.build(clf=None) + _ = Splitter(clf=None) for splitter_type in ["best", "random"]: for criterion in ["gini", "entropy"]: for criteria in [ @@ -178,26 +178,23 @@ class Splitter_test(unittest.TestCase): def test_splitter_parameter(self): expected_values = [ - [1, 2], # random gini min_distance - [0, 2], # random gini max_samples - [1, 3], # random gini max_distance - [1, 2], # random entropy min_distance - [1, 2], # random entropy max_samples - [0, 2], # random entropy max_distance - [1, 2], # best gini min_distance - [0, 2], # best gini max_samples - [0, 2], # best gini max_distance - [0, 1], # best entropy min_distance - [0, 1], # best entropy max_samples - [0, 1], # best entropy max_distance + [2, 3, 5, 7], # best entropy min_distance + [0, 2, 4, 5], # best entropy max_samples + [0, 2, 8, 12], # best entropy max_distance + [1, 2, 5, 12], # best gini min_distance + [0, 3, 4, 10], # best gini max_samples + [1, 2, 9, 12], # best gini max_distance + [3, 9, 11, 12], # random entropy min_distance + [1, 5, 6, 9], # random entropy max_samples + [1, 2, 4, 8], # random entropy max_distance + [2, 6, 7, 12], # random gini min_distance + [3, 9, 10, 11], # random gini max_samples + [2, 5, 8, 12], # random gini max_distance ] - X, y = load_dataset(self._random_state, n_features=6, n_classes=3) - from sklearn.datasets import load_iris - - X, y = load_iris(return_X_y=True) + X, y = load_wine(return_X_y=True) rn = 0 - for splitter_type in ["random", "best"]: - for criterion in ["gini", "entropy"]: + for splitter_type in ["best", "random"]: + for criterion in ["entropy", "gini"]: for criteria in [ "min_distance", "max_samples", @@ -207,11 +204,11 @@ class Splitter_test(unittest.TestCase): splitter_type=splitter_type, criterion=criterion, criteria=criteria, - random_state=rn, ) - rn += 3 expected = expected_values.pop(0) - dataset, computed = tcl.get_subspace(X, y, max_features=2) + random.seed(rn) + rn += 1 + dataset, computed = tcl.get_subspace(X, y, max_features=4) # print( # "{}, # {:7s}{:8s}{:15s}".format( # list(computed), splitter_type, criterion,