help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
housing-prices
RSK World
housing-prices
Housing Price Prediction Dataset - Real Estate ML + Price Prediction AI + Housing Price Deep Learning
housing-prices
  • __pycache__
  • .gitignore714 B
  • ADVANCED_FEATURES.md5.2 KB
  • LICENSE.txt1.5 KB
  • PROJECT_STRUCTURE.txt4.3 KB
  • README.md5.1 KB
  • advanced_models.py10.3 KB
  • data_analysis.py3.3 KB
  • data_visualization.py5.3 KB
  • dataset_info.txt3.5 KB
  • feature_engineering.py9.5 KB
  • housing_price_prediction.ipynb9.4 KB
  • housing_prices.csv4.8 KB
  • housing_prices.json23.7 KB
  • hyperparameter_tuning.py9.9 KB
  • index.html11.2 KB
  • model_comparison.py8.1 KB
  • predict_price.py4.6 KB
  • requirements.txt620 B
  • test_project.py6.8 KB
  • validate_data.py2.7 KB
housing_price_prediction.ipynb
housing_price_prediction.ipynb
Raw Download
Find: Go to:
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Housing Price Prediction Dataset\n",
        "## RSK World - Free Programming Resources & Source Code\n",
        "### Website: https://rskworld.in\n",
        "### Contact: help@rskworld.in, support@rskworld.in\n",
        "### Phone: +91 93305 39277\n",
        "### Founder: Molla Samser\n",
        "### Designer & Tester: Rima Khatun\n",
        "\n",
        "This notebook provides interactive analysis of the housing price prediction dataset.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Import required libraries\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.linear_model import LinearRegression\n",
        "from sklearn.ensemble import RandomForestRegressor\n",
        "from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error\n",
        "\n",
        "# Set display options\n",
        "pd.set_option('display.max_columns', None)\n",
        "pd.set_option('display.width', None)\n",
        "sns.set_style('whitegrid')\n",
        "plt.rcParams['figure.figsize'] = (12, 6)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 1. Load and Explore the Dataset\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Load the dataset\n",
        "df = pd.read_csv('housing_prices.csv')\n",
        "\n",
        "# Display basic information\n",
        "print(f\"Dataset Shape: {df.shape}\")\n",
        "print(f\"\\nColumns: {list(df.columns)}\")\n",
        "df.head()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Statistical summary\n",
        "df.describe()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Check for missing values\n",
        "print(\"Missing Values:\")\n",
        "print(df.isnull().sum())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 2. Data Visualization\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Price distribution\n",
        "plt.figure(figsize=(10, 6))\n",
        "plt.hist(df['price'], bins=30, edgecolor='black', alpha=0.7)\n",
        "plt.xlabel('Price ($)')\n",
        "plt.ylabel('Frequency')\n",
        "plt.title('Distribution of House Prices')\n",
        "plt.ticklabel_format(style='plain', axis='x')\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Correlation heatmap\n",
        "numeric_cols = df.select_dtypes(include=[np.number]).columns\n",
        "corr_matrix = df[numeric_cols].corr()\n",
        "\n",
        "plt.figure(figsize=(14, 10))\n",
        "sns.heatmap(corr_matrix, annot=True, fmt='.2f', cmap='coolwarm', center=0,\n",
        "            square=True, linewidths=1, cbar_kws={\"shrink\": 0.8})\n",
        "plt.title('Correlation Heatmap of Housing Features')\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Price vs Square Feet Living\n",
        "plt.figure(figsize=(10, 6))\n",
        "plt.scatter(df['sqft_living'], df['price'], alpha=0.5, edgecolors='black', linewidth=0.5)\n",
        "plt.xlabel('Square Feet Living')\n",
        "plt.ylabel('Price ($)')\n",
        "plt.title('Price vs Square Feet Living')\n",
        "plt.ticklabel_format(style='plain', axis='y')\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 3. Feature Engineering\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Select features for modeling\n",
        "feature_columns = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors',\n",
        "                   'waterfront', 'view', 'condition', 'grade', 'sqft_above',\n",
        "                   'sqft_basement', 'yr_built', 'yr_renovated', 'sqft_living15', 'sqft_lot15']\n",
        "\n",
        "X = df[feature_columns]\n",
        "y = df['price']\n",
        "\n",
        "print(f\"Features shape: {X.shape}\")\n",
        "print(f\"Target shape: {y.shape}\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 4. Model Training and Evaluation\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Split the data\n",
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
        "\n",
        "print(f\"Training set size: {X_train.shape[0]}\")\n",
        "print(f\"Test set size: {X_test.shape[0]}\")\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Train Linear Regression model\n",
        "lr_model = LinearRegression()\n",
        "lr_model.fit(X_train, y_train)\n",
        "\n",
        "# Make predictions\n",
        "y_train_pred = lr_model.predict(X_train)\n",
        "y_test_pred = lr_model.predict(X_test)\n",
        "\n",
        "# Evaluate\n",
        "print(\"Linear Regression Results:\")\n",
        "print(f\"Training R²: {r2_score(y_train, y_train_pred):.4f}\")\n",
        "print(f\"Test R²: {r2_score(y_test, y_test_pred):.4f}\")\n",
        "print(f\"Training RMSE: ${np.sqrt(mean_squared_error(y_train, y_train_pred)):,.2f}\")\n",
        "print(f\"Test RMSE: ${np.sqrt(mean_squared_error(y_test, y_test_pred)):,.2f}\")\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Train Random Forest model\n",
        "rf_model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
        "rf_model.fit(X_train, y_train)\n",
        "\n",
        "# Make predictions\n",
        "y_train_pred_rf = rf_model.predict(X_train)\n",
        "y_test_pred_rf = rf_model.predict(X_test)\n",
        "\n",
        "# Evaluate\n",
        "print(\"Random Forest Regression Results:\")\n",
        "print(f\"Training R²: {r2_score(y_train, y_train_pred_rf):.4f}\")\n",
        "print(f\"Test R²: {r2_score(y_test, y_test_pred_rf):.4f}\")\n",
        "print(f\"Training RMSE: ${np.sqrt(mean_squared_error(y_train, y_train_pred_rf)):,.2f}\")\n",
        "print(f\"Test RMSE: ${np.sqrt(mean_squared_error(y_test, y_test_pred_rf)):,.2f}\")\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Feature importance\n",
        "feature_importance = pd.DataFrame({\n",
        "    'Feature': feature_columns,\n",
        "    'Importance': rf_model.feature_importances_\n",
        "}).sort_values('Importance', ascending=False)\n",
        "\n",
        "plt.figure(figsize=(10, 6))\n",
        "plt.barh(range(len(feature_importance)), feature_importance['Importance'])\n",
        "plt.yticks(range(len(feature_importance)), feature_importance['Feature'])\n",
        "plt.xlabel('Importance')\n",
        "plt.title('Feature Importance (Random Forest)')\n",
        "plt.gca().invert_yaxis()\n",
        "plt.tight_layout()\n",
        "plt.show()\n",
        "\n",
        "print(feature_importance)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 5. Predictions Visualization\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Actual vs Predicted\n",
        "plt.figure(figsize=(12, 5))\n",
        "\n",
        "plt.subplot(1, 2, 1)\n",
        "plt.scatter(y_test, y_test_pred, alpha=0.5)\n",
        "plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'r--', lw=2)\n",
        "plt.xlabel('Actual Price')\n",
        "plt.ylabel('Predicted Price')\n",
        "plt.title('Linear Regression: Actual vs Predicted')\n",
        "plt.ticklabel_format(style='plain')\n",
        "\n",
        "plt.subplot(1, 2, 2)\n",
        "plt.scatter(y_test, y_test_pred_rf, alpha=0.5)\n",
        "plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'r--', lw=2)\n",
        "plt.xlabel('Actual Price')\n",
        "plt.ylabel('Predicted Price')\n",
        "plt.title('Random Forest: Actual vs Predicted')\n",
        "plt.ticklabel_format(style='plain')\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    }
  ],
  "metadata": {
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}
301 lines•9.4 KB
json

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer