Skip to content

Conversation

ngtduc693
Copy link
Contributor

@ngtduc693 ngtduc693 commented Oct 4, 2025

Summary

This PR introduces a simple linear regression implementation to the repository. Linear regression is a fundamental supervised learning algorithm used to model the relationship between a scalar dependent variable and an independent variable.

Changes

  • Implements univariate linear regression with detailed
  • Provides methods to fit the model and predict new values.
  • Includes comprehensive NUnit unit tests in to ensure correctness and edge case coverage.

Usage Example

var x = new List<double> { 1, 2, 3, 4 };
var y = new List<double> { 3, 5, 7, 9 };
var lr = new LinearRegression();
lr.Fit(x, y);
var prediction = lr.Predict(5); // returns 11.0

Unit Test Evidence

image
  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Comments in areas I changed are up to date
  • I have added comments to hard-to-understand areas of my code
  • I have made corresponding changes to the README.md

@ngtduc693 ngtduc693 marked this pull request as ready for review October 4, 2025 16:24
@ngtduc693 ngtduc693 requested a review from siriak as a code owner October 4, 2025 16:24
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.64%. Comparing base (d3652b1) to head (38e7a68).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #538      +/-   ##
==========================================
+ Coverage   96.62%   96.64%   +0.01%     
==========================================
  Files         274      275       +1     
  Lines       10824    10865      +41     
  Branches     1534     1541       +7     
==========================================
+ Hits        10459    10500      +41     
  Misses        232      232              
  Partials      133      133              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ngtduc693 ngtduc693 force-pushed the feature/add-linear-regression branch from 96a4748 to 2cc77f1 Compare October 4, 2025 16:36
@siriak siriak requested a review from Copilot October 4, 2025 22:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a simple linear regression implementation for univariate analysis, providing a fundamental supervised learning algorithm to model relationships between scalar dependent and independent variables.

Key changes:

  • Implements a complete LinearRegression class with fit and predict functionality
  • Adds comprehensive unit tests covering edge cases and validation scenarios
  • Updates documentation to include the new machine learning algorithm

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
README.md Added entry for the new Linear Regression algorithm in the Machine Learning section
Algorithms/MachineLearning/LinearRegression.cs Complete implementation of univariate linear regression with validation and prediction methods
Algorithms.Tests/MachineLearning/LinearRegressionTests.cs Comprehensive unit tests covering normal operation and edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) October 4, 2025 22:08
@siriak siriak merged commit e2c20ed into TheAlgorithms:master Oct 4, 2025
4 checks passed
ngtduc693 added a commit to ngtduc693/C-Sharp-Algorithms that referenced this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants