Welcome to SimpleLinearRegression, a macOS app built with Swift and SwiftUI that lets you explore linear and logistic regression with real-time visualizations! As an iOS developer, this was my first dive into machine learning, and I’m excited to share it with the community. Whether you’re learning ML basics or just curious about SwiftUI, this app offers an interactive way to train models, tweak parameters, and visualize results.
- Multiple Regression Models:
- Linear regression with polynomial degrees (up to x⁶).
- Logistic regression for binary classification.
- Interactive UI:
- Select datasets and models via a clean SwiftUI interface.
- Adjust hyperparameters like learning rate, regularization (L2), and stopping threshold.
- Manually tweak weights and bias for fine-grained control.
- Real-Time Visualizations:
- Scatter plots with regression lines (
PointsAndRegressionChartViewfor linear,LogisticRegressionChartViewfor logistic). - Parameter history (
ParametersChartView) and cost over time (CostChartView).
- Scatter plots with regression lines (
- Data Handling:
- Import datasets via CSV (using
CSV.swift). - Optional normalization for X and Y values.
- Import datasets via CSV (using
- Training & Evaluation:
- Gradient descent with early stopping based on cost convergence.
- R² score to evaluate model quality (linear regression).
- Testing: Includes unit tests for core functionality (
SimpleLinearRegressionTests).
| Main View with Charts | Training in Progress | Dataset Selection |
|---|---|---|
![]() |
![]() |
![]() |
- Clone the Repository:
git clone https://github.com/DarthRumata/SimpleLinearRegression.git
- Open in Xcode:
- Open
SimpleLinearRegression.xcodeprojin Xcode (version 15.0+ recommended). - Ensure you’re on macOS 14.0 or later.
- Open
- Install Dependencies:
- The project uses
CSV.swift(v2.5.2) via Swift Package Manager. Xcode will automatically resolve this dependency when you build.
- The project uses
- Build & Run:
- Select a macOS target and hit
Cmd+Rto run the app.
- Select a macOS target and hit
-
Load a Dataset:
- The app includes sample datasets in the
sample_data/folder (e.g.,linear_sample.csvandlogistic_sample.csv). - Use the
DatasetPickerto load a CSV file, or add your own by placing a CSV file in the project directory and updating the dataset list. - CSV format: First column is the target (
y), remaining columns are features (x1,x2, ...).
- The app includes sample datasets in the
-
Select a Model:
- Choose from linear regression (simple, parabolic, cubic, x⁶) or logistic regression using the model picker.
-
Adjust Hyperparameters:
- Tweak the learning rate, regularization (lambda), and stopping threshold in the control panel.
- Toggle X/Y normalization if needed.
-
Train the Model:
- Click “Train” to start gradient descent. Watch the charts update in real-time as the model learns!
- Use “Next Step” for manual stepping, or “Reset” to start over.
-
Visualize Results:
- Check the R² score (linear models) to evaluate fit.
- Explore the charts: data points with regression line, parameter history, and cost over iterations.
This project is licensed under the MIT License. See the LICENSE file for details.
- Uses CSV.swift for CSV parsing.
- Inspired by my curiosity to combine iOS dev skills with machine learning.



