https://github.com/bluegob/linear-regression-go
simple linear regression with Go from a csv file
https://github.com/bluegob/linear-regression-go
go linear-regression
Last synced: about 1 year ago
JSON representation
simple linear regression with Go from a csv file
- Host: GitHub
- URL: https://github.com/bluegob/linear-regression-go
- Owner: BlueGob
- Created: 2024-09-07T19:45:56.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-08T13:05:22.000Z (almost 2 years ago)
- Last Synced: 2025-03-02T17:16:17.961Z (over 1 year ago)
- Topics: go, linear-regression
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Linear Regression with Go
This project provides an implementation of linear regression with two variables in Go.
It includes various evaluation metrics such as R² (R-squared), Mean Squared Error (MSE),and Mean Absolute Error (MAE).
## Features
- Load data from a CSV file
- Fit a linear regression model
- Calculate MAE, MSE, and R²
- Make predictions based on the model
## Getting Started
### Usage
1. ```bash
go get github.com/BlueGob/Linear-regression-Go
```
2. Create a Go file (`main.go`) with the following content:
```go
package main
import (
"fmt"
"github.com/BlueGob/Linear-regression-Go/regression"
)
func main() {
lr := regression.NewLinearRegression("employee_salary.csv", "Salary", 0.2)
lr.Fit()
fmt.Println("Prediction for input 2:", lr.Predict(2))
fmt.Println("Mean Absolute Error (MAE):", lr.Mae())
fmt.Println("Mean Squared Error (MSE):", lr.Mse())
fmt.Println("R-squared (R²):", lr.R2())
}
```
2. Run the program:
```bash
go run main.go
```
### Dataset
The dataset used for this project can be found on [Kaggle](https://www.kaggle.com/datasets/hassanmustafa01/employee-salary-dataset)