CaseBasedReasoning/explore.ipynb

103 lines
2.5 KiB
Plaintext
Raw Normal View History

2022-12-13 13:25:31 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from model import *\n",
"from similarity import *\n",
"import csv"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"case_base = CaseBase.from_csv(\n",
" \"data/SIM_001.csv\",\n",
" problem_fields = (\"v\", \"v_left\", \"v_front\", \"d_left\", \"d_front\", \"type_left\", \"type_front\", \"radius_curve(m)\", \"slope_street\", \"street_type\", \"time\", \"weather\", \"type_vehicle\", \"speed_limit(km/h)\"),\n",
" solution_fields = (\"action\"),\n",
" encoding = \"utf-8\",\n",
" delimiter = \";\",\n",
" set_int = True\n",
")\n",
"print(case_base)\n",
"case_base[:3]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"query = Query.from_problems(\n",
" v = 28,\n",
" v_left = 37,\n",
" v_front = 22.5,\n",
" d_left = -20,\n",
" d_front = 51,\n",
")\n",
"# sim_funcs: manhattan_sim, euclid_sim\n",
"\n",
"retrieved = case_base.retrieve(\n",
" query,\n",
" v_left = euclid_sim,\n",
" v_front = euclid_sim,\n",
" d_left = euclid_sim,\n",
" d_front = euclid_sim,\n",
")\n",
"\n",
"print(\"Your Query:\")\n",
"for k, v in query.problem.items():\n",
" print(f\" - {k} = {v}\")\n",
"print()\n",
"print(\"I recommend you this car:\")\n",
"print(\" \".join(retrieved.solution.values()).capitalize())\n",
"print()\n",
"print(\"Explanation:\")\n",
"for field, sim_val in retrieved.sim_per_field.items():\n",
" print(f\" - {field} =\", retrieved.problem[field], f\"(similarity: {sim_val:.2f})\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.0"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}