aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 4d6833d5d9b2308cc12db58a67580b6042be3bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# ft_linear_regression

A simple linear regression implementation using gradient descent to predict car prices based on mileage.

## Requirements

- Python 3
- matplotlib (for visualization only)

```
pip install matplotlib
```

## Usage

### Train the model

```
python3 train.py <learning_rate> <iterations>
```

Example:
```
python3 train.py 1.0 1000
```

This trains the model on `data.csv` and saves the resulting parameters (θ0, θ1) to `thetas.csv`.

### Predict a price

```
python3 predict.py
```

Prompts for a mileage value and outputs the estimated price. Loops until Ctrl+C.
If no trained model is found, θ0 and θ1 default to 0.

### Visualize

```
python3 visualize.py
```

Displays a scatter plot of the dataset. If a trained model exists, the regression line is drawn on top.

## How it works

The model fits a linear function:

```
estimatePrice(mileage) = θ0 + θ1 * mileage
```

Parameters are found via gradient descent with min-max normalization on the input data. After training, thetas are denormalized so they work directly on raw mileage values.