{"uid":"cap_GHwfxaPSs4PEkCDhbIi1f","slug":"linear-algebra-least-squares-polynomial-fit-6b68bff3","name":"Linear Algebra Least-Squares Polynomial Fit","description":"Least-squares line or polynomial fit (degree 1 to 6, up to 100 points) with coefficients, R-squared and residuals.","url":"https://linear-algebra.x402tookit.com/least-squares?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["x","y"],"properties":{"x":{"type":"string","description":"x values, JSON like [1,2,3,4] or 1,2,3,4 (up to 100)"},"y":{"type":"string","description":"y values, same count as x"},"at":{"type":"number","description":"Optional x at which to evaluate the fitted curve"},"degree":{"type":"integer","description":"Polynomial degree 1 to 6 (default 1 = straight line); needs at least degree+1 points"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"rmse":{"type":["null","number"]},"slope":{"type":["null","number"]},"degree":{"type":["null","number"]},"fitted":{"type":["array","null"],"items":{"type":"number"}},"points":{"type":["null","number"]},"source":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"rSquared":{"type":["null","number"]},"intercept":{"type":["null","number"]},"residuals":{"type":["array","null"],"items":{"type":"number"}},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"coefficients":{"type":["array","null"],"items":{"type":"number"}},"conditioning":{"type":["null","object"],"properties":{"note":{"type":["null","string"]},"centre":{"type":["null","number"]},"halfRange":{"type":["null","number"]}}},"coefficientOrder":{"type":["null","string"]},"sumSquaredResiduals":{"type":["null","number"]},"residualStandardError":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_tOQyXHCrIAmb5y0hjucfa","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Fits a least-squares line or polynomial (degree 1–6) to up to 100 data points, returning coefficients, R-squared, residuals, and optional curve evaluation.","exampleAgentPrompt":"Fit a degree-2 polynomial to my data points x=[1,2,3,4,5] and y=[2.1,8.9,20.2,35.0,54.8], and evaluate the curve at x=6 — give me the coefficients, R-squared, and residuals.","exampleUseCases":[{"title":"Trendline for sales growth","prompt":"I have monthly sales figures for the past 8 months: x=[1,2,3,4,5,6,7,8] and y=[120,145,160,188,210,240,275,310]. Can you fit a straight line (degree 1) and tell me the slope, intercept, and R-squared so I can see the growth rate?"},{"title":"Quadratic fit for physics experiment","prompt":"I dropped a ball and recorded position vs time: x=[0,0.1,0.2,0.3,0.4,0.5] and y=[0,0.05,0.19,0.44,0.78,1.22]. Fit a degree-2 polynomial to these points and give me the coefficients and R-squared — I want to verify it follows a quadratic trajectory."},{"title":"Predict future value from historical data","prompt":"Here's historical temperature anomaly data: x=[1980,1990,2000,2010,2020] and y=[0.26,0.44,0.42,0.72,0.98]. Fit a degree-1 regression and evaluate it at x=2030 so I can see the projected value, and also give me R-squared."}],"resultDescription":"Returns a JSON object with the fitted polynomial coefficients (ordered from constant to highest degree), R-squared goodness-of-fit, slope and intercept (for degree-1), residuals array, RMSE, residual standard error, sum of squared residuals, fitted values at each input point, optional evaluated value at a requested x, number of points used, conditioning metadata (centering/scaling info), and any warnings or degraded-quality flags.","failureModes":["Fewer data points than degree+1 causes underdetermined system error","Mismatched x and y array lengths returns validation error","Degree outside 1–6 range rejected","More than 100 points exceeds limit","Ill-conditioned data (e.g. duplicate x values) may return degraded flag or NaN coefficients","Malformed JSON in x or y query params returns parse error"],"whenToPreferThis":"Choose this endpoint when you need least-squares regression with polynomial degrees 1 through 6 on moderate-sized datasets (up to 100 points), and want a single-call solution that returns not just coefficients but also R-squared, residuals, RMSE, and an optional point evaluation. Prefer it over general-purpose compute endpoints when the output format (coefficients, fit statistics, conditioning notes) matches your downstream needs directly.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T13:14:25.406Z","isFirstParty":false,"canonicalSlug":"linear-algebra-least-squares-polynomial-fit-6b68bff3"}