|
969 | 969 | "plt.show()\n" |
970 | 970 | ] |
971 | 971 | }, |
| 972 | + { |
| 973 | + "cell_type": "code", |
| 974 | + "execution_count": null, |
| 975 | + "id": "1e258546", |
| 976 | + "metadata": {}, |
| 977 | + "outputs": [], |
| 978 | + "source": [] |
| 979 | + }, |
972 | 980 | { |
973 | 981 | "cell_type": "markdown", |
974 | | - "id": "b042449d", |
| 982 | + "id": "355e2e68", |
975 | 983 | "metadata": {}, |
976 | 984 | "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" |
1007 | 986 | ] |
1008 | 987 | }, |
1009 | 988 | { |
1010 | 989 | "cell_type": "code", |
1011 | | - "execution_count": 25, |
1012 | | - "id": "ae4cd4fd", |
| 990 | + "execution_count": 29, |
| 991 | + "id": "59e0c6ab", |
1013 | 992 | "metadata": {}, |
1014 | 993 | "outputs": [ |
1015 | 994 | { |
|
1018 | 997 | "text": [ |
1019 | 998 | "=== MAKING PREDICTIONS ===\n", |
1020 | 999 | "\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" |
1033 | 1004 | ] |
1034 | 1005 | } |
1035 | 1006 | ], |
|
1106 | 1077 | { |
1107 | 1078 | "cell_type": "code", |
1108 | 1079 | "execution_count": null, |
1109 | | - "id": "1e258546", |
| 1080 | + "id": "e46cbf49", |
1110 | 1081 | "metadata": {}, |
1111 | 1082 | "outputs": [], |
1112 | 1083 | "source": [] |
|
0 commit comments