dotnet / machinelearning-samples

Samples for ML.NET, an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
4.49k stars 2.69k forks source link

Example Request: Simple polynomial fitting and get the coefficients #639

Closed hoangdungt2 closed 5 years ago

hoangdungt2 commented 5 years ago

hi, I'm looking for a simple example to polynomial fit data (uni-variate or multi-variate) and I want to print out the parameters to implement the prediction in embedded system. Thanks.

CESARDELATORRE commented 5 years ago

Do you mean an example of a Polynomial regression?

Also, what kind of embedded system are you targeting? Note that ML.NET doesn't support ARM-based devices.

This is ML.NET support on processors and Operating Systems and .NET frameworks: https://github.com/dotnet/machinelearning#operating-systems-and-processor-architectures-supported-by-mlnet

Can you elaborate a bit further on your specific scenario/problem for a polynomial regression?

hoangdungt2 commented 5 years ago

hi CESARDELATORRE, Thanks for your reply. For my problem, I want to fit z from x and y such that

z = a1 x^2 + a2 x y + a3 y^2 + a4 x + a5 y + a6

I have collected bunch of data of z, x, y. I want to use ML.NET to figure the a1,a2,a3,a4,a5,a6 parameters. From these parameters, in my embedded system when receiving x,y I can do prediction of z using C (programming language) and the above equation. Thanks

CESARDELATORRE commented 5 years ago

Hi @hoangdungt2 - Afaik, we currently don't have a direct algorithm/transform for this.

We have a RFF transform, which makes projections into a potentially useful space, but won't match theses features. If you are interested on 'Random Fourier Features Transform​ (command-line xf=RFF)' I can provide further info. But I think it is a different space.

However, you could probably create the feature interactions (x, x^2, x*y, y^2, y) in a custom ML.NET transform that you can create. Then you can fit a linear model to those features.

Here's info on how to create a custom transform in ML.NET:

Sample code: https://github.com/endintiers/Unearth.Demo.MLCustomTransform

Video: https://www.youtube.com/watch?v=TEnQp5qtopo

Btw, if you create such a custom transform it'd be great to have it as a sample for the community so we could point to it from the community samples page here: https://github.com/dotnet/machinelearning-samples/blob/master/docs/COMMUNITY-SAMPLES.md

Hope it helps,

hoangdungt2 commented 5 years ago

Thanks Cesar, I have created a function for getting polynomial features (link). I think I'll learn more about ML.Net custom transform, thanks for the info. Currently watching your talk at the dotNet Conf. Thanks

CESARDELATORRE commented 5 years ago

Nice! - Btw, as mentioned, if you create a custom Transform Estimator and publish it as a sample in your GitHub repo, ping me so I point to it from our community samples, ok? - I'd be a great example! đź‘Ť

https://github.com/dotnet/machinelearning-samples/blob/master/docs/COMMUNITY-SAMPLES.md