当前位置: 首页>>代码示例>>C++>>正文


C++ CsvReader::csvReadToMatrix方法代码示例

本文整理汇总了C++中CsvReader::csvReadToMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ CsvReader::csvReadToMatrix方法的具体用法?C++ CsvReader::csvReadToMatrix怎么用?C++ CsvReader::csvReadToMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader::csvReadToMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: evaluateTestData

void evaluateTestData(const Network& net) {
	CsvReader reader;
	CsvWriter writer;
	cout << "Leyendo test data" << endl;
	MatrixXd testData = reader.csvReadToMatrix(TEST_DATA_FILE);
	if (testData.rows() == 0 && testData.cols() == 0) {
		printf("Error leyendo test data.\n");
		return;
	}
	cout << "cantidad de features: " << (testData.cols() - 1) << endl << endl;
	cout << "Evaluando test data" << endl;
	MatrixXd results = net.evaluate(testData);
	writer.makeSubmitWithMatrix(SUBMIT_FILE, results);
}
开发者ID:gsnaider,项目名称:san-francisco-crime-classification,代码行数:14,代码来源:NeuralNetwork.cpp

示例2: generateInputData

inputData_t generateInputData() {
	CsvReader reader;

	MatrixXd matrix = reader.csvReadToMatrix(TRAIN_DATA_FILE);

	if (matrix.rows() == 0 && matrix.cols() == 0) {
		printf("Error leyendo data.\n");
		exit(-1);
	} else {
		cout << "cantidad de features: " << (matrix.cols() - 1) << endl << endl;
	}

	//shuflear toda la matrix
	PermutationMatrix<Dynamic, Dynamic> permutacionFilasRandom(matrix.rows());
	permutacionFilasRandom.setIdentity();

	srand(time(0));
	random_shuffle(permutacionFilasRandom.indices().data(),
			permutacionFilasRandom.indices().data()
					+ permutacionFilasRandom.indices().size());

	matrix = permutacionFilasRandom * (matrix);

//	Recuce el tamanio de la matriz para poder testear.
//	TODO Para correr con todos los datos cambiar DATA_SIZE = 1.
	int nuevo_ultimo_indice = round(matrix.rows() * DATA_SIZE);
	matrix.conservativeResize(nuevo_ultimo_indice, matrix.cols());

	int ultimo_indice_train = round(matrix.rows() * 0.8);
	int ultimo_indice_test = round(matrix.rows() * 0.9);

	MatrixXd matrix_train = matrix.block(0, 0, ultimo_indice_train, matrix.cols());

	MatrixXd matrix_test = matrix.block(ultimo_indice_train, 0,
			ultimo_indice_test - ultimo_indice_train, matrix_train.cols());

	MatrixXd matrix_validation = matrix.block(ultimo_indice_test, 0,
			matrix.rows() - ultimo_indice_test, matrix_train.cols());

	matrix.resize(0, 0);

	inputData_t data;

	//separar matrix_train en x_train, y_train
	//separar matrix_test en x_test, y_test
	data.x_train = matrix_train.block(0, 0, matrix_train.rows(),
			matrix_train.cols() - 1);
	data.y_train = (matrix_train.block(0, matrix_train.cols() - 1,
			matrix_train.rows(), 1)); //me dice que puse different types
	data.x_test = matrix_test.block(0, 0, matrix_test.rows(),
			matrix_test.cols() - 1);
	data.y_test = matrix_test.block(0, matrix_test.cols() - 1, matrix_test.rows(),
			1);
	data.x_validation = matrix_validation.block(0, 0, matrix_validation.rows(),
			matrix_validation.cols() - 1);
	data.y_validation = matrix_validation.block(0, matrix_validation.cols() - 1,
			matrix_validation.rows(), 1);

	matrix_train.resize(0, 0);
	matrix_test.resize(0, 0);

	cout << "Train x: " << data.x_train.rows() << "x" << data.x_train.cols() << "\n";
	cout << "Train y: " << data.y_train.rows() << "x" << data.y_train.cols() << "\n";
	cout << "Test x: " << data.x_test.rows() << "x" << data.x_test.cols() << "\n";
	cout << "Test y: " << data.y_test.rows() << "x" << data.y_test.cols() << "\n";
	cout << "Validation x: " << data.x_validation.rows() << "x"
			<< data.x_validation.cols() << "\n";
	cout << "Validation y: " << data.y_validation.rows() << "x"
			<< data.y_validation.cols() << "\n";

	return data;

}
开发者ID:gsnaider,项目名称:san-francisco-crime-classification,代码行数:73,代码来源:NeuralNetwork.cpp


注:本文中的CsvReader::csvReadToMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。