{ "cells": [ { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
property_typepricelocationcitybathspurposebedroomsArea_in_Marla
108839House13800000Pak Arab Housing SocietyLahore3For Sale35.0
97355House17500000Marghzar Officers ColonyLahore6For Sale610.0
125129House12500000Adiala RoadRawalpindi5For Sale510.0
155467Lower Portion47000Satellite TownRawalpindi3For Rent37.0
81132House7800000Shalimar Housing SchemeLahore4For Sale34.0
...........................
122491House19000000Lake CityLahore5For Sale410.0
44101Upper Portion40000Korang TownIslamabad5For Rent420.0
99634House42500000DHA DefenceLahore5For Sale410.0
147606Flat6800000Bahria Town KarachiKarachi2For Sale24.2
65106House300000F-7Islamabad6For Rent622.0
\n", "

10000 rows × 8 columns

\n", "
" ], "text/plain": [ " property_type price location city baths \\\n", "108839 House 13800000 Pak Arab Housing Society Lahore 3 \n", "97355 House 17500000 Marghzar Officers Colony Lahore 6 \n", "125129 House 12500000 Adiala Road Rawalpindi 5 \n", "155467 Lower Portion 47000 Satellite Town Rawalpindi 3 \n", "81132 House 7800000 Shalimar Housing Scheme Lahore 4 \n", "... ... ... ... ... ... \n", "122491 House 19000000 Lake City Lahore 5 \n", "44101 Upper Portion 40000 Korang Town Islamabad 5 \n", "99634 House 42500000 DHA Defence Lahore 5 \n", "147606 Flat 6800000 Bahria Town Karachi Karachi 2 \n", "65106 House 300000 F-7 Islamabad 6 \n", "\n", " purpose bedrooms Area_in_Marla \n", "108839 For Sale 3 5.0 \n", "97355 For Sale 6 10.0 \n", "125129 For Sale 5 10.0 \n", "155467 For Rent 3 7.0 \n", "81132 For Sale 3 4.0 \n", "... ... ... ... \n", "122491 For Sale 4 10.0 \n", "44101 For Rent 4 20.0 \n", "99634 For Sale 4 10.0 \n", "147606 For Sale 2 4.2 \n", "65106 For Rent 6 22.0 \n", "\n", "[10000 rows x 8 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "data = pd.read_csv(\"house_prices.csv\", index_col=0)\n", "data = data.sample(10000, random_state=0)\n", "data" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas in ./.venv/lib/python3.11/site-packages (2.2.0)\n", "Requirement already satisfied: numpy<2,>=1.23.2 in ./.venv/lib/python3.11/site-packages (from pandas) (1.26.3)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in ./.venv/lib/python3.11/site-packages (from pandas) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in ./.venv/lib/python3.11/site-packages (from pandas) (2023.4)\n", "Requirement already satisfied: tzdata>=2022.7 in ./.venv/lib/python3.11/site-packages (from pandas) (2023.4)\n", "Requirement already satisfied: six>=1.5 in ./.venv/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], "source": [ "!pip install pandas" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
property_typepricelocationcitybathspurposebedroomsArea_in_Marla
108839House13800000Pak Arab Housing SocietyLahore3For Sale35.0
97355House17500000Marghzar Officers ColonyLahore6For Sale610.0
125129House12500000Adiala RoadRawalpindi5For Sale510.0
155467Lower Portion47000Satellite TownRawalpindi3For Rent37.0
81132House7800000Shalimar Housing SchemeLahore4For Sale34.0
...........................
122491House19000000Lake CityLahore5For Sale410.0
44101Upper Portion40000Korang TownIslamabad5For Rent420.0
99634House42500000DHA DefenceLahore5For Sale410.0
147606Flat6800000Bahria Town KarachiKarachi2For Sale24.2
65106House300000F-7Islamabad6For Rent622.0
\n", "

9999 rows × 8 columns

\n", "
" ], "text/plain": [ " property_type price location city baths \\\n", "108839 House 13800000 Pak Arab Housing Society Lahore 3 \n", "97355 House 17500000 Marghzar Officers Colony Lahore 6 \n", "125129 House 12500000 Adiala Road Rawalpindi 5 \n", "155467 Lower Portion 47000 Satellite Town Rawalpindi 3 \n", "81132 House 7800000 Shalimar Housing Scheme Lahore 4 \n", "... ... ... ... ... ... \n", "122491 House 19000000 Lake City Lahore 5 \n", "44101 Upper Portion 40000 Korang Town Islamabad 5 \n", "99634 House 42500000 DHA Defence Lahore 5 \n", "147606 Flat 6800000 Bahria Town Karachi Karachi 2 \n", "65106 House 300000 F-7 Islamabad 6 \n", "\n", " purpose bedrooms Area_in_Marla \n", "108839 For Sale 3 5.0 \n", "97355 For Sale 6 10.0 \n", "125129 For Sale 5 10.0 \n", "155467 For Rent 3 7.0 \n", "81132 For Sale 3 4.0 \n", "... ... ... ... \n", "122491 For Sale 4 10.0 \n", "44101 For Rent 4 20.0 \n", "99634 For Sale 4 10.0 \n", "147606 For Sale 2 4.2 \n", "65106 For Rent 6 22.0 \n", "\n", "[9999 rows x 8 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = data[data[\"Area_in_Marla\"] > 0]\n", "data" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: scikit-learn in ./.venv/lib/python3.11/site-packages (1.4.0)\n", "Requirement already satisfied: numpy<2.0,>=1.19.5 in ./.venv/lib/python3.11/site-packages (from scikit-learn) (1.26.3)\n", "Requirement already satisfied: scipy>=1.6.0 in ./.venv/lib/python3.11/site-packages (from scikit-learn) (1.12.0)\n", "Requirement already satisfied: joblib>=1.2.0 in ./.venv/lib/python3.11/site-packages (from scikit-learn) (1.3.2)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in ./.venv/lib/python3.11/site-packages (from scikit-learn) (3.2.0)\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], "source": [ "!pip install scikit-learn" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(6999, 1500, 1500)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn.model_selection import train_test_split\n", "\n", "train_data, test_data = train_test_split(data, test_size=0.3, random_state=0)\n", "valid_data, test_data = train_test_split(test_data, test_size=0.5, random_state=0)\n", "train_data.shape[0], valid_data.shape[0], test_data.shape[0]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "57800 29000000\n", "166018 6000000\n", "150291 100000\n", "133319 10500000\n", "119191 9800000\n", " ... \n", "101191 14700000\n", "48738 43500000\n", "69691 33500000\n", "160108 53000\n", "124749 30000\n", "Name: price, Length: 6999, dtype: int64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "label = \"price\"\n", "train_data[label]" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "57800 0.983117\n", "166018 0.356093\n", "150291 -1.273352\n", "133319 0.578806\n", "119191 0.551349\n", " ... \n", "101191 0.712714\n", "48738 1.144482\n", "69691 1.040525\n", "160108 -1.526018\n", "124749 -1.752503\n", "Name: price, Length: 6999, dtype: float64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn.pipeline import make_pipeline\n", "from sklearn.preprocessing import FunctionTransformer, StandardScaler\n", "\n", "import numpy as np\n", "\n", "label_pipeline = make_pipeline(\n", " FunctionTransformer(np.log2, inverse_func=np.exp2),\n", " StandardScaler(),\n", ")\n", "\n", "train_data[label] = label_pipeline.fit_transform(train_data[[label]])\n", "valid_data[label] = label_pipeline.transform(valid_data[[label]])\n", "test_data[label] = label_pipeline.transform(test_data[[label]])\n", "\n", "train_data[label]" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
citylocationArea_in_Marlabedroomsbaths
57800KarachiCantt11.433
166018LahoreGreen Cap Housing Society3.044
150291KarachiDHA Defence20.022
133319RawalpindiBahria Town Rawalpindi5.034
119191LahoreCanal Garden5.033
..................
101191RawalpindiBahria Town Rawalpindi7.055
48738LahoreDHA Defence20.056
69691KarachiGulshan-e-Iqbal Town12.033
160108KarachiCantt11.433
124749IslamabadPakistan Town10.033
\n", "

6999 rows × 5 columns

\n", "
" ], "text/plain": [ " city location Area_in_Marla bedrooms baths\n", "57800 Karachi Cantt 11.4 3 3\n", "166018 Lahore Green Cap Housing Society 3.0 4 4\n", "150291 Karachi DHA Defence 20.0 2 2\n", "133319 Rawalpindi Bahria Town Rawalpindi 5.0 3 4\n", "119191 Lahore Canal Garden 5.0 3 3\n", "... ... ... ... ... ...\n", "101191 Rawalpindi Bahria Town Rawalpindi 7.0 5 5\n", "48738 Lahore DHA Defence 20.0 5 6\n", "69691 Karachi Gulshan-e-Iqbal Town 12.0 3 3\n", "160108 Karachi Cantt 11.4 3 3\n", "124749 Islamabad Pakistan Town 10.0 3 3\n", "\n", "[6999 rows x 5 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "features = [\n", " \"city\",\n", " \"location\",\n", " \"Area_in_Marla\",\n", " \"bedrooms\",\n", " \"baths\",\n", "]\n", "\n", "train_data[features]" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.002\n" ] } ], "source": [ "from sklearn.dummy import DummyRegressor\n", "\n", "baseline = DummyRegressor(strategy=\"mean\") # DummyClassifier() for classification\n", "baseline.fit(train_data[features], train_data[label])\n", "\n", "baseline_score = baseline.score(test_data[features], test_data[label])\n", "print(f\"{baseline_score:,.3f}\")" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Karachi', 'Lahore', 'Rawalpindi', 'Islamabad', 'Faisalabad']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cities = train_data[\"city\"].unique()\n", "cities = list(cities)\n", "cities" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Pipeline(steps=[('columntransformer',\n",
       "                 ColumnTransformer(remainder='passthrough',\n",
       "                                   transformers=[('onehotencoder',\n",
       "                                                  OneHotEncoder(), ['city']),\n",
       "                                                 ('tfidfvectorizer',\n",
       "                                                  TfidfVectorizer(max_df=0.5,\n",
       "                                                                  min_df=5,\n",
       "                                                                  ngram_range=(1,\n",
       "                                                                               3)),\n",
       "                                                  'location'),\n",
       "                                                 ('standardscaler-1',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['Area_in_Marla']),\n",
       "                                                 ('standardscaler-2',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['bedrooms']),\n",
       "                                                 ('standardscaler-3',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['baths'])])),\n",
       "                ('sgdregressor', SGDRegressor(random_state=0))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "Pipeline(steps=[('columntransformer',\n", " ColumnTransformer(remainder='passthrough',\n", " transformers=[('onehotencoder',\n", " OneHotEncoder(), ['city']),\n", " ('tfidfvectorizer',\n", " TfidfVectorizer(max_df=0.5,\n", " min_df=5,\n", " ngram_range=(1,\n", " 3)),\n", " 'location'),\n", " ('standardscaler-1',\n", " StandardScaler(),\n", " ['Area_in_Marla']),\n", " ('standardscaler-2',\n", " StandardScaler(),\n", " ['bedrooms']),\n", " ('standardscaler-3',\n", " StandardScaler(),\n", " ['baths'])])),\n", " ('sgdregressor', SGDRegressor(random_state=0))])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn.compose import make_column_transformer\n", "from sklearn.preprocessing import OneHotEncoder\n", "from sklearn.feature_extraction.text import TfidfVectorizer as TfidfVec\n", "from sklearn.linear_model import SGDRegressor\n", "\n", "def create_pipeline():\n", " return make_pipeline(\n", " make_column_transformer(\n", " (OneHotEncoder(), [\"city\"]),\n", " (TfidfVec(ngram_range=(1, 3), min_df=5, max_df=0.5), \"location\"),\n", " (StandardScaler(), [\"Area_in_Marla\"]),\n", " (StandardScaler(), [\"bedrooms\"]),\n", " (StandardScaler(), [\"baths\"]),\n", " remainder=\"passthrough\",\n", " ),\n", " SGDRegressor(random_state=0),\n", " )\n", "\n", "pipeline = create_pipeline()\n", "pipeline" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.372\n" ] } ], "source": [ "pipeline.fit(train_data[features], train_data[label])\n", "\n", "train_score = pipeline.score(train_data[features], train_data[label])\n", "print(f\"{train_score:,.3f}\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "458" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pipeline.steps[-1][1].n_features_in_" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.363 {'sgdregressor__penalty': 'elasticnet', 'sgdregressor__l1_ratio': 0.01, 'sgdregressor__alpha': 1e-05}\n" ] } ], "source": [ "from sklearn.model_selection import RandomizedSearchCV\n", "\n", "params = dict(\n", " sgdregressor__penalty=[\"l1\", \"l2\", \"elasticnet\"],\n", " sgdregressor__alpha=[0.00001, 0.0001, 0.001],\n", " sgdregressor__l1_ratio=[0.01, 0.1, 1],\n", ")\n", "\n", "search = RandomizedSearchCV(create_pipeline(), params, n_iter=10, cv=5, n_jobs=2, random_state=0)\n", "search.fit(train_data[features], train_data[label])\n", "\n", "print(f\"{search.best_score_:,.3f}\", search.best_params_)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.365\n" ] } ], "source": [ "test_score = search.best_estimator_.score(test_data[features], test_data[label])\n", "print(f\"{test_score:,.3f}\")" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['cities.joblib']" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import joblib\n", "\n", "# \"Artifacts\"\n", "joblib.dump(search.best_estimator_, \"pipeline.joblib\")\n", "joblib.dump(label_pipeline, \"label_pipeline.joblib\")\n", "\n", "joblib.dump(cities, \"cities.joblib\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Pipeline(steps=[('columntransformer',\n",
       "                 ColumnTransformer(remainder='passthrough',\n",
       "                                   transformers=[('onehotencoder',\n",
       "                                                  OneHotEncoder(), ['city']),\n",
       "                                                 ('tfidfvectorizer',\n",
       "                                                  TfidfVectorizer(max_df=0.5,\n",
       "                                                                  min_df=5,\n",
       "                                                                  ngram_range=(1,\n",
       "                                                                               3)),\n",
       "                                                  'location'),\n",
       "                                                 ('standardscaler-1',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['Area_in_Marla']),\n",
       "                                                 ('standardscaler-2',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['bedrooms']),\n",
       "                                                 ('standardscaler-3',\n",
       "                                                  StandardScaler(),\n",
       "                                                  ['baths'])])),\n",
       "                ('sgdregressor',\n",
       "                 SGDRegressor(alpha=1e-05, l1_ratio=0.01, penalty='elasticnet',\n",
       "                              random_state=0))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "Pipeline(steps=[('columntransformer',\n", " ColumnTransformer(remainder='passthrough',\n", " transformers=[('onehotencoder',\n", " OneHotEncoder(), ['city']),\n", " ('tfidfvectorizer',\n", " TfidfVectorizer(max_df=0.5,\n", " min_df=5,\n", " ngram_range=(1,\n", " 3)),\n", " 'location'),\n", " ('standardscaler-1',\n", " StandardScaler(),\n", " ['Area_in_Marla']),\n", " ('standardscaler-2',\n", " StandardScaler(),\n", " ['bedrooms']),\n", " ('standardscaler-3',\n", " StandardScaler(),\n", " ['baths'])])),\n", " ('sgdregressor',\n", " SGDRegressor(alpha=1e-05, l1_ratio=0.01, penalty='elasticnet',\n", " random_state=0))])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pipeline = joblib.load(\"pipeline.joblib\")\n", "label_pipeline = joblib.load(\"label_pipeline.joblib\")\n", "cities = joblib.load(\"cities.joblib\")\n", "\n", "pipeline" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing app.py\n" ] } ], "source": [ "%%writefile app.py\n", "# !pip install gradio ipywidgets\n", "import pandas as pd\n", "import gradio as gr\n", "import joblib\n", "\n", "# \"Artifacts\"\n", "pipeline = joblib.load(\"pipeline.joblib\")\n", "label_pipeline = joblib.load(\"label_pipeline.joblib\")\n", "cities = joblib.load(\"cities.joblib\")\n", "\n", "def predict(city, location, area, bedrooms, baths):\n", " sample = dict()\n", " sample[\"city\"] = city\n", " sample[\"location\"] = location\n", " sample[\"Area_in_Marla\"] = area # Column names matching feature names\n", " sample[\"bedrooms\"] = bedrooms\n", " sample[\"baths\"] = baths\n", "\n", " price = pipeline.predict(pd.DataFrame([sample]))\n", " price = label_pipeline.inverse_transform([price])\n", " \n", " return int(price[0][0])\n", "\n", "# https://www.gradio.app/guides\n", "with gr.Blocks() as blocks:\n", " city = gr.Dropdown(cities, value=cities[0], label=\"City\")\n", " location = gr.Textbox(label=\"Location\")\n", " area = gr.Number(label=\"Area\", value=1, minimum=0.5, step=0.5)\n", " bedrooms = gr.Slider(label=\"Bedrooms\", minimum=0, maximum=10, step=1)\n", " baths = gr.Slider(label=\"Baths\", minimum=0, maximum=10, step=1)\n", "\n", " price = gr.Number(label=\"Price\")\n", "\n", " inputs = [city, location, area, bedrooms, baths]\n", " outputs = [price]\n", "\n", " predict_btn = gr.Button(\"Predict\")\n", " predict_btn.click(predict, inputs=inputs, outputs=outputs)\n", "\n", "if __name__ == \"__main__\":\n", " blocks.launch() # Local machine only\n", " # blocks.launch(server_name=\"0.0.0.0\") # LAN access to local machine\n", " # blocks.launch(share=True) # Public access to local machine" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting gradio\n", " Using cached gradio-4.16.0-py3-none-any.whl (16.7 MB)\n", "Collecting aiofiles<24.0,>=22.0 (from gradio)\n", " Using cached aiofiles-23.2.1-py3-none-any.whl (15 kB)\n", "Collecting altair<6.0,>=4.2.0 (from gradio)\n", " Using cached altair-5.2.0-py3-none-any.whl (996 kB)\n", "Collecting fastapi (from gradio)\n", " Using cached fastapi-0.109.0-py3-none-any.whl (92 kB)\n", "Collecting ffmpy (from gradio)\n", " Using cached ffmpy-0.3.1.tar.gz (5.5 kB)\n", " Installing build dependencies ... \u001b[?25ldone\n", "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n", "\u001b[?25h Preparing metadata (pyproject.toml) ... \u001b[?25ldone\n", "\u001b[?25hCollecting gradio-client==0.8.1 (from gradio)\n", " Using cached gradio_client-0.8.1-py3-none-any.whl (305 kB)\n", "Collecting httpx (from gradio)\n", " Using cached httpx-0.26.0-py3-none-any.whl (75 kB)\n", "Collecting huggingface-hub>=0.19.3 (from gradio)\n", " Using cached huggingface_hub-0.20.3-py3-none-any.whl (330 kB)\n", "Collecting importlib-resources<7.0,>=1.3 (from gradio)\n", " Using cached importlib_resources-6.1.1-py3-none-any.whl (33 kB)\n", "Collecting jinja2<4.0 (from gradio)\n", " Using cached Jinja2-3.1.3-py3-none-any.whl (133 kB)\n", "Collecting markupsafe~=2.0 (from gradio)\n", " Downloading MarkupSafe-2.1.4-cp311-cp311-macosx_10_9_universal2.whl (17 kB)\n", "Collecting matplotlib~=3.0 (from gradio)\n", " Downloading matplotlib-3.8.2-cp311-cp311-macosx_11_0_arm64.whl (7.5 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.5/7.5 MB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: numpy~=1.0 in ./.venv/lib/python3.11/site-packages (from gradio) (1.26.3)\n", "Collecting orjson~=3.0 (from gradio)\n", " Downloading orjson-3.9.12-cp311-cp311-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl (250 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m250.6/250.6 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: packaging in ./.venv/lib/python3.11/site-packages (from gradio) (23.2)\n", "Requirement already satisfied: pandas<3.0,>=1.0 in ./.venv/lib/python3.11/site-packages (from gradio) (2.2.0)\n", "Collecting pillow<11.0,>=8.0 (from gradio)\n", " Downloading pillow-10.2.0-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0mm\n", "\u001b[?25hCollecting pydantic>=2.0 (from gradio)\n", " Using cached pydantic-2.6.0-py3-none-any.whl (394 kB)\n", "Collecting pydub (from gradio)\n", " Using cached pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n", "Collecting python-multipart (from gradio)\n", " Using cached python_multipart-0.0.6-py3-none-any.whl (45 kB)\n", "Collecting pyyaml<7.0,>=5.0 (from gradio)\n", " Using cached PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl (167 kB)\n", "Collecting ruff>=0.1.7 (from gradio)\n", " Using cached ruff-0.1.15-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.4 MB)\n", "Collecting semantic-version~=2.0 (from gradio)\n", " Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n", "Collecting tomlkit==0.12.0 (from gradio)\n", " Using cached tomlkit-0.12.0-py3-none-any.whl (37 kB)\n", "Collecting typer[all]<1.0,>=0.9 (from gradio)\n", " Using cached typer-0.9.0-py3-none-any.whl (45 kB)\n", "Collecting typing-extensions~=4.0 (from gradio)\n", " Using cached typing_extensions-4.9.0-py3-none-any.whl (32 kB)\n", "Collecting uvicorn>=0.14.0 (from gradio)\n", " Using cached uvicorn-0.27.0.post1-py3-none-any.whl (60 kB)\n", "Collecting fsspec (from gradio-client==0.8.1->gradio)\n", " Using cached fsspec-2023.12.2-py3-none-any.whl (168 kB)\n", "Collecting websockets<12.0,>=10.0 (from gradio-client==0.8.1->gradio)\n", " Downloading websockets-11.0.3-cp311-cp311-macosx_11_0_arm64.whl (121 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.0/121.0 kB\u001b[0m \u001b[31m7.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting jsonschema>=3.0 (from altair<6.0,>=4.2.0->gradio)\n", " Using cached jsonschema-4.21.1-py3-none-any.whl (85 kB)\n", "Collecting toolz (from altair<6.0,>=4.2.0->gradio)\n", " Using cached toolz-0.12.1-py3-none-any.whl (56 kB)\n", "Collecting filelock (from huggingface-hub>=0.19.3->gradio)\n", " Using cached filelock-3.13.1-py3-none-any.whl (11 kB)\n", "Collecting requests (from huggingface-hub>=0.19.3->gradio)\n", " Using cached requests-2.31.0-py3-none-any.whl (62 kB)\n", "Collecting tqdm>=4.42.1 (from huggingface-hub>=0.19.3->gradio)\n", " Using cached tqdm-4.66.1-py3-none-any.whl (78 kB)\n", "Collecting contourpy>=1.0.1 (from matplotlib~=3.0->gradio)\n", " Downloading contourpy-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (243 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m243.4/243.4 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hCollecting cycler>=0.10 (from matplotlib~=3.0->gradio)\n", " Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)\n", "Collecting fonttools>=4.22.0 (from matplotlib~=3.0->gradio)\n", " Downloading fonttools-4.47.2-cp311-cp311-macosx_10_9_universal2.whl (2.8 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting kiwisolver>=1.3.1 (from matplotlib~=3.0->gradio)\n", " Downloading kiwisolver-1.4.5-cp311-cp311-macosx_11_0_arm64.whl (66 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.2/66.2 kB\u001b[0m \u001b[31m7.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting pyparsing>=2.3.1 (from matplotlib~=3.0->gradio)\n", " Using cached pyparsing-3.1.1-py3-none-any.whl (103 kB)\n", "Requirement already satisfied: python-dateutil>=2.7 in ./.venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in ./.venv/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n", "Requirement already satisfied: tzdata>=2022.7 in ./.venv/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n", "Collecting annotated-types>=0.4.0 (from pydantic>=2.0->gradio)\n", " Using cached annotated_types-0.6.0-py3-none-any.whl (12 kB)\n", "Collecting pydantic-core==2.16.1 (from pydantic>=2.0->gradio)\n", " Downloading pydantic_core-2.16.1-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting click<9.0.0,>=7.1.1 (from typer[all]<1.0,>=0.9->gradio)\n", " Using cached click-8.1.7-py3-none-any.whl (97 kB)\n", "Collecting colorama<0.5.0,>=0.4.3 (from typer[all]<1.0,>=0.9->gradio)\n", " Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)\n", "Collecting shellingham<2.0.0,>=1.3.0 (from typer[all]<1.0,>=0.9->gradio)\n", " Using cached shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n", "Collecting rich<14.0.0,>=10.11.0 (from typer[all]<1.0,>=0.9->gradio)\n", " Using cached rich-13.7.0-py3-none-any.whl (240 kB)\n", "Collecting h11>=0.8 (from uvicorn>=0.14.0->gradio)\n", " Using cached h11-0.14.0-py3-none-any.whl (58 kB)\n", "Collecting starlette<0.36.0,>=0.35.0 (from fastapi->gradio)\n", " Using cached starlette-0.35.1-py3-none-any.whl (71 kB)\n", "Collecting anyio (from httpx->gradio)\n", " Using cached anyio-4.2.0-py3-none-any.whl (85 kB)\n", "Collecting certifi (from httpx->gradio)\n", " Using cached certifi-2023.11.17-py3-none-any.whl (162 kB)\n", "Collecting httpcore==1.* (from httpx->gradio)\n", " Using cached httpcore-1.0.2-py3-none-any.whl (76 kB)\n", "Collecting idna (from httpx->gradio)\n", " Using cached idna-3.6-py3-none-any.whl (61 kB)\n", "Collecting sniffio (from httpx->gradio)\n", " Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)\n", "Collecting attrs>=22.2.0 (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio)\n", " Using cached attrs-23.2.0-py3-none-any.whl (60 kB)\n", "Collecting jsonschema-specifications>=2023.03.6 (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio)\n", " Using cached jsonschema_specifications-2023.12.1-py3-none-any.whl (18 kB)\n", "Collecting referencing>=0.28.4 (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio)\n", " Using cached referencing-0.33.0-py3-none-any.whl (26 kB)\n", "Collecting rpds-py>=0.7.1 (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio)\n", " Downloading rpds_py-0.17.1-cp311-cp311-macosx_11_0_arm64.whl (352 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m352.9/352.9 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: six>=1.5 in ./.venv/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n", "Collecting markdown-it-py>=2.2.0 (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio)\n", " Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./.venv/lib/python3.11/site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.17.2)\n", "Collecting charset-normalizer<4,>=2 (from requests->huggingface-hub>=0.19.3->gradio)\n", " Downloading charset_normalizer-3.3.2-cp311-cp311-macosx_11_0_arm64.whl (118 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m119.0/119.0 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hCollecting urllib3<3,>=1.21.1 (from requests->huggingface-hub>=0.19.3->gradio)\n", " Using cached urllib3-2.1.0-py3-none-any.whl (104 kB)\n", "Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio)\n", " Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n", "Building wheels for collected packages: ffmpy\n", " Building wheel for ffmpy (pyproject.toml) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for ffmpy: filename=ffmpy-0.3.1-py3-none-any.whl size=5579 sha256=bcec3d3aee63cf7bbbe34df541b5e2143e7a777f3b9de4e1824eed8a06d51f2f\n", " Stored in directory: /Users/sarawutinpol/Library/Caches/pip/wheels/99/3b/84/22ac1eab7a10222ac6bbc3f7e69b04f3980db328978c533a3f\n", "Successfully built ffmpy\n", "Installing collected packages: pydub, ffmpy, websockets, urllib3, typing-extensions, tqdm, toolz, tomlkit, sniffio, shellingham, semantic-version, ruff, rpds-py, pyyaml, python-multipart, pyparsing, pillow, orjson, mdurl, markupsafe, kiwisolver, importlib-resources, idna, h11, fsspec, fonttools, filelock, cycler, contourpy, colorama, click, charset-normalizer, certifi, attrs, annotated-types, aiofiles, uvicorn, typer, requests, referencing, pydantic-core, matplotlib, markdown-it-py, jinja2, httpcore, anyio, starlette, rich, pydantic, jsonschema-specifications, huggingface-hub, httpx, jsonschema, gradio-client, fastapi, altair, gradio\n", "Successfully installed aiofiles-23.2.1 altair-5.2.0 annotated-types-0.6.0 anyio-4.2.0 attrs-23.2.0 certifi-2023.11.17 charset-normalizer-3.3.2 click-8.1.7 colorama-0.4.6 contourpy-1.2.0 cycler-0.12.1 fastapi-0.109.0 ffmpy-0.3.1 filelock-3.13.1 fonttools-4.47.2 fsspec-2023.12.2 gradio-4.16.0 gradio-client-0.8.1 h11-0.14.0 httpcore-1.0.2 httpx-0.26.0 huggingface-hub-0.20.3 idna-3.6 importlib-resources-6.1.1 jinja2-3.1.3 jsonschema-4.21.1 jsonschema-specifications-2023.12.1 kiwisolver-1.4.5 markdown-it-py-3.0.0 markupsafe-2.1.4 matplotlib-3.8.2 mdurl-0.1.2 orjson-3.9.12 pillow-10.2.0 pydantic-2.6.0 pydantic-core-2.16.1 pydub-0.25.1 pyparsing-3.1.1 python-multipart-0.0.6 pyyaml-6.0.1 referencing-0.33.0 requests-2.31.0 rich-13.7.0 rpds-py-0.17.1 ruff-0.1.15 semantic-version-2.10.0 shellingham-1.5.4 sniffio-1.3.0 starlette-0.35.1 tomlkit-0.12.0 toolz-0.12.1 tqdm-4.66.1 typer-0.9.0 typing-extensions-4.9.0 urllib3-2.1.0 uvicorn-0.27.0.post1 websockets-11.0.3\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], "source": [ "!pip install gradio" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas in ./.venv/lib/python3.11/site-packages (2.2.0)\n", "Requirement already satisfied: joblib in ./.venv/lib/python3.11/site-packages (1.3.2)\n", "Requirement already satisfied: numpy<2,>=1.23.2 in ./.venv/lib/python3.11/site-packages (from pandas) (1.26.3)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in ./.venv/lib/python3.11/site-packages (from pandas) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in ./.venv/lib/python3.11/site-packages (from pandas) (2023.4)\n", "Requirement already satisfied: tzdata>=2022.7 in ./.venv/lib/python3.11/site-packages (from pandas) (2023.4)\n", "Requirement already satisfied: six>=1.5 in ./.venv/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], "source": [ "!pip install pandas joblib" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/sarawutinpol/Documents/ml_lap_2/.venv/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7861\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run app.py" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "aiofiles==23.2.1\n", "altair==5.2.0\n", "annotated-types==0.6.0\n", "anyio==4.2.0\n", "appnope==0.1.3\n", "asttokens==2.4.1\n", "attrs==23.2.0\n", "certifi==2023.11.17\n", "charset-normalizer==3.3.2\n", "click==8.1.7\n", "colorama==0.4.6\n", "comm==0.2.1\n", "contourpy==1.2.0\n", "cycler==0.12.1\n", "debugpy==1.8.0\n", "decorator==5.1.1\n", "executing==2.0.1\n", "fastapi==0.109.0\n", "ffmpy==0.3.1\n", "filelock==3.13.1\n", "fonttools==4.47.2\n", "fsspec==2023.12.2\n", "gradio==4.16.0\n", "gradio_client==0.8.1\n", "h11==0.14.0\n", "httpcore==1.0.2\n", "httpx==0.26.0\n", "huggingface-hub==0.20.3\n", "idna==3.6\n", "importlib-resources==6.1.1\n", "ipykernel==6.29.0\n", "ipython==8.20.0\n", "jedi==0.19.1\n", "Jinja2==3.1.3\n", "joblib==1.3.2\n", "jsonschema==4.21.1\n", "jsonschema-specifications==2023.12.1\n", "jupyter_client==8.6.0\n", "jupyter_core==5.7.1\n", "kiwisolver==1.4.5\n", "markdown-it-py==3.0.0\n", "MarkupSafe==2.1.4\n", "matplotlib==3.8.2\n", "matplotlib-inline==0.1.6\n", "mdurl==0.1.2\n", "nest-asyncio==1.6.0\n", "numpy==1.26.3\n", "orjson==3.9.12\n", "packaging==23.2\n", "pandas==2.2.0\n", "parso==0.8.3\n", "pexpect==4.9.0\n", "pillow==10.2.0\n", "platformdirs==4.1.0\n", "prompt-toolkit==3.0.43\n", "psutil==5.9.8\n", "ptyprocess==0.7.0\n", "pure-eval==0.2.2\n", "pydantic==2.6.0\n", "pydantic_core==2.16.1\n", "pydub==0.25.1\n", "Pygments==2.17.2\n", "pyparsing==3.1.1\n", "python-dateutil==2.8.2\n", "python-multipart==0.0.6\n", "pytz==2023.4\n", "PyYAML==6.0.1\n", "pyzmq==25.1.2\n", "referencing==0.33.0\n", "requests==2.31.0\n", "rich==13.7.0\n", "rpds-py==0.17.1\n", "ruff==0.1.15\n", "scikit-learn==1.4.0\n", "scipy==1.12.0\n", "semantic-version==2.10.0\n", "shellingham==1.5.4\n", "six==1.16.0\n", "sniffio==1.3.0\n", "stack-data==0.6.3\n", "starlette==0.35.1\n", "threadpoolctl==3.2.0\n", "tomlkit==0.12.0\n", "toolz==0.12.1\n", "tornado==6.4\n", "tqdm==4.66.1\n", "traitlets==5.14.1\n", "typer==0.9.0\n", "typing_extensions==4.9.0\n", "tzdata==2023.4\n", "urllib3==2.1.0\n", "uvicorn==0.27.0.post1\n", "wcwidth==0.2.13\n", "websockets==11.0.3\n" ] } ], "source": [ "!pip freeze" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "# Recreate virtual environment and install required modules if needed" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "!pip freeze > requirements.txt" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cloning into 'eco'...\n", "remote: Enumerating objects: 4, done.\u001b[K\n", "remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 4\u001b[K\n", "Unpacking objects: 100% (4/4), 1.27 KiB | 433.00 KiB/s, done.\n" ] } ], "source": [ "!git clone https://huggingface.co/spaces/Beerth21624/eco" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[main d177e0a] Add artifacts\n", " 7 files changed, 102025 insertions(+)\n", " create mode 100644 6_model_deployment (Updated).ipynb\n", " create mode 100644 app.py\n", " create mode 100644 cities.joblib\n", " create mode 100644 house_prices.csv\n", " create mode 100644 label_pipeline.joblib\n", " create mode 100644 pipeline.joblib\n", " create mode 100644 requirements.txt\n", "Username for 'https://huggingface.co': " ] } ], "source": [ "# !git clone xxx\n", "# OR\n", "# !git init\n", "# !git remote add origin https://huggingface.co/spaces/Beerth21624/eco\n", "# !git remote get-url origin\n", "# !git clone https://huggingface.co/spaces/Beerth21624/eco\n", "# OPTIONAL\n", "# !git lfs install\n", "# !git lfs track \"*.pipeline\"\n", "# !git add .gitattributes\n", "\n", "\n", "\n", "# !git add .\n", "# !git config user.name \"beerth21624\"\n", "# !git config user.email \"beerzii.4321@gmail.com\"\n", "# !git commit -m \"Add artifacts\"\n", "# !git push origin -f main" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "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.4" } }, "nbformat": 4, "nbformat_minor": 2 }