{ "cells": [ { "cell_type": "markdown", "id": "612527b3", "metadata": {}, "source": [ "# Using probability and membership values of classes for prediction" ] }, { "cell_type": "markdown", "id": "5b7ad80b", "metadata": {}, "source": [ "This example shows how to use probability and membership values of class labels for prediction when applying single hyperbox-based models, ensemble models of hyperbox-based classifiers, and multigranular hyperbox-based models. We employ the original online learning algorithm for general fuzzy min-max neural network, accelerated agglomerative learning algorithm for general fuzzy min-max neural network, Simpson's online learning agorithm for fuzzy min-max neural network, bagging of hyperbox-based models, and multigranular hyperbox-based models for demostration in this tutorial." ] }, { "cell_type": "code", "execution_count": 1, "id": "de2dce99", "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": 2, "id": "911da355", "metadata": {}, "outputs": [], "source": [ "import os\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "c7af4f59", "metadata": {}, "source": [ "### Load training and testing datasets " ] }, { "cell_type": "code", "execution_count": 3, "id": "294a7008", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C:\\\\hyperbox-brain\\\\examples\\\\other_learning_ability_gfmm'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get the path to the this jupyter notebook file\n", "this_notebook_dir = os.path.dirname(os.path.abspath(\"__file__\"))\n", "this_notebook_dir" ] }, { "cell_type": "code", "execution_count": 4, "id": "bab49c9a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "WindowsPath('C:/hyperbox-brain')" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get the home folder of the hyperbox-brain toolbox\n", "from pathlib import Path\n", "project_dir = Path(this_notebook_dir).parent.parent\n", "project_dir" ] }, { "cell_type": "code", "execution_count": 5, "id": "8e9fada2", "metadata": {}, "outputs": [], "source": [ "# Create the path to the training and testing files\n", "training_file = os.path.join(project_dir, Path(\"dataset/syn_num_train.csv\"))\n", "testing_file = os.path.join(project_dir, Path(\"dataset/syn_num_test.csv\"))" ] }, { "cell_type": "code", "execution_count": 6, "id": "04b9e564", "metadata": {}, "outputs": [], "source": [ "# Create training and testing data sets\n", "df_train = pd.read_csv(training_file, header=None)\n", "df_test = pd.read_csv(testing_file, header=None)\n", "\n", "Xy_train = df_train.to_numpy()\n", "Xy_test = df_test.to_numpy()\n", "\n", "Xtr = Xy_train[:, :-1]\n", "ytr = Xy_train[:, -1]\n", "\n", "Xtest = Xy_test[:, :-1]\n", "ytest = Xy_test[:, -1]" ] }, { "cell_type": "markdown", "id": "3574ea5e", "metadata": {}, "source": [ "### 1. Original online learning algorithm for General fuzzy min-max neural network (Onln-GFMM)" ] }, { "cell_type": "code", "execution_count": 7, "id": "abdabe6b", "metadata": {}, "outputs": [], "source": [ "from hbbrain.numerical_data.incremental_learner.onln_gfmm import OnlineGFMM" ] }, { "cell_type": "code", "execution_count": 8, "id": "ea49453a", "metadata": {}, "outputs": [], "source": [ "# Initializing parameters\n", "theta = 0.1\n", "theta_min = 0.1\n", "gamma = 4\n", "is_draw = False" ] }, { "cell_type": "markdown", "id": "6f3e3a55", "metadata": {}, "source": [ "#### Train a model" ] }, { "cell_type": "code", "execution_count": 9, "id": "380dc6a9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OnlineGFMM(C=array([1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1,\n", " 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2, 1, 1,\n", " 2, 2, 1, 2, 2, 2, 2, 2, 1]),\n", " V=array([[0.42413 , 0.53516 ],\n", " [0.70577 , 0.397105 ],\n", " [0.82785 , 0.78025 ],\n", " [0.66038 , 0.51128 ],\n", " [0.48794 , 0.672 ],\n", " [0.26651 , 0.18424 ],\n", " [0.32289 , 0.60194 ],\n", " [0.19944 , 0.03 ],\n", " [0.29343 , 0.28975 ],\n", " [0.63683 , 0.6936 ],\n", " [0.32906 , 0.55512 ],\n", " [0.03 , 0.47757 ],\n", " [0.54...\n", " [0.815 , 0.397095 ],\n", " [0.67906 , 0.83605 ],\n", " [0.37033 , 0.26124 ],\n", " [0.52197 , 0.91371 ],\n", " [0.66037 , 0.57837 ],\n", " [0.52621 , 0.66846 ],\n", " [0.80583 , 0.43242 ],\n", " [0.79935 , 0.7757 ],\n", " [0.35813 , 0.58772 ],\n", " [0.79516 , 0.32629 ],\n", " [0.70743 , 0.50325 ],\n", " [0.36057 , 0.71561 ],\n", " [0.72496 , 0.38674 ],\n", " [0.28822 , 0.62174 ],\n", " [0.14737 , 0.28498 ],\n", " [0.56487 , 0.17003 ],\n", " [0.68469 , 0.2221 ],\n", " [0.55763 , 0.43813 ]]),\n", " gamma=4, theta=0.1, theta_min=0.1)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "onln_gfmm_clf = OnlineGFMM(theta=theta, theta_min=theta_min, gamma=gamma, is_draw=is_draw)\n", "onln_gfmm_clf.fit(Xtr, ytr)" ] }, { "cell_type": "markdown", "id": "5890d07b", "metadata": {}, "source": [ "#### Make prediction" ] }, { "cell_type": "markdown", "id": "f23109ce", "metadata": {}, "source": [ "Use probability values and membership values to make prediction for the first ten testing samples. The orders of columns are also the orders of class labels in an ascending order. In this example, the first column contains the predicted values for class 1, and the second column contains the predicted values for class 2.\n", "\n", "The predicted class probability is the fraction of the membership value of the representative hyperbox of that class and the sum of all membership values of all representative hyperboxes of all classes. The predicted class membership value is the membership value of the representative hyperbox of that class." ] }, { "cell_type": "code", "execution_count": 10, "id": "2946d866", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Input classes: [1. 2.]\n" ] } ], "source": [ "print(\"Input classes: \", np.unique(ytr))" ] }, { "cell_type": "code", "execution_count": 11, "id": "eda26e67", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.50044451, 0.49955549],\n", " [0.48259685, 0.51740315],\n", " [0.42006751, 0.57993249],\n", " [0.52674382, 0.47325618],\n", " [0.46011316, 0.53988684],\n", " [0.50352398, 0.49647602],\n", " [0.49915114, 0.50084886],\n", " [0.3190052 , 0.6809948 ],\n", " [0.50079564, 0.49920436],\n", " [0.44152243, 0.55847757]])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "onln_gfmm_clf.predict_proba(Xtest[:10])" ] }, { "cell_type": "code", "execution_count": 12, "id": "4704f301", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.95696 , 0.95526 ],\n", " [0.76536 , 0.82056 ],\n", " [0.72176 , 0.99644 ],\n", " [0.94304 , 0.84728 ],\n", " [0.85224 , 1. ],\n", " [0.96876 , 0.9552 ],\n", " [0.92908 , 0.93224 ],\n", " [0.46844 , 1. ],\n", " [1. , 0.9968225],\n", " [0.78976 , 0.99896 ]])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "onln_gfmm_clf.predict_with_membership(Xtest[:10])" ] }, { "cell_type": "markdown", "id": "3532adc8", "metadata": {}, "source": [ "### 2. Accelerated agglomerative learning algorithm for General fuzzy min-max neural network (AGGLO-2)" ] }, { "cell_type": "code", "execution_count": 13, "id": "ec33c7ce", "metadata": {}, "outputs": [], "source": [ "from hbbrain.numerical_data.batch_learner.accel_agglo_gfmm import AccelAgglomerativeLearningGFMM" ] }, { "cell_type": "code", "execution_count": 14, "id": "b7d3bde9", "metadata": {}, "outputs": [], "source": [ "# Initializing parameters\n", "theta=0.1\n", "gamma=4\n", "min_simil=0\n", "simil_measure='long'\n", "is_draw=False" ] }, { "cell_type": "markdown", "id": "af19cf8e", "metadata": {}, "source": [ "#### Train a model" ] }, { "cell_type": "code", "execution_count": 15, "id": "3052c18a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "AccelAgglomerativeLearningGFMM(gamma=4, min_simil=0, simil_measure='long',\n", " theta=0.1)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "agglo2_gfmm_clf = AccelAgglomerativeLearningGFMM(theta=theta, gamma=gamma, min_simil=min_simil, simil_measure=simil_measure, is_draw=is_draw)\n", "agglo2_gfmm_clf.fit(Xtr, ytr)" ] }, { "cell_type": "markdown", "id": "9fecaa33", "metadata": {}, "source": [ "#### Make prediction" ] }, { "cell_type": "code", "execution_count": 16, "id": "fc2c68ec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.50882641, 0.49117359],\n", " [0.47279466, 0.52720534],\n", " [0.42148046, 0.57851954],\n", " [0.56160076, 0.43839924],\n", " [0.46758668, 0.53241332],\n", " [0.50352398, 0.49647602],\n", " [0.49915114, 0.50084886],\n", " [0.20099716, 0.79900284],\n", " [0.49770692, 0.50229308],\n", " [0.44615176, 0.55384824]])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "agglo2_gfmm_clf.predict_proba(Xtest[:10])" ] }, { "cell_type": "code", "execution_count": 17, "id": "af0ff336", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.95696, 0.92376],\n", " [0.76536, 0.85344],\n", " [0.72176, 0.99068],\n", " [0.94304, 0.73616],\n", " [0.87824, 1. ],\n", " [0.96876, 0.9552 ],\n", " [0.92908, 0.93224],\n", " [0.25156, 1. ],\n", " [0.9116 , 0.92 ],\n", " [0.78976, 0.9804 ]])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "agglo2_gfmm_clf.predict_with_membership(Xtest[:10])" ] }, { "cell_type": "markdown", "id": "a0d04aec", "metadata": {}, "source": [ "### 3. Original online learning algorithm for Simpson's Fuzzy min-max neural network (FMNN)" ] }, { "cell_type": "code", "execution_count": 18, "id": "2419157f", "metadata": {}, "outputs": [], "source": [ "from hbbrain.numerical_data.incremental_learner.fmnn import FMNNClassifier" ] }, { "cell_type": "code", "execution_count": 19, "id": "42ca9c6b", "metadata": {}, "outputs": [], "source": [ "# Initializing parameters\n", "theta = 0.1\n", "gamma = 4\n", "is_draw = False" ] }, { "cell_type": "markdown", "id": "0fc99d74", "metadata": {}, "source": [ "#### Train a model" ] }, { "cell_type": "code", "execution_count": 20, "id": "d62d8677", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "FMNNClassifier(C=array([1, 2, 1, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 2,\n", " 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1,\n", " 2, 1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2,\n", " 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 1, 2,\n", " 1, 1, 1]),\n", " V=array([[0.36239 , 0.55942 ],\n", " [0.64082 , 0.43016875],\n", " [0.91059 , 0.82085 ],\n", " [0.65328 , 0.50326 ],\n", " [0.46107 , 0.68306 ],\n", " [0.29812 , 0.18424 ],\n", " [0.33593 , 0.68775 ],\n", " [0.1...\n", " [0.25621 , 0.62174 ],\n", " [0.42403 , 0.7592 ],\n", " [0.79157 , 0.59996 ],\n", " [0.72496 , 0.34978 ],\n", " [0.36842 , 0.76576 ],\n", " [0.73681 , 0.71261 ],\n", " [0.66773 , 0.31155 ],\n", " [0.32289 , 0.6747 ],\n", " [0.28077 , 0.27116 ],\n", " [0.61106 , 0.28476 ],\n", " [0.75421 , 0.40498 ],\n", " [0.38038 , 0.67232 ],\n", " [0.36745 , 0.52006 ],\n", " [0.91185 , 0.48697 ],\n", " [0.35813 , 0.58584 ],\n", " [0.25924 , 0.42696 ],\n", " [0.70685 , 0.64383 ],\n", " [0.75047 , 0.6092 ],\n", " [0.72842 , 0.61048 ]]),\n", " gamma=4, theta=0.1)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fmnn_clf = FMNNClassifier(theta=theta, gamma=gamma, is_draw=is_draw)\n", "fmnn_clf.fit(Xtr, ytr)" ] }, { "cell_type": "markdown", "id": "af0aa4fd", "metadata": {}, "source": [ "#### Make prediction" ] }, { "cell_type": "code", "execution_count": 21, "id": "a487385c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.5001282 , 0.4998718 ],\n", " [0.49113606, 0.50886394],\n", " [0.47048553, 0.52951447],\n", " [0.51190571, 0.48809429],\n", " [0.49033913, 0.50966087],\n", " [0.5028714 , 0.4971286 ],\n", " [0.49750079, 0.50249921],\n", " [0.41923606, 0.58076394],\n", " [0.49781361, 0.50218639],\n", " [0.47269621, 0.52730379]])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fmnn_clf.predict_proba(Xtest[:10])" ] }, { "cell_type": "code", "execution_count": 22, "id": "3620e992", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.9801625 , 0.97966 ],\n", " [0.92338 , 0.95671 ],\n", " [0.8885225 , 1. ],\n", " [0.96807 , 0.92304 ],\n", " [0.96158875, 0.99948 ],\n", " [1. , 0.98858 ],\n", " [0.97989 , 0.989735 ],\n", " [0.72187 , 1. ],\n", " [0.9912925 , 1. ],\n", " [0.89644 , 1. ]])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fmnn_clf.predict_with_membership(Xtest[:10])" ] }, { "cell_type": "markdown", "id": "ad75d0cb", "metadata": {}, "source": [ "### 4. Bagging of base general fuzzy min-max neural networks trained by the original online learning algorithm" ] }, { "cell_type": "code", "execution_count": 23, "id": "4e19d543", "metadata": {}, "outputs": [], "source": [ "from hbbrain.numerical_data.ensemble_learner.decision_comb_bagging import DecisionCombinationBagging" ] }, { "cell_type": "code", "execution_count": 24, "id": "ff2510d8", "metadata": {}, "outputs": [], "source": [ "# Initialise parameters\n", "n_estimators = 20 # number of base learners\n", "max_samples = 0.5 # sampling rate for samples\n", "bootstrap = False # random subsampling without replacement\n", "class_balanced = False # do not use the class-balanced sampling mode\n", "n_jobs = 4 # number of processes is used to build base learners" ] }, { "cell_type": "markdown", "id": "4b765f9b", "metadata": {}, "source": [ "#### Train a bagging model" ] }, { "cell_type": "code", "execution_count": 25, "id": "b0cc009c", "metadata": {}, "outputs": [], "source": [ "# Init a hyperbox-based model used to train base learners\n", "# Using the GFMM classifier with the original online learning algorithm with the maximum hyperbox size 0.1\n", "base_estimator = OnlineGFMM(theta=theta, gamma=gamma)" ] }, { "cell_type": "code", "execution_count": 26, "id": "251d1fe3", "metadata": {}, "outputs": [], "source": [ "dc_bagging_subsampling = DecisionCombinationBagging(base_estimator=base_estimator, n_estimators=n_estimators, max_samples=max_samples, bootstrap=bootstrap, class_balanced=class_balanced, n_jobs=n_jobs, random_state=0)" ] }, { "cell_type": "code", "execution_count": 27, "id": "8b0fd4e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DecisionCombinationBagging(base_estimator=OnlineGFMM(C=array([], dtype=float64),\n", " V=array([], dtype=float64),\n", " W=array([], dtype=float64),\n", " gamma=4, theta=0.1),\n", " n_estimators=20, n_jobs=4, random_state=0)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dc_bagging_subsampling.fit(Xtr, ytr)" ] }, { "cell_type": "markdown", "id": "0b33991d", "metadata": {}, "source": [ "#### Make prediction" ] }, { "cell_type": "markdown", "id": "15646ab7", "metadata": {}, "source": [ "This example shows how to use predict_proba and predict_with_membership functions to make prediction. The predicted class probabilities of an input sample with respect to an ensemble model are computed as the mean predicted class probabilities of the hyperbox-based learners in the ensemble model. The class probability of a single hyperbox-based learner is the fraction of the membership value of the representative hyperbox of that class and the sum of all membership values of all representative hyperboxes of all classes.\n", "\n", "The predicted class memberships of an input sample are computed as the mean predicted class memberships of the hyperbox-based learners in the ensemble model. The class membership of a single hyperbox-based learner is the membership from the input X to the representative hyperbox of that class to join the prediction procedure." ] }, { "cell_type": "code", "execution_count": 28, "id": "a75cfdb0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.47815396, 0.52184604],\n", " [0.5012498 , 0.4987502 ],\n", " [0.3955224 , 0.6044776 ],\n", " [0.54362581, 0.45637419],\n", " [0.47159695, 0.52840305],\n", " [0.52292342, 0.47707658],\n", " [0.49756119, 0.50243881],\n", " [0.1964586 , 0.8035414 ],\n", " [0.47362699, 0.52637301],\n", " [0.39199205, 0.60800795]])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dc_bagging_subsampling.predict_proba(Xtest[:10])" ] }, { "cell_type": "code", "execution_count": 29, "id": "c7d1c540", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.843956 , 0.91573 ],\n", " [0.818432 , 0.810635 ],\n", " [0.639162 , 0.963144 ],\n", " [0.87822 , 0.7370675 ],\n", " [0.858645 , 0.958337 ],\n", " [0.98751575, 0.90252725],\n", " [0.916385 , 0.927697 ],\n", " [0.232785 , 0.932006 ],\n", " [0.86215975, 0.953138 ],\n", " [0.6373855 , 0.977412 ]])" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dc_bagging_subsampling.predict_with_membership(Xtest[:10])" ] }, { "cell_type": "markdown", "id": "e3315b7f", "metadata": {}, "source": [ "### 5. Multi-resolution Hierarchical Granular Representation based Classifier using GFMM" ] }, { "cell_type": "code", "execution_count": 30, "id": "8f230f65", "metadata": {}, "outputs": [], "source": [ "from hbbrain.numerical_data.multigranular_learner.multi_resolution_gfmm import MultiGranularGFMM" ] }, { "cell_type": "code", "execution_count": 31, "id": "09baf4e4", "metadata": {}, "outputs": [], "source": [ "# Initializing parameters\n", "# number of disjoint partitions to build base learners\n", "n_partitions = 4\n", "# a list of maximum hyperbox sizes for granularity levels\n", "granular_theta = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]\n", "# minimum membership values between two hyperboxes aggregated at higher abstraction levels\n", "min_membership_aggregation = 0.1\n", "# the speed of decreasing of membership values\n", "gamma = 4" ] }, { "cell_type": "markdown", "id": "ab24dc5d", "metadata": {}, "source": [ "#### Training a multigranular model" ] }, { "cell_type": "code", "execution_count": 32, "id": "2afd9155", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[Parallel(n_jobs=4)]: Using backend LokyBackend with 4 concurrent workers.\n", "[Parallel(n_jobs=4)]: Done 2 out of 4 | elapsed: 2.7s remaining: 2.7s\n", "[Parallel(n_jobs=4)]: Done 4 out of 4 | elapsed: 2.7s finished\n" ] }, { "data": { "text/plain": [ "MultiGranularGFMM(gamma=4, granular_theta=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6],\n", " min_membership_aggregation=0.1)" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from hbbrain.constants import HETEROGENEOUS_CLASS_LEARNING\n", "multi_granular_gfmm_clf = MultiGranularGFMM(n_partitions=n_partitions, granular_theta=granular_theta, gamma=gamma, min_membership_aggregation=min_membership_aggregation)\n", "# Training using the heterogeneous model for class labels.\n", "multi_granular_gfmm_clf.fit(Xtr, ytr, learning_type=HETEROGENEOUS_CLASS_LEARNING)" ] }, { "cell_type": "markdown", "id": "d75daac3", "metadata": {}, "source": [ "#### Make prediction" ] }, { "cell_type": "markdown", "id": "714fed0f", "metadata": {}, "source": [ "The predicted class probability at a given granularity level is the fraction of the membership value of the representative hyperbox of that class at the given granularity level and the sum of all membership values of all representative hyperboxes of all classes joining the prediction procedure. If the given granularity level gets the values of -1, then the predicted class probability value for each sample is the average of probability values at all available granularity levels. Similar meaning is applied for the predicted class membership values." ] }, { "cell_type": "code", "execution_count": 33, "id": "13c24520", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.51102808, 0.48897192],\n", " [0.54380893, 0.45619107],\n", " [0.39490266, 0.60509734],\n", " [0.54865927, 0.45134073],\n", " [0.46152604, 0.53847396],\n", " [0.52639798, 0.47360202],\n", " [0.48346396, 0.51653604],\n", " [0.2453813 , 0.7546187 ],\n", " [0.45120077, 0.54879923],\n", " [0.44126587, 0.55873413]])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Predicted class probability values for the first ten samples based on the average values of all available granularity levels\n", "multi_granular_gfmm_clf.predict_proba(Xtest[:10], level=-1)" ] }, { "cell_type": "code", "execution_count": 34, "id": "330f6be1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.51670508, 0.48329492],\n", " [0.54928154, 0.45071846],\n", " [0.38979741, 0.61020259],\n", " [0.54133645, 0.45866355],\n", " [0.45073053, 0.54926947],\n", " [0.51150372, 0.48849628],\n", " [0.47904728, 0.52095272],\n", " [0.20099716, 0.79900284],\n", " [0.43810123, 0.56189877],\n", " [0.44126587, 0.55873413]])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Predicted class probability values for the first ten samples at the second granularity level\n", "multi_granular_gfmm_clf.predict_proba(Xtest[:10], level=1)" ] }, { "cell_type": "code", "execution_count": 35, "id": "7bbaeb0c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.98879333, 0.94611667],\n", " [0.97816 , 0.82056 ],\n", " [0.65262667, 1. ],\n", " [0.9936 , 0.81736 ],\n", " [0.8571 , 1. ],\n", " [1. , 0.89970333],\n", " [0.93597333, 1. ],\n", " [0.32505333, 0.99963333],\n", " [0.82216 , 1. ],\n", " [0.78976 , 1. ]])" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Predicted class membership values for the first ten samples based on the average values of all available granularity levels\n", "multi_granular_gfmm_clf.predict_with_membership(Xtest[:10], level=-1)" ] }, { "cell_type": "code", "execution_count": 36, "id": "12db8368", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1. , 0.93534],\n", " [1. , 0.82056],\n", " [0.6388 , 1. ],\n", " [1. , 0.84728],\n", " [0.8206 , 1. ],\n", " [1. , 0.95502],\n", " [0.91956, 1. ],\n", " [0.25156, 1. ],\n", " [0.77968, 1. ],\n", " [0.78976, 1. ]])" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Predicted class membership values for the first ten samples at the second granularity level\n", "multi_granular_gfmm_clf.predict_with_membership(Xtest[:10], level=1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }