public void WriteFile(List <List <string> > numericDataset, string file, List <string> atrNames, List <string> targetValues, bool isTargetNumeric)
        {
            weka.core.FastVector targetVals = new weka.core.FastVector();

            weka.core.Instances dataRel;

            for (int i = 0; i < targetValues.Count; i++)
            {
                targetVals.addElement(targetValues[i]);
            }

            weka.core.Instances  data;
            weka.core.FastVector atts = new weka.core.FastVector();

            // fill and prepare the dataset for the arrf file
            for (int j = 0; j < insts.numAttributes(); j++)
            {
                if (j == insts.numAttributes() - 1 && isTargetNumeric == false) // target value can be nominal
                {
                    atts.addElement(new weka.core.Attribute(atrNames[j], targetVals));
                }
                else
                {
                    atts.addElement(new weka.core.Attribute(atrNames[j]));
                }
            }

            data = new weka.core.Instances("MyRelation", atts, 0);

            for (int i = 0; i < insts.numInstances(); i++)
            {
                double[] vals = new double[insts.numAttributes()];

                for (int j = 0; j < insts.numAttributes(); j++)
                {
                    if (j == insts.numAttributes() - 1 && isTargetNumeric == false) // target value can be nominal
                    {
                        vals[j] = targetVals.indexOf(numericDataset[j][i]);
                    }
                    else
                    {
                        vals[j] = Convert.ToDouble(numericDataset[j][i]);
                    }
                }

                data.add(new weka.core.DenseInstance(1.0, vals));
            }

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var saver = new weka.core.converters.ArffSaver();

            saver.setInstances(data);
            saver.setFile(new java.io.File(file));
            // files are saved into {AppFolder}/bin/Debug folder. You can find two files in this path.
            saver.writeBatch();
        }