From 4a4ee41e0d3563d613020126ff6ce63979584bc6 Mon Sep 17 00:00:00 2001 From: abhisingh977 Date: Sun, 19 Apr 2020 19:47:15 -0500 Subject: [PATCH] final --- .../GBR.py => Gradientboost/Gradientboost.py} | 2 +- .../models/Gradientboost/Icon\r" | 0 src/models/regression/regression.py | 2 +- src/models_helper.ipynb | 90 ++++++++++++++++++- 4 files changed, 88 insertions(+), 6 deletions(-) rename src/models/{GBR/GBR.py => Gradientboost/Gradientboost.py} (98%) rename "src/models/GBR/Icon\r" => "src/models/Gradientboost/Icon\r" (100%) diff --git a/src/models/GBR/GBR.py b/src/models/Gradientboost/Gradientboost.py similarity index 98% rename from src/models/GBR/GBR.py rename to src/models/Gradientboost/Gradientboost.py index 8ca6d29..80be8d4 100644 --- a/src/models/GBR/GBR.py +++ b/src/models/Gradientboost/Gradientboost.py @@ -40,7 +40,7 @@ def convert_to_categorical(df, categorical_variables, categories, need_pickup = x = df[['pickup_community_area' ,'temperature', 'relative_humidity', 'wind_direction', 'wind_speed', 'precipitation_cat', 'sky_level', 'daytype', 'Day Name', 'Month', 'Hour', 'Fare Last Month', 'Trips Last Hour', - 'Trips Last Week (Same Hour)', 'Trips 2 Weeks Ago (Same Hour)', 'Quarter', 'Year', 'trip_start_timestamp']] + 'Trips Last Week (Same Hour)', 'Trips 2 Weeks Ago (Same Hour)', 'Year', 'trip_start_timestamp']] categorical_variables = ['pickup_community_area', 'daytype', 'sky_level', 'Day Name', 'Month','Hour', 'Year'] categories = [[*(range(1,78))], ['U', 'W', 'A'], ['OVC', 'BKN', 'SCT', 'FEW', 'CLR', 'VV '], diff --git "a/src/models/GBR/Icon\r" "b/src/models/Gradientboost/Icon\r" similarity index 100% rename from "src/models/GBR/Icon\r" rename to "src/models/Gradientboost/Icon\r" diff --git a/src/models/regression/regression.py b/src/models/regression/regression.py index 8ca6d29..80be8d4 100644 --- a/src/models/regression/regression.py +++ b/src/models/regression/regression.py @@ -40,7 +40,7 @@ def convert_to_categorical(df, categorical_variables, categories, need_pickup = x = df[['pickup_community_area' ,'temperature', 'relative_humidity', 'wind_direction', 'wind_speed', 'precipitation_cat', 'sky_level', 'daytype', 'Day Name', 'Month', 'Hour', 'Fare Last Month', 'Trips Last Hour', - 'Trips Last Week (Same Hour)', 'Trips 2 Weeks Ago (Same Hour)', 'Quarter', 'Year', 'trip_start_timestamp']] + 'Trips Last Week (Same Hour)', 'Trips 2 Weeks Ago (Same Hour)', 'Year', 'trip_start_timestamp']] categorical_variables = ['pickup_community_area', 'daytype', 'sky_level', 'Day Name', 'Month','Hour', 'Year'] categories = [[*(range(1,78))], ['U', 'W', 'A'], ['OVC', 'BKN', 'SCT', 'FEW', 'CLR', 'VV '], diff --git a/src/models_helper.ipynb b/src/models_helper.ipynb index 869d262..151ec9d 100755 --- a/src/models_helper.ipynb +++ b/src/models_helper.ipynb @@ -207,9 +207,7 @@ "execution_count": 4, "metadata": {}, "outputs": [], - "source": [ - "df = df.drop(columns=['Unnamed: 0'],axis=1)" - ] + "source": [] }, { "cell_type": "code", @@ -301,7 +299,91 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# Gradientboost\n", + "model_Gradientboost = joblib.load(path_datasets+\"/model/GBR.pickle\")\n", + "\n", + "path_to_model = pathToSrc + f'{sep}models{sep}/Gradientboost/Gradientboost.py'\n", + "spec = importlib.util.spec_from_file_location(\"Gradientboost\", path_to_model)\n", + "Gradientboost = importlib.util.module_from_spec(spec)\n", + "spec.loader.exec_module(Gradientboost)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "date = \"2019-11-16 16:00:00\"\n", + "#getDate from request.form.values:\n", + "#row = df[df['trip_start_timestamp'] == date].iloc[0,]\n", + "\n", + "# Transform to array X\n", + "X = Gradientboost.TransformDataToX(df, date)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Predict\n", + "Y = model_Gradientboost.predict(X)\n", + "#prediction = np.random.randint(1,200,77)\n", + "# Create map\n", + "\n", + "prediction = Gradientboost.TransformYToResult(Y)\n", + "\n", + "# Create map\n", + "mp.mapGenerator(prediction)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Liner_Regression\n", + "model_regression = joblib.load(path_datasets+\"/model/reg.pickle\")\n", + "\n", + "path_to_model = pathToSrc + f'{sep}models{sep}/regression/regression.py'\n", + "spec = importlib.util.spec_from_file_location(\"regression\", path_to_model)\n", + "regression = importlib.util.module_from_spec(spec)\n", + "spec.loader.exec_module(regression)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "date = \"2019-11-16 16:00:00\"\n", + "\n", + "# Transform to array X\n", + "X = regression.TransformDataToX(df, date)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Predict\n", + "Y = model_regression.predict(X)\n", + "#prediction = np.random.randint(1,200,77)\n", + "# Create map\n", + "\n", + "prediction = regression.TransformYToResult(Y)\n", + "\n", + "# Create map\n", + "mp.mapGenerator(prediction)" + ] } ], "metadata": {