.. _tabular-building-classification: ======================= Building Classification ======================= This page covers building **Tabular Classification** models for categorizing data into discrete classes. .. contents:: On this page :local: :depth: 2 When to Use Classification ========================== Use the Classification template when: - Your outputs are **discrete categories or labels** (not continuous values) - You want to assign inputs to one of several classes - Examples: disease diagnosis, quality grades, object categories .. important:: Classification outputs must be **one-hot encoded**. Each row contains exactly one ``1`` (the class) and ``0`` elsewhere. Building a Classification Model =============================== .. tabs:: .. tab:: GUI **1. Create a new project** Launch NeurEco GUI and select **Tabular Classification**. **2. Configure settings** In the **Settings** tab: - **Training data:** Select your input file and one-hot encoded output file - **Validation percentage:** Adjust if needed (default: 33.33%) - **Normalization:** Configure input normalization (output normalization is handled automatically for classification) - **GPU:** Enable if available for faster training **3. Start the build** Click the **BUILD** button. NeurEco will: - Display training progress in the **Training** panel - Show classification accuracy metrics - Save checkpoints periodically **4. Monitor progress** Watch the training metrics including classification accuracy. The build automatically stops when optimal accuracy is reached. .. tab:: Python API **1. Import and prepare data** .. code-block:: python from NeurEco import NeurEcoTabular as Tabular import numpy as np # Load data x_train = np.genfromtxt("x_train.csv", delimiter=";", skip_header=True) y_train = np.genfromtxt("y_train.csv", delimiter=";", skip_header=True) # y_train must be one-hot encoded! # Shape: (n_samples, n_classes) **2. Create the model** .. code-block:: python model = Tabular.Classifier() **3. Configure and build** .. code-block:: python config = Tabular.ClassifierBuildConfig( # Required: Data input_data=x_train, output_data=y_train, # Must be one-hot encoded # Required: Output paths write_model_to="./model/classification.ednn", checkpoint_address="./model/classification.checkpoint", # Optional: Validation valid_percentage=33.33, # Optional: Normalization (inputs only - outputs handled automatically) inputs_shifting="min_centered", inputs_scaling="max_centered", inputs_normalize_per_feature=True, # Optional: GPU use_gpu=False, gpu_id=0, ) model.build(config) .. tab:: CLI **1. Create a configuration file** Create ``build_classification.conf``: .. code-block:: json { "neurecoClassification_build": { "DevSettings": { "disconnect_inputs_if_possible": true, "final_learning": true, "initial_beta_reg": 0.1, "valid_percentage": 33.33 }, "UserSettings": { "gpu_id": 0, "use_gpu": false }, "checkpoint_address": "./model/classification.checkpoint", "exc_filenames": ["x_train.csv"], "output_filenames": ["y_train_onehot.csv"], "input_normalization": { "normalize_per_feature": true, "scale_type": "max_centered", "shift_type": "min_centered" }, "write_model_to": "./model/classification.ednn" } } **2. Run the build** .. code-block:: shell neureco Classification build build_classification.conf One-Hot Encoding ================ Classification requires one-hot encoded outputs. Here's how to convert integer labels: **Example: Converting integer labels to one-hot** .. code-block:: python import numpy as np # Original labels: 0, 1, 2 (3 classes) labels = np.array([0, 1, 2, 0, 1, 2, 0, 1]) # Convert to one-hot n_samples = len(labels) n_classes = len(np.unique(labels)) one_hot = np.zeros((n_samples, n_classes)) one_hot[np.arange(n_samples), labels] = 1 # Result: # [[1, 0, 0], # [0, 1, 0], # [0, 0, 1], # [1, 0, 0], # ...] **CSV format for one-hot encoded data:** .. code-block:: text class_A;class_B;class_C 1;0;0 0;1;0 0;0;1 1;0;0 Classification-Specific Considerations ====================================== Output Normalization -------------------- For classification, output normalization is typically not needed since the outputs are binary (0 or 1). NeurEco handles this automatically. Interpreting Predictions ------------------------ The model outputs probability-like values for each class. To get the predicted class: .. code-block:: python predictions = model.evaluate(x_test) predicted_classes = np.argmax(predictions, axis=1) Accuracy Metrics ---------------- For classification, relevant metrics include: - **Classification accuracy:** Percentage of correctly classified samples - **Confusion matrix:** Shows which classes are confused with each other - **Per-class accuracy:** Accuracy for each individual class Complete Parameter Reference ============================ .. list-table:: :header-rows: 1 :widths: 30 15 55 * - Parameter - Default - Description * - ``input_data`` - Required - Training inputs (array or file path) * - ``output_data`` - Required - Training outputs - **must be one-hot encoded** * - ``write_model_to`` - Required - Output path for model (.ednn) * - ``checkpoint_address`` - None - Path for checkpoints * - ``valid_percentage`` - 33.33 - Validation split percentage * - ``validation_input_data`` - None - Separate validation inputs * - ``validation_output_data`` - None - Separate validation outputs (one-hot) * - ``inputs_shifting`` - "auto" - Input shift method * - ``inputs_scaling`` - "auto" - Input scale method * - ``inputs_normalize_per_feature`` - True - Per-feature input normalization * - ``initial_beta_reg`` - 0.1 - Initial regularization coefficient (see :ref:`regularization-coefficient`) * - ``final_learning`` - True - Final pruning, a last pass that disconnects unused inputs (if ``disconnect_inputs_if_possible`` is True) and a training pass that includes validation; ``False`` skips all three (see :ref:`final-learning`) * - ``disconnect_inputs_if_possible`` - True - Allow pruning of the links from the inputs at every structure change and, when ``final_learning`` is True, a last pass that disconnects unused inputs; ``False`` never prunes a link from an input * - ``links_maximum_number`` - 0 - Max network connections (0=unlimited) * - ``use_gpu`` - False - Enable GPU acceleration * - ``gpu_id`` - 0 - GPU device ID Example: Cancer Classification ============================== Here's a complete example classifying cancer types from RNA expression data: .. tabs:: .. tab:: Python API .. code-block:: python from NeurEco import NeurEcoTabular as Tabular import numpy as np # Load the Cancer RNA dataset — the training set ships in two parts x_train = np.vstack([ np.genfromtxt("x_train_0_.csv", delimiter=";", skip_header=True), np.genfromtxt("x_train_1_.csv", delimiter=";", skip_header=True), ]) y_train = np.vstack([ np.genfromtxt("y_train_0_.csv", delimiter=";", skip_header=True), np.genfromtxt("y_train_1_.csv", delimiter=";", skip_header=True), ]) # y_train is already one-hot encoded x_test = np.genfromtxt("x_test.csv", delimiter=";", skip_header=True) y_test = np.genfromtxt("y_test.csv", delimiter=";", skip_header=True) # Create and build the model model = Tabular.Classifier() config = Tabular.ClassifierBuildConfig( input_data=x_train, output_data=y_train, write_model_to="./cancer_model/cancer.ednn", checkpoint_address="./cancer_model/cancer.checkpoint", valid_percentage=33.33, ) model.build(config) # Evaluate on test data predictions = model.evaluate(x_test) # Get predicted classes predicted_classes = np.argmax(predictions, axis=1) actual_classes = np.argmax(y_test, axis=1) # Calculate accuracy accuracy = np.mean(predicted_classes == actual_classes) print(f"Test accuracy: {accuracy * 100:.2f}%") # Clean up model.delete() Next Steps ========== - :ref:`Evaluate your model ` - :ref:`Export for deployment ` - See :ref:`advanced features ` for sensitivity analysis