D DevBrainBox

Model Training & Testing

AI is technology that enables computers and machines to simulate human learning.

How to Train an AI Model

Training is the process of teaching the model to recognize patterns in data.

Steps:

  1. Collect Data
  • Example: House prices dataset with features (size, rooms, location) and target (price).
  1. Preprocess Data
  • Handle missing values, scale numbers, encode categories.
  1. Split Data
  • Usually 80% training, 20% testing.
  1. Choose an Algorithm/Model
  • Regression (predict numbers),
  • Classification (predict categories),
  • Neural networks (deep learning tasks).
  1. Fit the Model (Training)
  • The model learns patterns from the training dataset.
  • Example: A decision tree learns rules like “if size > 2000 sqft → price higher”.

How to Test an AI Model

Testing means evaluating the trained model on data it has never seen before.

Steps:

1. Use Test Data (20%)

  • Provide unseen examples to the model.
  • Example: Give house features → model predicts price.

2. Compare Predictions with Actual Values

  • If actual price = 300,000 and model predicted 290,000, it’s close.
  • Collect errors for all test samples.

3. Evaluate Using Metrics

  • Accuracy (for classification).
  • Precision/Recall/F1-score (for imbalanced classes).
  • Mean Squared Error (MSE) or R² Score (for regression).

4. Training vs. Testing (Key Difference)

  • Training = Model learns from known data.
  • Testing = Model performance is measured on new, unseen data.

✅ Summary:

  • Collect & preprocess data.
  • Split into training & testing sets.
  • Train (fit) the model on training data.
  • Test it with unseen data.
  • Evaluate with metrics.

On this page