TrainVectorClassifier with No geometries data?

I have a csv file that record 5000 sample’s photo mean and SD.

(It’s calculate by other program)

But TrainVectorClassifier require geometries.

How to train no geometries data?

Hello,

OGR, the GDAL library used by OTB to manage vector data, actually supports CSV. TrainVectorClassifier requires a Vector data file as input. But it doesn’t matter if there is no geometry information in the features contained in the layers because the application does not use the geographical information for the training. This means you should be able to use your CSV file for the training.

An example with some very simple data :

test.csv:

feat1,feat2,feat3,feat4,class
1,2,3,4,1
1,2,3,4,1
1,2,3,4,1
4,3,2,1,2
4,3,2,1,2
4,3,2,1,2
4,3,2,1,2

A classifier can be trained using the following command:

otbcli_TrainVectorClassifier -io.vd "test.csv?&gdal:oo:AUTODETECT_TYPE=ON"  -io.out model.txt -cfield class -feat feat1 feat2 feat3 feat4

Here an extended filename is applied to test.csv to pass the option (AUTODETECT_TYPE=ON) to OGR. Without this option all fields are read as string, and cannot be used for the classification.You might need other options to open the file, see the OGR documentation for more infos.

I hope that helps,
Cédric

3 Likes

Thanks @cedric.traizet , You save my day! :smiley:
Key point is exactly AUTODETECT_TYPE=ON
Transform CSV to ODS is also work!