Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:59:04+00:00 2026-06-17T19:59:04+00:00

I was trying to use commons math to figure out the constants in a

  • 0

I was trying to use commons math to figure out the constants in a polynomial. It looks like the routine exists but I got this error. Does anyone see the issue?

I was trying to convert this question to commons-math:
https://math.stackexchange.com/questions/121212/how-to-find-curve-equation-from-data

From plotting you data (Wolfram|Alpha link), it does not look linear. So it better be fit by a polynomial. I assume you want to fit the data:

X Y
1 4
2 8
3 13
4 18
5 24
..
using a quadratic polynomial y=ax2+bx+c.

And wolfram alpha provided a great utility. I wish I could get the same answers like from wolfram.

http://www.wolframalpha.com/input/?i=fit+4%2C+8%2C+13%2C

E.g. By entering that data, I would get : 4.5 x-0.666667 (linear)

Here is the code and error:

import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;
import org.apache.commons.math3.stat.regression.SimpleRegression;
final OLSMultipleLinearRegression regression2 = new OLSMultipleLinearRegression();
double[] y = {
        4.0, 
        8, 
        13,                 
};      
double[][] x2 = 
    {
        { 1.0, 1, 1  },
        { 1.0, 2, 4  },
        { 0.0, 3, 9  },             
    };
regression2.newSampleData(y, x2);
regression2.setNoIntercept(true);
regression2.newSampleData(y, x2);       
double[] beta = regression2.estimateRegressionParameters();
for (double d : beta) {
    System.out.println("D: " + d);
}

Exception in thread “main” org.apache.commons.math3.exception.MathIllegalArgumentException: not enough data (3 rows) for this many predictors (3 predictors)
at org.apache.commons.math3.stat.regression.AbstractMultipleLinearRegression.validateSampleData(AbstractMultipleLinearRegression.java:236)
at org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression.newSampleData(OLSMultipleLinearRegression.java:70)
at org.berlin.bot.algo.BruteForceSort.main(BruteForceSort.java:108)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:59:05+00:00Added an answer on June 17, 2026 at 7:59 pm

    Rcook was right. I provided an additional row (test case) and that generated the same answer as from wolfram/alpha.

    D: 0.24999999999999822
    D: 3.4500000000000033
    D: 0.24999999999999914

    Or 0.25x^2 + 3.45x + 0.25

    final OLSMultipleLinearRegression regression2 = new OLSMultipleLinearRegression();
            double[] y = {
                    4, 
                    8, 
                    13,         
                    18
            };              
            double[][] x2 = 
                {
                    { 1, 1, 1  },
                    { 1, 2, 4  },
                    { 1, 3, 9  },                                                               
                    { 1, 4, 16  },
                };
    
            regression2.newSampleData(y, x2);
            regression2.setNoIntercept(true);
            regression2.newSampleData(y, x2);       
            double[] beta = regression2.estimateRegressionParameters();
            for (double d : beta) {
                System.out.println("D: " + d);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how to use Apache Commons IO DirectoryWalker .
I am trying to use Apache Commons Math's SpearmansCorrelation but I am having some
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.
Ok so I'm trying to use Apache Commons Math library to compute a double
Hi Im trying to use a standard deviation library from Apache Commons Math. I'm
I've been trying to figure out how I could use the Maybe monad in
Hi basic question in trying to use commons-math's PolynomialSolver classes. According to the documentation
I am trying to use the SimplexSolver class in the Apache Commons Math package,
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
I'm trying to use VFS S3 a plugin for the Apache Commons VFS for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.