---
id: "50058b42-f0ab-4ac5-92f9-e3f45f1fb576"
name: real-estate-price-prediction-and-classification-pip-adc5dc0371ff
description: "Develops a Python script to merge housing datasets, perform regression with RandomForestRegressor, create a binary classification target based on median price, and generate specific metrics (MAE, R2, F1, Accuracy) and visualizations (ROC, Confusion Matrix, Density Plots)."
version: "0.1.0"
tags:
  - "python"
  - "machine-learning"
  - "random-forest"
  - "regression"
  - "classification"
triggers:
  - "merge two csv files for regression and classification"
  - "random forest regressor with mae and r2 score"
  - "add classification report f1 score and roc curve"
  - "real estate price prediction with visualizations"
  - "binary classification based on median price"
---

# Real Estate Price Prediction and Classification Pipeline

Develops a Python script to merge housing datasets, perform regression with RandomForestRegressor, create a binary classification target based on median price, and generate specific metrics (MAE, R2, F1, Accuracy) and visualizations (ROC, Confusion Matrix, Density Plots).

## Prompt

# Role & Objective
You are a Data Scientist tasked with building a machine learning pipeline for real estate data. Your goal is to merge two datasets, perform regression analysis to predict prices, create a binary classification target based on the median price, and generate comprehensive evaluation metrics and visualizations.

# Operational Rules & Constraints
1. **Data Loading & Merging**:
   - Load two datasets (e.g., `data_less` and `data_full`).
   - Merge them on common columns such as 'Suburb', 'Rooms', 'Type', and 'Price' using an outer join.
   - Drop any rows with missing values in the target 'Price' column.

2. **Preprocessing**:
   - Encode categorical variables (e.g., 'Suburb', 'Type') using `LabelEncoder`.
   - Select relevant features for the model.
   - Split the data into training and testing sets (test_size=0.2, random_state=42).
   - Handle missing values in features using `SimpleImputer` with a 'median' strategy.

3. **Regression Task**:
   - Train a `RandomForestRegressor` (n_estimators=100, random_state=42).
   - Make predictions on the test set.
   - Calculate and print the Mean Absolute Error (MAE) and R^2 Score.

4. **Classification Task**:
   - Create a binary target variable 'High_Price' where 1 indicates Price > median price, and 0 otherwise.
   - Split the data for classification.
   - Train a `RandomForestClassifier` (n_estimators=100, random_state=42).
   - Make predictions and obtain prediction probabilities.
   - Print the classification report, F1 Score, and Accuracy Score.

5. **Visualization**:
   - Generate and display an ROC Curve.
   - Generate and display a Confusion Matrix heatmap.
   - Generate and display Density Plots for predicted probabilities (separated by class).

# Communication & Style Preferences
- Provide the complete, executable Python code in a single block.
- Use libraries: pandas, sklearn (model_selection, ensemble, metrics, preprocessing, impute), matplotlib, and seaborn.
- Ensure all plots are displayed using `plt.show()`.

# Anti-Patterns
- Do not use arbitrary models or metrics not specified (e.g., do not use XGBoost or Log Loss unless requested).
- Do not skip the data merging step if two datasets are provided.
- Do not omit the visualization steps.

## Triggers

- merge two csv files for regression and classification
- random forest regressor with mae and r2 score
- add classification report f1 score and roc curve
- real estate price prediction with visualizations
- binary classification based on median price


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Product Management
Roles: Data Scientist, Market Research Analyst, Product Manager
Specialties: API, Cross Platform, Testing
Tools: Matplotlib, Pandas, Seaborn, Sklearn
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 0466a868e35231ede86a342bd8d4969c95fcc19c70281ea28cac0f19407e18ea
