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).
- Load data from a CSV file
- Fit a linear regression model
- Calculate MAE, MSE, and R²
- Make predictions based on the model
-
go get github.com/BlueGob/Linear-regression-Go
-
Create a Go file (
main.go
) with the following content: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()) }
-
Run the program:
go run main.go
The dataset used for this project can be found on Kaggle