Skip to content

Commit 6b064f4

Browse files
Making Predictions on New Data
1 parent a7b2d59 commit 6b064f4

1 file changed

Lines changed: 17 additions & 46 deletions

File tree

4_data_analysis/MLProject.ipynb

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -969,47 +969,26 @@
969969
"plt.show()\n"
970970
]
971971
},
972+
{
973+
"cell_type": "code",
974+
"execution_count": null,
975+
"id": "1e258546",
976+
"metadata": {},
977+
"outputs": [],
978+
"source": []
979+
},
972980
{
973981
"cell_type": "markdown",
974-
"id": "b042449d",
982+
"id": "355e2e68",
975983
"metadata": {},
976984
"source": [
977-
"# Step 8.1: Analyze feature importance\n",
978-
"print(\"=== FEATURE IMPORTANCE ANALYSIS ===\")\n",
979-
"\n",
980-
"# Create a DataFrame with feature names and coefficients\n",
981-
"feature_importance = pd.DataFrame({\n",
982-
" 'Feature': X.columns,\n",
983-
" 'Coefficient': model.coef_\n",
984-
"})\n",
985-
"\n",
986-
"# Sort by absolute value of coefficients\n",
987-
"feature_importance['Abs_Coefficient'] = np.abs(feature_importance['Coefficient'])\n",
988-
"feature_importance = feature_importance.sort_values('Abs_Coefficient', ascending=False)\n",
989-
"\n",
990-
"print(\"\\nFeature Importance (sorted by absolute coefficient value):\")\n",
991-
"print(feature_importance[['Feature', 'Coefficient']])\n",
992-
"\n",
993-
"# Visualize feature importance\n",
994-
"plt.figure(figsize=(10, 6))\n",
995-
"bars = plt.barh(feature_importance['Feature'], feature_importance['Abs_Coefficient'])\n",
996-
"plt.xlabel('Absolute Coefficient Value')\n",
997-
"plt.title('Feature Importance in Linear Regression Model')\n",
998-
"plt.gca().invert_yaxis() # Highest importance at top\n",
999-
"plt.grid(True, alpha=0.3, axis='x')\n",
1000-
"\n",
1001-
"# Add coefficient values on bars\n",
1002-
"for bar, coeff in zip(bars, feature_importance['Coefficient']):\n",
1003-
" plt.text(bar.get_width() * 1.01, bar.get_y() + bar.get_height()/2,\n",
1004-
" f'{coeff:.2f}', va='center')\n",
1005-
"\n",
1006-
"plt.show()"
985+
"9. Making Predictions on New Data\n"
1007986
]
1008987
},
1009988
{
1010989
"cell_type": "code",
1011-
"execution_count": 25,
1012-
"id": "ae4cd4fd",
990+
"execution_count": 29,
991+
"id": "59e0c6ab",
1013992
"metadata": {},
1014993
"outputs": [
1015994
{
@@ -1018,18 +997,10 @@
1018997
"text": [
1019998
"=== MAKING PREDICTIONS ===\n",
1020999
"\n",
1021-
"=== EXAMPLE PREDICTIONS ===\n"
1022-
]
1023-
},
1024-
{
1025-
"ename": "ValueError",
1026-
"evalue": "Unknown format code 'f' for object of type 'str'",
1027-
"output_type": "error",
1028-
"traceback": [
1029-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1030-
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
1031-
"Cell \u001b[0;32mIn[25], line 57\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;66;03m# Example 1\u001b[39;00m\n\u001b[1;32m 56\u001b[0m pred1 \u001b[38;5;241m=\u001b[39m predict_tourist_numbers(\u001b[38;5;241m2025\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBahamas\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtourists\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 57\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPredicted tourists for Bahamas in 2025: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpred1\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m.0f\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m thousand trips\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 59\u001b[0m \u001b[38;5;66;03m# Example 2\u001b[39;00m\n\u001b[1;32m 60\u001b[0m pred2 \u001b[38;5;241m=\u001b[39m predict_tourist_numbers(\u001b[38;5;241m2023\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDominican Republic\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvisitors_total\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
1032-
"\u001b[0;31mValueError\u001b[0m: Unknown format code 'f' for object of type 'str'"
1000+
"=== EXAMPLE PREDICTIONS ===\n",
1001+
"Predicted tourists for Bahamas in 2025: 1503 thousand trips\n",
1002+
"Predicted total visitors for Dominican Republic in 2023: 1730 thousand trips\n",
1003+
"Predicted excursionists for Jamaica in 2026: 1129 thousand trips\n"
10331004
]
10341005
}
10351006
],
@@ -1106,7 +1077,7 @@
11061077
{
11071078
"cell_type": "code",
11081079
"execution_count": null,
1109-
"id": "1e258546",
1080+
"id": "e46cbf49",
11101081
"metadata": {},
11111082
"outputs": [],
11121083
"source": []

0 commit comments

Comments
 (0)