Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 2.15 KB

readme.md

File metadata and controls

85 lines (57 loc) · 2.15 KB

Certainly! Here's a more detailed and structured README.md file:

# House Price Prediction Using Neural Network

This repository contains code to train and evaluate a neural network for predicting house prices using the California housing dataset. The model is implemented using PyTorch, and the data preprocessing is done with scikit-learn.

## Requirements

- Python 3.x
- PyTorch
- scikit-learn

You can install the required libraries using pip:

```bash
pip install torch scikit-learn

Code Overview

The main functionality is provided by the compute function, which trains and evaluates a neural network for regression prediction.

compute Function

def compute(epoch):
    """Trains and evaluates a neural network for regression prediction.

    Inputs:
        epoch (int): The number of training epochs.

    Outputs:
        result (dict): A dictionary containing the predicted house prices and the average loss.

    Requirements:
        PyTorch, scikit-learn
    """
    # Function implementation here...

test Function

The test function demonstrates how to use the compute function:

def test():
    """Test the compute function."""
    print("Running test")
    result = compute(epoch=100)
    print("Predictions:", result["predictions"])
    print("Average Loss:", result["avg_loss"])

test()

Data Loading and Preprocessing

The California housing dataset is loaded using scikit-learn's fetch_california_housing. The data is split into training and testing sets, and features are standardized using StandardScaler.

Neural Network Definition

A simple feedforward neural network is defined with one hidden layer.

Training

The model is trained using the Mean Squared Error (MSE) loss function and the Adam optimizer. Training progress is printed every 10 epochs.

Evaluation

The model is evaluated on the test set. Predictions and the average loss are returned.

Example Output

Running test
Epoch [10/100], Loss: 0.5241
Epoch [20/100], Loss: 0.4312
...
Epoch [100/100], Loss: 0.2289
Average loss on test data: 0.3012
Predictions: [2.511, 3.412, 1.911, ...]
Average Loss: 0.3012