I want to get the weighted linear regression coefficients of the pair xy represented by two arrays in java. I reset to weka, but it requests an object of the "Instances" class in the "LinearRegression" class. To create an Instances class file, you need an ARFF file that contains data. I came across solutions that use the FastVector class, but now it is deprecated in the latest version of weka. How to create an ARFF file for a pair of xy and corresponding weights, all represented by arrays in java?
Here is my Base based code. This gives an exception in the last line of “lr.buildClassifier (newDataset)” - Thread [main] (Suspended (UnassignedClassException exception))
Capabilities.testWithFail (instances): 1302. Here the code is
public static void test() throws Exception
{
double[][] data = {{4058.0, 4059.0, 4060.0, 214.0, 1710.0, 2452.0, 2473.0, 2474.0, 2475.0, 2476.0, 2477.0, 2478.0, 2688.0, 2905.0, 2906.0, 2907.0, 2908.0, 2909.0, 2950.0, 2969.0, 2970.0, 3202.0, 3342.0, 3900.0, 4007.0, 4052.0, 4058.0, 4059.0, 4060.0}, {19.0, 20.0, 21.0, 31.0, 103.0, 136.0, 141.0, 142.0, 143.0, 144.0, 145.0, 146.0, 212.0, 243.0, 244.0, 245.0, 246.0, 247.0, 261.0, 270.0, 271.0, 294.0, 302.0, 340.0, 343.0, 354.0, 356.0, 357.0, 358.0}};
int numInstances = data[0].length;
ArrayList<Attribute> atts = new ArrayList<Attribute>();
List<Instance> instances = new ArrayList<Instance>();
for(int dim = 0; dim < 2; dim++)
{
Attribute current = new Attribute("Attribute" + dim, dim);
if(dim == 0)
{
for(int obj = 0; obj < numInstances; obj++)
{
instances.add(new SparseInstance(numInstances));
}
}
for(int obj = 0; obj < numInstances; obj++)
{
instances.get(obj).setValue(current, data[dim][obj]);
}
atts.add(current);
}
Instances newDataset = new Instances("Dataset", atts, instances.size());
for(Instance inst : instances)
newDataset.add(inst);
LinearRegression lr = new LinearRegression();
lr.buildClassifier(newDataset);
}