{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "cc80518c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Health: {'status': 'ok'}\n", "Predicted cancellation probabilities: [0.3003077208995819]\n" ] } ], "source": [ "import requests\n", "\n", "# Set your API endpoint (local or HF Space)\n", "API = \"https://rjuro-hotel-cancel-api.hf.space\"\n", "print(\"Health:\", requests.get(f\"{API}/health\", timeout=15).json())\n", "\n", "payload = {\n", " \"data\": [\n", " {\n", " \"lead_time\":120, \"arrival_date_week_number\":40, \"arrival_date_day_of_month\":15,\n", " \"stays_in_weekend_nights\":1, \"stays_in_week_nights\":2, \"adults\":2, \"children\":0, \"babies\":0,\n", " \"is_repeated_guest\":0, \"previous_cancellations\":0, \"previous_bookings_not_canceled\":1,\n", " \"booking_changes\":0, \"agent\":0, \"days_in_waiting_list\":0, \"adr\":140.0,\n", " \"required_car_parking_spaces\":0, \"total_of_special_requests\":1, \"total_guests\":2,\n", " \"total_nights\":3, \"is_summer\":0, \"previous_cancellation_rate\":0.0,\n", " \"hotel\":\"City Hotel\", \"meal\":\"BB\", \"market_segment\":\"Online TA\",\n", " \"distribution_channel\":\"TA/TO\", \"reserved_room_type\":\"A\", \"deposit_type\":\"No Deposit\",\n", " \"customer_type\":\"Transient\"\n", " }\n", " ]\n", "}\n", "\n", "\n", "resp = requests.post(f\"{API}/predict_batch\", json=payload, timeout=30)\n", "resp.raise_for_status()\n", "print(\"Predicted cancellation probabilities:\", resp.json()[\"probabilities\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "a1b481dc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'features': ['lead_time',\n", " 'arrival_date_week_number',\n", " 'arrival_date_day_of_month',\n", " 'stays_in_weekend_nights',\n", " 'stays_in_week_nights',\n", " 'adults',\n", " 'children',\n", " 'babies',\n", " 'is_repeated_guest',\n", " 'previous_cancellations',\n", " 'previous_bookings_not_canceled',\n", " 'booking_changes',\n", " 'agent',\n", " 'days_in_waiting_list',\n", " 'adr',\n", " 'required_car_parking_spaces',\n", " 'total_of_special_requests',\n", " 'total_guests',\n", " 'total_nights',\n", " 'is_summer',\n", " 'previous_cancellation_rate',\n", " 'hotel',\n", " 'meal',\n", " 'market_segment',\n", " 'distribution_channel',\n", " 'reserved_room_type',\n", " 'deposit_type',\n", " 'customer_type']}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 2) Discover expected feature names (nice sanity check)\n", "import requests\n", "API = \"https://rjuro-hotel-cancel-api.hf.space\"\n", "requests.get(f\"{API}/features\", timeout=15).json()" ] }, { "cell_type": "code", "execution_count": 10, "id": "40da2ed6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " baseline: 0.300\n", " riskier_long_lead: 0.556\n", "safer_repeated_guest: 0.138\n", " safer_refundable: 0.401\n" ] } ], "source": [ "import requests, copy\n", "API = \"https://rjuro-hotel-cancel-api.hf.space\"\n", "\n", "base = {\n", " \"lead_time\":120,\"arrival_date_week_number\":40,\"arrival_date_day_of_month\":15,\n", " \"stays_in_weekend_nights\":1,\"stays_in_week_nights\":2,\"adults\":2,\"children\":0,\"babies\":0,\n", " \"is_repeated_guest\":0,\"previous_cancellations\":0,\"previous_bookings_not_canceled\":1,\n", " \"booking_changes\":0,\"agent\":0,\"days_in_waiting_list\":0,\"adr\":140.0,\n", " \"required_car_parking_spaces\":0,\"total_of_special_requests\":1,\"total_guests\":2,\n", " \"total_nights\":3,\"is_summer\":0,\"previous_cancellation_rate\":0.0,\n", " \"hotel\":\"City Hotel\",\"meal\":\"BB\",\"market_segment\":\"Online TA\",\n", " \"distribution_channel\":\"TA/TO\",\"reserved_room_type\":\"A\",\"deposit_type\":\"No Deposit\",\n", " \"customer_type\":\"Transient\"\n", "}\n", "\n", "tests = {\n", " \"baseline\": base,\n", " \"riskier_long_lead\": {**base, \"lead_time\": 300, \"total_of_special_requests\": 0},\n", " \"safer_repeated_guest\": {**base, \"is_repeated_guest\": 1, \"total_of_special_requests\": 3, \"lead_time\": 10},\n", " \"safer_refundable\": {**base, \"deposit_type\": \"Refundable\", \"total_of_special_requests\": 2},\n", "}\n", "\n", "payload = {\"data\": list(tests.values())}\n", "probs = requests.post(f\"{API}/predict_batch\", json=payload, timeout=30).json()[\"probabilities\"]\n", "for name, p in zip(tests.keys(), probs):\n", " print(f\"{name:>20}: {p:.3f}\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "0852a1c1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'probabilities': [0.999868631362915]}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tests = [{**base, \"deposit_type\":\"Non Refund\"}]\n", "requests.post(f\"{API}/predict_batch\", json={\"data\":tests}, timeout=30).json()" ] }, { "cell_type": "code", "execution_count": null, "id": "2b4ad53c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "langcorn", "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.5" } }, "nbformat": 4, "nbformat_minor": 5 }