src/train.cpp
void read_dataset(char *filename, cv::Mat &data, cv::Mat &classes, int total_samples)
{

	int label;
	float pixelvalue;
	//open the file
	FILE* inputfile = fopen(filename, "r");

	//read each row of the csv file
	for (int row = 0; row < total_samples; row++)
	{
		//for each attribute in the row
		for (int col = 0; col <= ATTRIBUTES; col++)
		{
			//if its the pixel value.
			if (col < ATTRIBUTES){

				fscanf(inputfile, "%f,", &pixelvalue);
				data.at<float>(row, col) = pixelvalue;

			}//if its the label
			else if (col == ATTRIBUTES){
				//make the value of label column in that row as 1.
				fscanf(inputfile, "%i", &label);
				classes.at<float>(row, label) = 1.0;

			}
		}
	}

	fclose(inputfile);

}
/********************************************************************************
This function will read the csv files(training and test dataset) and convert them
into two matrices. classes matrix have 10 columns, one column for each class label. If the label of nth row in data matrix
is, lets say 5 then the value of classes[n][5] = 1.
********************************************************************************/
This function will read the csv files(training and test dataset) and convert them
into two matrices. classes matrix have 10 columns, one column for each class label. If the label of nth row in data matrix
is, lets say 5 then the value of classes[n][5] = 1.
This function will read the csv files ( training and test dataset ) and convert them into two matrices . classes matrix have 10 columns one column for each class label . If the label of nth row in data matrix is lets say 5 then the value of classes [ n ] [ 5 ] = 1 .
void read_dataset(char *filename, cv::Mat &data, cv::Mat &classes, int total_samples)
{
	int label;
	float pixelvalue;
	FILE* inputfile = fopen(filename, "r");
	for (int row = 0; row < total_samples; row++)
	{
		for (int col = 0; col <= ATTRIBUTES; col++)
		{
			if (col < ATTRIBUTES){
				fscanf(inputfile, "%f,", &pixelvalue);
				data.at<float>(row, col) = pixelvalue;
			}
			else if (col == ATTRIBUTES){
				fscanf(inputfile, "%i", &label);
				classes.at<float>(row, label) = 1.0;
			}
		}
	}
	fclose(inputfile);
}
void read_dataset ( char * filename , cv :: Mat & data , cv :: Mat & classes , int total_samples ) { int label ; float pixelvalue ; FILE * inputfile = fopen ( filename , " " ) ; for ( int row = 0 ; row < total_samples ; row ++ ) { for ( int col = 0 ; col <= ATTRIBUTES ; col ++ ) { if ( col < ATTRIBUTES ) { fscanf ( inputfile , " " , & pixelvalue ) ; data . at < float > ( row , col ) = pixelvalue ; } else if ( col == ATTRIBUTES ) { fscanf ( inputfile , " " , & label ) ; classes . at < float > ( row , label ) = 1.0 ; } } } fclose ( inputfile ) ; }
This function will read the csv files(training and test dataset) and convert them
into two matrices.
This function will read the csv files ( training and test dataset ) and convert them into two matrices .
//open the file
 //read each row of the csv file
 //for each attribute in the row
 //if its the pixel value.
 //if its the label
 //make the value of label column in that row as 1.
