How-to
Get Your First Prediction from the KC1 API
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, thencd group6-kc1-defect-prediction. - Internet access for the first training run, which downloads the KC1 data set.
Steps#
Build the image.
docker compose buildTrain the model. The trainer downloads KC1, compares four candidates, and saves the selected model in
artifacts/.docker compose --profile train run --rm trainerThe last lines name the model and its threshold:
Selected: Logistic balanced; threshold: 0.50.Start the API in the background.
docker compose up -dCheck that the API has loaded the model.
curl http://127.0.0.1:8000/healthThe answer includes
"model_loaded": trueand"feature_count": 21.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}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.
Open
http://127.0.0.1:8000/docs, and select POST /predict.
Opens at full size in a new tab.Figure 1. The API's documentation page, with POST /predict marked. Select Try it out, and paste the contents of
module.jsoninto the request body.
Opens at full size in a new tab.Figure 2. The request body with the module's metrics, marked. Select Execute. The page shows the status code,
200, and the same response as step 6.
Opens at full size in a new tab.Figure 3. The server response, with the status code and the response body marked.
Next Steps#
- Read the KC1 Prediction API Reference for every field and every error.
- If a request fails, see Troubleshoot the KC1 API.