{ "cells": [ { "cell_type": "markdown", "id": "d7d4a567", "metadata": {}, "source": [ "# Evaluating an active learning pipeline using the evaluator\n", "In this example we will specify and evaluate an active learning pipeline using the **Evaluator**, which can be done in only **a few lines of code**. The query strategy, learning algorithm and setting have to be specified by strings. (Check ALP/evaluation/experimenter/DefaultSetup.py to ensure you are using the same descriptions we are using.)" ] }, { "cell_type": "code", "execution_count": 1, "id": "f7efe8ce", "metadata": {}, "outputs": [], "source": [ "from sklearn.metrics import accuracy_score\n", "\n", "from alpbench.benchmark.BenchmarkConnector import DataFileBenchmarkConnector\n", "from alpbench.evaluation.experimenter.DefaultSetup import ensure_default_setup\n", "from alpbench.pipeline.ALPEvaluator import ALPEvaluator" ] }, { "cell_type": "markdown", "id": "07e8a070", "metadata": {}, "source": [ "### Establish the database connection" ] }, { "cell_type": "code", "execution_count": 2, "id": "5b95dfa5", "metadata": {}, "outputs": [], "source": [ "# create benchmark connector and establish database connection\n", "benchmark_connector = DataFileBenchmarkConnector()\n", "\n", "# load some default settings and algorithm choices\n", "ensure_default_setup(benchmark_connector)" ] }, { "cell_type": "markdown", "id": "290042e6", "metadata": {}, "source": [ "### Fit an ALP " ] }, { "cell_type": "code", "execution_count": 3, "id": "c6a39dde", "metadata": {}, "outputs": [], "source": [ "# we choose dataset with **openmlid 31**, the ALP is composed out of a **rf and BALD**\n", "evaluator = ALPEvaluator(\n", " benchmark_connector=benchmark_connector,\n", " setting_name=\"small\",\n", " openml_id=31,\n", " query_strategy_name=\"bald\",\n", " learner_name=\"rf_entropy\",\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "id": "9419ce82", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "final test acc 0.7454545454545455\n" ] } ], "source": [ "alp = evaluator.fit()\n", "\n", "# fit / predict and evaluate predictions\n", "X_test, y_test = evaluator.get_test_data()\n", "y_hat = alp.predict(X=X_test)\n", "print(\"final test acc\", accuracy_score(y_test, y_hat))" ] }, { "cell_type": "code", "execution_count": null, "id": "42862f69", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "alpbench kernel release 0.1.1", "language": "python", "name": "test_venv3" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }