adisharma Posted October 20, 2021 Share Posted October 20, 2021 (edited) Hello Everyone, Im working with Quantrix. A java based software. The scripting language is Groovy and i want to build a customized function, a simple linear regression. Im not a java developer so I truly just know the fundamentals. My code takes a gander right now like this. I think the issue is some place in the syntax, which im not that familiar working with. double simple_regression(double dependend_values, double independend_values, double x_test) { slope = double slope(dependend_values, independend_values) intercept = double intercept(dependend_values, independend_values) return intercept + slope * x_test } Here is another try, done in a java online compiler public class simple_regression { static void main (String [] args) { int x=10; int y=25; int x_test=20; double predict; SimpleRegression sreg = SimpleRegression(); sreg.addData(); sreg.addData(x, y); predict = sreg.predict(x_test); System.out.println(predict); } } and this is the error i get /simple_regression.java:7: error: cannot find symbol SimpleRegression sreg = SimpleRegression(); ^ symbol: class SimpleRegression location: class simple_regression /simple_regression.java:7: error: cannot find symbol SimpleRegression sreg = SimpleRegression(); ^ symbol: method SimpleRegression() location: class simple_regression 2 errors Edited June 15, 2022 by Phi for All No advertising, please. Link to comment Share on other sites More sharing options...
Ghideon Posted October 20, 2021 Share Posted October 20, 2021 (edited) 1 hour ago, adisharma said: error: cannot find symbol SimpleRegression sreg = SimpleRegression(); The error indicates that the code is missing an import statement for the class (or package) that defines SimpleRegression. For more information about Java import ser for instance : https://www.w3schools.com/java/ref_keyword_import.asp Edited October 20, 2021 by Ghideon Reference 1 Link to comment Share on other sites More sharing options...
Sensei Posted October 20, 2021 Share Posted October 20, 2021 (edited) 3 hours ago, adisharma said: I think the issue is some place in the syntax, which im not that familiar working with. Apart from what @Ghideon said: You have missing semicolons in several places. Groovy online interpreter accepts it, but it will learn you bad habits. 'slope' and 'intercept' are nowhere declared and then used as either variable and as method/function name and also nowhere declared.. My fixed version which passes through online Groovy interpreter: https://www.tutorialspoint.com/execute_groovy_online.php Looks like: /* Hello World in Groovy */ double slope( double a, double b ) { return( a ); } double intercept( double a, double b ) { return( a ); } double simple_regression(double dependend_values, double independend_values, double x_test) { double slope = slope(dependend_values, independend_values); double intercept = intercept(dependend_values, independend_values); return intercept + slope * x_test; } But you will need to fill slope() and intercept() with proper functionality. 3 hours ago, adisharma said: sreg.addData(); SimpleRegression java class from: https://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/stat/regression/SimpleRegression.html doesn't have addData() without parameters.. Edited October 20, 2021 by Sensei 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now