neural network - How Do I Normalize CSV Input Data in Encog? -
i have made neural network using jeff heaton's encog library. using classify (iris plants).
the problem have follows:
i have dataset csv file contains ideal output , use training. wish use separate csv file doesn't contain output field recognition. problem have when use new csv without output field following error when trying normalize file:
the error:
"can't determine target field automatically, please specify one.
this can happen if specified wrong file format."
this method:
public void normalizefile(fileinfo sourcedatafile, fileinfo normalizeddatafile) { var wizard = new analystwizard(_analyst); // line errors wizard.wizard(sourcedatafile, _useheaders, analystfileformat.decpntcomma); var norm = new analystnormalizecsv(); norm.analyze(sourcedatafile, _useheaders, csvformat.english, _analyst); norm.produceoutputheaders = _useheaders; norm.normalize(normalizeddatafile); } when doing training involves normalizing training data. save normalization data. reload normalization data when recognizing.
if keep output column in data, i'm recognizing, works! cases of new data when classification unknown?
for example when use following format file recognized:
sepal_l, sepal_w, petal_l, petal_w, name
then adds column predicted output this:
sepal_l, sepal_w, petal_l, petal_w, name, prediction,
however want able enter files without name column.
many thanks, kiran
you can accomplish task in multiple ways. however, typical flow :
take data --> normalize using normalization information stored in encog analyst ---> create input array of normalized inputs --> pass trained network , compute output (or predict class in classification problem)
i have updated iris demo (evaluation phase) scenario (which covered in pluralsight course:
here portion of code :
// evaluating new data set no class information var extraevaluationset = encogutility.loadcsv2memory(config.extraevaluationfile.tostring(), network.inputcount, 0, true, csvformat.english, false); int extrafilecount = 0; using (var file = new system.io.streamwriter(config.extraevaluationfileoutput.tostring())) { file.writeline("sepal_l,sepal_w,petal_l,petal_w,predicted"); foreach (var item in extraevaluationset) { //normalize input double normalized_sepal_l = analyst.script.normalize.normalizedfields[0].normalize(item.input[0]); double normalized_sepal_w = analyst.script.normalize.normalizedfields[1].normalize(item.input[1]); double normalized_petal_l = analyst.script.normalize.normalizedfields[2].normalize(item.input[2]); double normalized_petal_w = analyst.script.normalize.normalizedfields[3].normalize(item.input[3]); double[] inputtonetwork = { normalized_sepal_l, normalized_sepal_w, normalized_petal_l, normalized_petal_w }; count++; //output var output = network.compute(new basicmldata(inputtonetwork)); int classcount = analyst.script.normalize.normalizedfields[4].classes.count; double normalizationhigh = analyst.script.normalize.normalizedfields[4].normalizedhigh; double normalizationlow = analyst.script.normalize.normalizedfields[4].normalizedlow; var eq = new encog.mathutil.equilateral(classcount, normalizationhigh, normalizationlow); var predictedclassint = eq.decode(output); var predictedclass = analyst.script.normalize.normalizedfields[4].classes[predictedclassint].name; var resultline = string.format("{0},{1},{2},{3},{4}", item.input[0], item.input[1], item.input[2], item.input[3],predictedclass); file.writeline(resultline); console.writeline("count :{0} properties [{1},{2},{3},{4}] ,predicted : {5} ", extrafilecount, item.input[0], item.input[1], item.input[2], item.input[3], predictedclass); } } the demo code available on following link : http://bit.ly/1grg0u7 (please edit data folder path before executing)
Comments
Post a Comment