Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException:Field coalProduction doesn't exist #781

Closed
byTianHai opened this issue Jul 28, 2024 · 1 comment
Closed

IllegalArgumentException:Field coalProduction doesn't exist #781

byTianHai opened this issue Jul 28, 2024 · 1 comment

Comments

@byTianHai
Copy link

Describe the bug

Exception in thread "main" java.lang.IllegalArgumentException: Field coalProduction doesn't exist   
at smile.data.type.StructType.indexOf(StructType.java:103)  
at smile.data.formula.Variable$1.<init>(Variable.java:80)  
at smile.data.formula.Variable.bind(Variable.java:78)  
at smile.data.formula.Formula.lambda$bind$12(Formula.java:348)    
at smile.data.formula.Formula.bind(Formula.java:349)   
at smile.regression.OLS.fit(OLS.java:121)  
at smile.regression.OLS.fit(OLS.java:106)  
at smile.regression.OLS.fit(OLS.java:85)  
at com.smile.LinerR.main(LinerR.java:31) 

Expected behavior

I am planning to perform a multi-objective regression analysis task. Based on smile, I plan to bind target variables and feature variables one by one to conduct linear regression analysis and achieve multi-objective regression. I'm having a few problems at the moment, my feature variable is coalProduction and my target variable is every variable in targetColumns, here's my source code

Actual behavior

OLS.fit(formula, dataSplits)throws an exception:IllegalArgumentException: Field coalProduction doesn't exist.
After testing, my object file reads in normally, containing the feature variable coalProduction. So I don't understand this error.

Code snippet

DataFrame df= Read.csv("coalta.csv");
String[] targetColumns = {"drainage","industrialUsage","domesticUsage","waterTreatment","waterStorage","discharge"};
StringBuilder result = new StringBuilder();
for (String targetColumn : targetColumns) {
Formula formula = Formula.of(targetColumn,"coalProduction");
LinearModel ols = OLS.fit(formula, df);
result.append("Model for ").append(targetColumn).append(":\n")
.append("Coefficients: ").append(Arrays.toString(ols.coefficients())).append("\n")
.append("Intercept: ").append(ols.intercept()).append("\n\n");
}
System.out.println(result.toString());

Input data
coalProduction,drainage,industrialUsage,domesticUsage,waterTreatment,waterStorage,discharge
1000,200,150,80,60,70,90
1010,202,152,82,62,72,92
1020,205,155,85,64,74,94
1030,208,158,88,66,76,96
1040,210,160,90,68,78,98
1050,213,162,92,70,80,100
1060,215,165,94,72,82,102
1070,218,168,96,74,84,104
1080,220,170,98,76,86,106

Additional context

  • java 1.8 version
  • Smile version 3.1.1
  • build system (Windows)
@haifengl
Copy link
Owner

Set header=true for the format parameter of Read.csv. Or Read.data(path, “header=true”)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants