{ "cells": [ { "cell_type": "markdown", "id": "57e279da-2992-48d5-ace4-ae421f69e8d2", "metadata": {}, "source": [ "# Analyzing classification result" ] }, { "cell_type": "code", "execution_count": 194, "id": "1e5597b1-b1a0-4015-b2b2-3f539435a3dc", "metadata": {}, "outputs": [], "source": [ "import logging\n", "import pickle\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from mne.decoding import CSP\n", "\n", "mne_logger = logging.getLogger('mne')\n", "mne_logger.setLevel(logging.ERROR)" ] }, { "cell_type": "code", "execution_count": 195, "id": "8eb6d6b1-a92b-41ed-8446-29f165c00329", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import RepeatedKFold\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.pipeline import make_pipeline\n", "from sklearn.preprocessing import StandardScaler\n", "from sklearn.svm import SVC\n", "from sklearn.preprocessing import FunctionTransformer\n", "from sklearn.linear_model import LogisticRegression\n", "from sklearn.preprocessing import FunctionTransformer\n", "from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA" ] }, { "cell_type": "code", "execution_count": 196, "id": "74f509ab-bfdd-42b8-abab-4507b0602133", "metadata": {}, "outputs": [], "source": [ "import conf\n", "import utils\n", "import transforms as trans" ] }, { "cell_type": "markdown", "id": "1e3368f3-cd01-432e-a374-673c4c938735", "metadata": {}, "source": [ "## Building and running the best pipeline (`csp_svm`)" ] }, { "cell_type": "markdown", "id": "0b26b767-862e-4a01-b7d5-42864230292a", "metadata": {}, "source": [ "Next, we run the best pipeline once which we have developed which provided 85.3%\n", "accuracy previously." ] }, { "cell_type": "code", "execution_count": 197, "id": "30009cd7-f4d9-4a04-854a-25d36c40beef", "metadata": {}, "outputs": [], "source": [ "# Load our dataset\n", "with (conf.DATA_DIR / \"filteredX.pickle\").open(\"rb\") as f:\n", " filteredX = pickle.load(f)\n", " \n", "with (conf.DATA_DIR / \"y.npy\").open(\"rb\") as f:\n", " y = pickle.load(f)" ] }, { "cell_type": "code", "execution_count": 198, "id": "3e519585-58ce-4860-9b65-c468c8b18adb", "metadata": {}, "outputs": [], "source": [ "best_start = conf.dT - 0.1\n", "\n", "window_length = 0.3\n", "\n", "clf = make_pipeline(\n", " trans.GetWindow(best_start, best_start + window_length),\n", " trans.NpArrayTransform,\n", " CSP(),\n", " SVC(gamma='auto'),\n", ")" ] }, { "cell_type": "code", "execution_count": 200, "id": "2d89ca26-098b-4a3d-b1ff-2e4e1df2884a", "metadata": {}, "outputs": [], "source": [ "clf.fit(filteredX, y); pass" ] }, { "cell_type": "code", "execution_count": 201, "id": "b1ea3a08-d790-4e5f-bfd5-ec44ea2703b6", "metadata": {}, "outputs": [], "source": [ "y_hat = clf.predict(filteredX)" ] }, { "cell_type": "markdown", "id": "ca9d56b4-eaf5-4e17-8308-5d8d9e2cf217", "metadata": {}, "source": [ "## Obtaining GWOSC Parameter Estimations for detected coalescenses" ] }, { "cell_type": "code", "execution_count": 208, "id": "4791c190-9cdc-45c7-bbc7-da1e521cdca6", "metadata": {}, "outputs": [], "source": [ "# Get the GWOSC catalog containing estimated parameters\n", "\n", "confident = pd.read_csv(\"https://www.gw-openscience.org/eventapi/csv/allevents/\")" ] }, { "cell_type": "code", "execution_count": 209, "id": "e1579bec-f004-4084-8fac-01950724d6b0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | id | \n", "commonName | \n", "version | \n", "catalog.shortName | \n", "GPS | \n", "reference | \n", "jsonurl | \n", "mass_1_source | \n", "mass_1_source_lower | \n", "mass_1_source_upper | \n", "... | \n", "redshift_upper | \n", "far | \n", "far_lower | \n", "far_upper | \n", "p_astro | \n", "p_astro_lower | \n", "p_astro_upper | \n", "final_mass_source | \n", "final_mass_source_lower | \n", "final_mass_source_upper | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "151008-v1 | \n", "151008 | \n", "1 | \n", "GWTC-1-marginal | \n", "1.128349e+09 | \n", "https://doi.org/10.7935/82H3-HH23 | \n", "https://www.gw-openscience.org/eventapi/json/G... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "10.17 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 1 | \n", "151012.2-v1 | \n", "151012.2 | \n", "1 | \n", "GWTC-1-marginal | \n", "1.128667e+09 | \n", "https://doi.org/10.7935/82H3-HH23 | \n", "https://www.gw-openscience.org/eventapi/json/G... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "8.56 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 2 | \n", "151116-v1 | \n", "151116 | \n", "1 | \n", "GWTC-1-marginal | \n", "1.131749e+09 | \n", "https://doi.org/10.7935/82H3-HH23 | \n", "https://www.gw-openscience.org/eventapi/json/G... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "4.77 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
3 rows × 43 columns
\n", "