Skip to content

[Goal] LinearRegression: Near-Identical Python→C# Translation #580

@Nucs

Description

@Nucs

The README screenshot showcases a LinearRegression implementation - Python on the left, C# on the right.

This is what NumSharp was built for: enabling near-identical code translation from Python to C#.

Python vs C# LinearRegression

What This Demonstrates

The screenshot proves NumSharp's core promise: you can take NumPy code and translate it to C# with minimal changes:

Python/NumPy C#/NumSharp
np.hstack(...) np.hstack(...)
np.mean(X, 0) np.mean(X, 0)
np.std(X, 0) np.std(X, 0)
np.expand_dims(y, -1) np.expand_dims(y, -1)
np.zeros(...) np.zeros(...)
X @ self.params np.matmul(X, @params)
(y - y_pred)**2 np.power(y - y_pred, 2)

The entire LinearRegression class - constructor, fit(), score(), and predict() methods - translates almost 1-to-1.

Achievement Unlocked 🏆

This example should be preserved, tested, and maintained as a canonical demonstration of NumSharp's capabilities.

Tasks

  • Add LinearRegression example to test suite to ensure it never breaks
  • Verify all APIs used still work correctly with NumPy 2.x behavior
  • Consider adding to documentation as a "getting started" example

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions