{ "cells": [ { "cell_type": "code", "execution_count": 1, "source": [ "from femda import FEMDA" ], "outputs": [], "metadata": {} }, { "cell_type": "markdown", "source": [ "# 1. Using FEMDA in a sklearn.pipeline" ], "metadata": {} }, { "cell_type": "code", "execution_count": 1, "source": [ "from sklearn.datasets import load_iris, load_digits\r\n", "from sklearn.pipeline import make_pipeline\r\n", "from sklearn.model_selection import train_test_split\r\n", "from sklearn.decomposition import PCA\r\n", "\r\n", "X, y = load_digits(return_X_y=True)\r\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 2, "source": [ "pipe = make_pipeline(PCA(n_components=5), FEMDA())" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 3, "source": [ "pipe.fit(X_train, y_train)" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Pipeline(steps=[('pca', PCA(n_components=5)), ('femda', FEMDA())])" ] }, "metadata": {}, "execution_count": 3 } ], "metadata": {} }, { "cell_type": "code", "execution_count": 4, "source": [ "print(pipe.score(X_test, y_test))\r\n", "\r\n", "y_pred = pipe.predict(X_test)\r\n", "#from sklearn.metrics import classification_report\r\n", "#print(classification_report(y_test, y_pred))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "0.8855218855218855\n" ] } ], "metadata": {} }, { "cell_type": "markdown", "source": [ "# 2. Testing FEMDA on other datasets" ], "metadata": {} }, { "cell_type": "code", "execution_count": 7, "source": [ "import femda.experiments.preprocessing as pre\r\n", "from femda._models_lda import LDA, QDA\r\n", "from femda._models_t_lda import t_QDA\r\n", "X_train, y_train, X_test, y_test = pre.ionosphere(r\"data\\Paper\\\\\") \r\n", "#Choose between ionosphere, statlog, ecoli, breast_cancer, spam_base" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 8, "source": [ "print(\"FEMDA\", FEMDA().fit(X_train, y_train).score(X_test, y_test))\r\n", "print(\"t_QDA\", t_QDA().fit(X_train, y_train).score(X_test, y_test))\r\n", "print(\"LDA\", LDA() .fit(X_train, y_train).score(X_test, y_test))\r\n", "print(\"QDA\", QDA() .fit(X_train, y_train).score(X_test, y_test))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "FEMDA 0.9339622641509434\n", "t_QDA 0.9339622641509434\n", "LDA 0.8773584905660378\n", "QDA 0.8867924528301887\n" ] } ], "metadata": {} }, { "cell_type": "markdown", "source": [ "# 3. Running experiments presented in the paper" ], "metadata": {} }, { "cell_type": "code", "execution_count": 5, "source": [ "from femda.experiments import run_experiments" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "run_experiments()" ], "outputs": [], "metadata": {} }, { "cell_type": "markdown", "source": [ "# Check estimator" ], "metadata": {} }, { "cell_type": "code", "execution_count": 9, "source": [ "from sklearn.utils.estimator_checks import check_estimator" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 10, "source": [ "f = FEMDA()" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 11, "source": [ "print(check_estimator(f) == None)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "True\n" ] } ], "metadata": {} } ], "metadata": { "interpreter": { "hash": "c7a650d791d0a1d035b66682f8967f04fed3045153a1ba3c3bfeefd2541b18a6" }, "kernelspec": { "name": "python3", "display_name": "Python 3.8.7 64-bit" }, "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.8.7" } }, "nbformat": 4, "nbformat_minor": 4 }