How-to

Get Your First Prediction from the KC1 API

KC1 defect prediction. KC1-API-002, version 1.0, published 2026-11-19. 2 min read. Source on GitHub. Passes the style check.

PDF, 14 pages, with the set’s other documentsHTML5, from DITA Open Toolkit

Train the KC1 model, start the prediction API, and send it the metrics of one software module.

Before You Start#

  • Docker with Compose version 2. Check with docker compose version.
  • A copy of the project: git clone https://github.com/domail2karandeshmukh-cyber/group6-kc1-defect-prediction.git, then cd group6-kc1-defect-prediction.
  • Internet access for the first training run, which downloads the KC1 data set.

Steps#

  1. Build the image.

    docker compose build
  2. Train the model. The trainer downloads KC1, compares four candidates, and saves the selected model in artifacts/.

    docker compose --profile train run --rm trainer

    The last lines name the model and its threshold: Selected: Logistic balanced; threshold: 0.50.

  3. Start the API in the background.

    docker compose up -d
  4. Check that the API has loaded the model.

    curl http://127.0.0.1:8000/health

    The answer includes "model_loaded": true and "feature_count": 21.

  5. Save the metrics of a module in a file named module.json.

    {"loc": 25, "v(g)": 3, "ev(g)": 1, "iv(g)": 3, "n": 58, "v": 254.75, "l": 0.11, "d": 9.35, "i": 27.25, "e": 2381.95, "b": 0.08, "t": 132.33, "lOCode": 21, "lOComment": 0, "lOBlank": 2, "locCodeAndComment": 0, "uniq_Op": 11, "uniq_Opnd": 10, "total_Op": 41, "total_Opnd": 17, "branchCount": 5}
  6. Send the file to the API.

    curl -X POST http://127.0.0.1:8000/predict -H "Content-Type: application/json" -d @module.json

Check That It Worked#

The API answers with one prediction.

{"prediction": 0, "label": "Non-defective", "defect_probability": 0.3920490229417669, "threshold": 0.5, "model": "Logistic balanced"}

These outputs are real. On 19 November 2026, the project's trainer produced the output in step 2. FastAPI's test client recorded the answers in steps 4 and 6 by calling the API in the same process. The Docker commands come from the project's README, and that check didn't include them.

Try It from the API’s Own Page#

The API serves an interactive page at http://127.0.0.1:8000/docs, made by Swagger UI from the API's OpenAPI description.

  1. Open http://127.0.0.1:8000/docs, and select POST /predict.

    The API's documentation page, with POST /predict marked Opens at full size in a new tab.
    Figure 1. The API's documentation page, with POST /predict marked.
  2. Select Try it out, and paste the contents of module.json into the request body.

    The request body with the module's metrics, marked Opens at full size in a new tab.
    Figure 2. The request body with the module's metrics, marked.
  3. Select Execute. The page shows the status code, 200, and the same response as step 6.

    The server response, with the status code and the response body marked Opens at full size in a new tab.
    Figure 3. The server response, with the status code and the response body marked.

Next Steps#