{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connection closed.\n", "Connected. Call `.close()` to terminate connection gracefully.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Logged in to project, explore it here https://c.app.hopsworks.ai:443/p/1160344\n", "Connected. Call `.close()` to terminate connection gracefully.\n", "Connected. Call `.close()` to terminate connection gracefully.\n" ] } ], "source": [ "import datetime\n", "import pandas as pd\n", "from xgboost import XGBRegressor\n", "import hopsworks\n", "import json\n", "from functions import util\n", "import os\n", "\n", "# Set up\n", "\n", "api_key = os.getenv('HOPSWORKS_API_KEY')\n", "project_name = os.getenv('HOPSWORKS_PROJECT')\n", "\n", "project = hopsworks.login(project=project_name, api_key_value=api_key)\n", "fs = project.get_feature_store() \n", "secrets = util.secrets_api(project.name)\n", "location_str = secrets.get_secret(\"SENSOR_LOCATION_JSON\").value\n", "location = json.loads(location_str)\n", "country=location['country']\n", "city=location['city']\n", "street=location['street']\n", "\n", "AQI_API_KEY = secrets.get_secret(\"AQI_API_KEY\").value\n", "location_str = secrets.get_secret(\"SENSOR_LOCATION_JSON\").value\n", "location = json.loads(location_str)\n", "\n", "today = datetime.datetime.now() - datetime.timedelta(0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected. Call `.close()` to terminate connection gracefully.\n", "Finished: Reading data from Hopsworks, using Hopsworks Feature Query Service (1.02s) \n" ] } ], "source": [ "### Retreive model\n", "\n", "mr = project.get_model_registry()\n", "\n", "retrieved_model = mr.get_model(\n", " name=\"air_quality_xgboost_model\",\n", " version=1,\n", ")\n", "\n", "saved_model_dir = retrieved_model.download()\n", "retrieved_xgboost_model = XGBRegressor()\n", "retrieved_xgboost_model.load_model(saved_model_dir + \"/model.json\")\n", "\n", "### Retrieve features \n", "\n", "weather_fg = fs.get_feature_group(\n", " name='weather',\n", " version=1,\n", ")\n", "\n", "today_timestamp = pd.to_datetime(today)\n", "batch_data = weather_fg.filter(weather_fg.date >= today_timestamp ).read().sort_values(by=['date'])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | date | \n", "temperature_2m_mean | \n", "precipitation_sum | \n", "wind_speed_10m_max | \n", "wind_direction_10m_dominant | \n", "city | \n", "
---|---|---|---|---|---|---|
1 | \n", "2024-11-21 00:00:00+00:00 | \n", "21.700001 | \n", "0.0 | \n", "1.138420 | \n", "71.564964 | \n", "lahore | \n", "
4 | \n", "2024-11-22 00:00:00+00:00 | \n", "21.850000 | \n", "0.0 | \n", "4.610250 | \n", "128.659836 | \n", "lahore | \n", "
7 | \n", "2024-11-23 00:00:00+00:00 | \n", "22.250000 | \n", "0.0 | \n", "5.091168 | \n", "44.999897 | \n", "lahore | \n", "
6 | \n", "2024-11-24 00:00:00+00:00 | \n", "21.400000 | \n", "0.0 | \n", "4.334974 | \n", "318.366547 | \n", "lahore | \n", "
5 | \n", "2024-11-25 00:00:00+00:00 | \n", "20.750000 | \n", "0.0 | \n", "6.439876 | \n", "296.564972 | \n", "lahore | \n", "
2 | \n", "2024-11-26 00:00:00+00:00 | \n", "20.750000 | \n", "0.0 | \n", "4.680000 | \n", "270.000000 | \n", "lahore | \n", "
0 | \n", "2024-11-27 00:00:00+00:00 | \n", "20.350000 | \n", "0.0 | \n", "4.104631 | \n", "37.875053 | \n", "lahore | \n", "
3 | \n", "2024-11-28 00:00:00+00:00 | \n", "19.799999 | \n", "0.0 | \n", "2.189795 | \n", "9.462248 | \n", "lahore | \n", "