4.3 KiB
4.3 KiB
API TESTING REPORT
Generated: 2026-04-04
✅ LANGKAH 1: FLASK API DIBUAT
File yang Dibuat
- ✅
app.py- Flask REST API (complete) - ✅
requirements.txt- Python dependencies
API Endpoints
- GET /health - Health check
- GET /metadata - Model metadata
- GET /info - API information
- POST /prediksi - Single prediction
- POST /batch-prediksi - Batch prediction
✅ LANGKAH 2: API TESTING
Test Results
1. Health Check
GET /health
Status: 200 OK ✅
Response:
{
"status": "healthy",
"model_type": "Random Forest",
"r2_score": 0.9964,
"timestamp": "2026-04-04T14:52:25.670963"
}
2. Metadata Endpoint
GET /metadata
Status: 200 OK ✅
Response:
{
"status": "success",
"model_info": {
"type": "Random Forest",
"r2_score": 0.9964,
"mae": 0.0295,
"rmse": 0.1178,
"features": [10 features],
"target": "jumlah_permintaan_bahan",
"total_samples": 6742
}
}
3. Single Prediction
POST /prediksi
Status: 200 OK ✅
Input:
{
"tahun": 2024,
"bulan": 4,
"hari": 4,
"hari_dalam_minggu": 3,
"harga_satuan_update": 50000,
"total_harga_update": 250000,
"produk_encoded": 2,
"nama_produk_encoded": 2,
"kategori_produk_encoded": 1,
"hari_minggu": 3
}
Response:
{
"status": "success",
"prediksi": {
"jumlah_unit": 7,
"nilai_raw": 6.9
},
"model_accuracy": {
"r2_score": 0.9964,
"mae": 0.0295,
"rmse": 0.1178
}
}
4. Batch Prediction
POST /batch-prediksi
Status: 200 OK ✅
Items: 2
Results:
[
{
"index": 0,
"status": "success",
"prediksi": 7,
"nilai_raw": 6.9
},
{
"index": 1,
"status": "success",
"prediksi": 9,
"nilai_raw": 8.81
}
]
5. API Info
GET /info
Status: 200 OK ✅
Response:
{
"api_name": "Prediksi Permintaan Stok Bahan",
"version": "2.0",
"model": "Random Forest",
"endpoints": {
"GET /health": "API health check",
"GET /metadata": "Get model metadata",
"GET /info": "Get API info",
"POST /prediksi": "Single prediction",
"POST /batch-prediksi": "Batch prediction"
}
}
📊 TEST SUMMARY
| Test | Endpoint | Status | Response Time |
|---|---|---|---|
| Health Check | GET /health | ✅ PASS | ~50ms |
| Metadata | GET /metadata | ✅ PASS | ~30ms |
| Single Prediction | POST /prediksi | ✅ PASS | ~100ms |
| Batch Prediction | POST /batch-prediksi | ✅ PASS | ~150ms |
| API Info | GET /info | ✅ PASS | ~25ms |
Overall Status: 🟢 ALL TESTS PASSED ✅
🚀 API READY FOR DEPLOYMENT
Server Configuration
- Host: 0.0.0.0 (all interfaces)
- Port: 5000
- Debug Mode: Disabled
- CORS: Enabled (for Flutter integration)
Requirements
All dependencies installed:
- Flask 2.3.0
- Flask-CORS 4.0.0
- scikit-learn 1.2.0
- joblib 1.3.0
- pandas 2.0.0
- numpy 1.25.0
How to Run
cd ml_model
python app.py
Output:
[INFO] Models loaded successfully
[INFO] Model: Random Forest
[INFO] Accuracy (R²): 0.9964
[INFO] Running on http://0.0.0.0:5000
✨ NEXT STEP: INTEGRATE TO FLUTTER
For Flutter Integration:
-
Update API URL in
ml_service.dart:static const String baseUrl = 'http://localhost:5000'; // OR for remote: 'http://192.168.1.X:5000' -
Map features to API payload
-
Handle responses in Flutter
📋 FILES CREATED
ml_model/
├── ✅ model_prediksi.pkl (2.7M) - Random Forest Model
├── ✅ encoders.pkl (973B) - Label Encoders
├── ✅ feature_columns.pkl (181B) - Feature List
├── ✅ model_metadata.pkl (440B) - Model Metadata
├── ✅ model_testing.py - Testing Script
├── ✅ app.py - Flask API (NEW)
├── ✅ requirements.txt - Dependencies (NEW)
├── ✅ model_testing_results.txt - Results Report
└── ✅ TESTING_SUMMARY.md - Summary Doc
✅ COMPLETION STATUS
- ✅ Step 1: Buat Flask API - DONE
- ✅ Step 2: Test API - DONE
Status: 🟢 READY FOR FLUTTER INTEGRATION