मैं MathNet.Iridium रिहाई का इस्तेमाल किया है क्योंकि यह .NET 3.5 और VS2008 साथ संगत है। विधि Vandermonde मैट्रिक्स पर आधारित है। [1,0.57,-0.15]
की
using MathNet.Numerics.LinearAlgebra;
class Program
{
static void Main(string[] args)
{
Vector x_data = new Vector(new double[] { 0, 1, 2, 3, 4 });
Vector y_data = new Vector(new double[] { 1.0, 1.4, 1.6, 1.3, 0.9 });
var poly = new PolynomialRegression(x_data, y_data, 2);
Console.WriteLine("{0,6}{1,9}", "x", "y");
for (int i = 0; i < 10; i++)
{
double x = (i * 0.5);
double y = poly.Fit(x);
Console.WriteLine("{0,6:F2}{1,9:F4}", x, y);
}
}
}
परिकलित गुणांक उत्पादन के साथ:
x y
0.00 1.0000
0.50 1.2475
1.00 1.4200
1.50 1.5175
2.00 1.5400
2.50 1.4875
3.00 1.3600
3.50 1.1575
4.00 0.8800
4.50 0.5275
कौन से मेल खाता है तब मैं अपने बहुपद प्रतिगमन धारण करने के लिए
using MathNet.Numerics.LinearAlgebra;
public class PolynomialRegression
{
Vector x_data, y_data, coef;
int order;
public PolynomialRegression(Vector x_data, Vector y_data, int order)
{
if (x_data.Length != y_data.Length)
{
throw new IndexOutOfRangeException();
}
this.x_data = x_data;
this.y_data = y_data;
this.order = order;
int N = x_data.Length;
Matrix A = new Matrix(N, order + 1);
for (int i = 0; i < N; i++)
{
A.SetRowVector(VandermondeRow(x_data[i]) , i);
}
// Least Squares of |y=A(x)*c|
// tr(A)*y = tr(A)*A*c
// inv(tr(A)*A)*tr(A)*y = c
Matrix At = Matrix.Transpose(A);
Matrix y2 = new Matrix(y_data, N);
coef = (At * A).Solve(At * y2).GetColumnVector(0);
}
Vector VandermondeRow(double x)
{
double[] row = new double[order + 1];
for (int i = 0; i <= order; i++)
{
row[i] = Math.Pow(x, i);
}
return new Vector(row);
}
public double Fit(double x)
{
return Vector.ScalarProduct(VandermondeRow(x) , coef);
}
public int Order { get { return order; } }
public Vector Coefficients { get { return coef; } }
public Vector XData { get { return x_data; } }
public Vector YData { get { return y_data; } }
}
जो तब मैं इसे इस तरह का प्रयोग कर एक श्रेणी का निर्माण वोल्फ्राम अल्फा से quadratic परिणाम।

संपादित करें 1 फिट आप x_data
और y_data
निम्नलिखित आरंभ की कोशिश करना चाहते हैं पाने के लिए:
Matrix points = new Matrix(new double[,] { { 1, 82.96 },
{ 2, 86.23 }, { 3, 87.09 }, { 4, 84.28 },
{ 5, 83.69 }, { 6, 89.18 }, { 7, 85.71 },
{ 8, 85.05 }, { 9, 85.58 }, { 10, 86.95 },
{ 11, 87.95 }, { 12, 89.44 }, { 13, 93.47 } });
Vector x_data = points.GetColumnVector(0);
Vector y_data = points.GetColumnVector(1);
जो निम्नलिखित गुणांक (सबसे कम बिजली से उच्चतम करने के लिए) का उत्पादन
Coef=[85.892,-0.5542,0.074990]
x y
0.00 85.8920
1.00 85.4127
2.00 85.0835
3.00 84.9043
4.00 84.8750
5.00 84.9957
6.00 85.2664
7.00 85.6871
8.00 86.2577
9.00 86.9783
10.00 87.8490
11.00 88.8695
12.00 90.0401
13.00 91.3607
14.00 92.8312
यह वही परिणाम है जो मैं देख रहा हूं: http://www3.wolframalpha.com/input/?i=quadratic+fit+%7B1%2C82.96%7D%2C%7B2%2C86.23%7D % 2C% 7B3% 2C87.09% 7 दिन% 2C% 7B4% 2C84.28% 7 दिन% 2C% 7B5% 2C83.69% 7 दिन% 2C% 7B6% 2C89.18% 7 दिन% 2C% 7B7% 2C85.71% 7 दिन % 2C% 7B8% 2C85.05% 7 दिन% 2C% 7B9% 2C85.58% 7 दिन% 2C% 7B10% 2C86.95% 7 दिन% 2C% 7B11% 2C87.95% 7 दिन% 2C% 7B12% 2C89.44% 7 दिन % 2 सी% 7 बी 13% 2C93.47% 7 डी – Polynomial
लिंक के साथ एक और क्यू: http://stackoverflow.com/questions/882009/is-there-any-tool-for-regression-model एक प्रासंगिक दिखने वाला कोडप्रोजेक्ट चीज़: http: //www.codeproject.com/KB/recipes/QuadraticRegression.aspx – AakashM
पूर्व इंटरपोलेशन मॉडल के लिंक का एक सेट है, और बाद में असामान्य रूप से गलत/निर्विवाद परिणाम देता है, इसे 'डबल' के बजाय 'दशमलव' का उपयोग करने के बाद भी परिवर्तित किया जाता है '। – Polynomial