Data Mining Final Assignment
Data Mining Final Assignment
DATA MINING
Submitted to: Sir Khurshid
3-1-2025
Qno1: Predict house prices using regression in Python (scikit-
learn).
Here's a step-by-step example of predicting house prices using regression in Python
with the scikit-learn library.
Steps:
print("Model Evaluation:")
print(f"Mean Absolute Error (MAE): {mae}")
print(f"Mean Squared Error (MSE): {mse}")
print(f"Root Mean Squared Error (RMSE): {rmse}")
print(f"R^2 Score: {r2}")
# Example prediction
example_house = np.array([[2000, 4, 8]]) # 2000 sq ft, 4 bedrooms, 8 years old
predicted_price = model.predict(example_house)
print(f"Predicted price for the house: ${predicted_price[0]:,.2f}")
Explanation:
1. Dataset: The dataset is a small example; in practice, you would use a more
extensive dataset.
2. Features and Target: The features (X) include size, bedrooms, and age, and the
target variable (y) is the price.
3. Splitting Data: The data is divided into training and testing sets using an 80-20
split.
4. Model: A Linear Regression model is used for simplicity.
5. Evaluation: Common metrics (MAE, MSE, RMSE, R²) assess the model's
performance.
6. Prediction: The model predicts house prices based on new data.