An end-to-end Machine Learning platform combining fraud detection, regression, NLP, recommendation systems, and deep learning into a unified Java system with production-ready REST APIs.
This project is a full-stack Java ML platform that brings together five distinct machine learning domains into a single, cohesive system. Each module is independently trained, served through its own REST endpoint, and designed with graceful fallbacks β making the platform resilient, extensible, and production-aware.
ai-intelligence-platform-java-ml/
β
βββ src/main/java/com/mazen/aiplatform/
β βββ Application.java # Spring Boot entry point
β β
β βββ controllers/
β β βββ FraudController.java # POST /api/fraud/predict
β β βββ PriceController.java # POST /api/price/predict
β β βββ NlpController.java # POST /api/nlp/sentiment & /spam
β β βββ RecommendController.java # POST /api/recommend
β β βββ ImageController.java # POST /api/image/predict
β β βββ GlobalExceptionHandler.java # Unified error handling
β β
β βββ services/
β β βββ FraudService.java # Fraud detection orchestration
β β βββ PriceService.java # Price prediction orchestration
β β βββ NlpService.java # Sentiment + Spam orchestration
β β βββ RecommendService.java # Recommendation orchestration
β β βββ ImageService.java # Image classification orchestration
β β
β βββ ml/
β β βββ fraud/FraudDetector.java # Weka J48 + rule-based fallback
β β βββ regression/PricePredictor.java # Gradient descent regression
β β βββ nlp/SentimentAnalyzer.java # Lexicon-based sentiment engine
β β βββ nlp/SpamDetector.java # Keyword + pattern spam scorer
β β βββ recommender/RecommenderEngine.java # Collaborative filtering (cosine)
β β βββ deep_learning/ImageClassifier.java # DL4J 4-layer dense network
β β
β βββ models/
β β βββ FraudRequest.java
β β βββ PriceRequest.java
β β βββ NlpRequest.java
β β βββ RecommendRequest.java
β β βββ PredictionResponse.java
β β
β βββ utils/
β βββ CsvUtils.java # CSV parsing utility
β
βββ datasets/ # Auto-loaded on startup
βββ saved_models/ # PMML / ONNX exports
βββ pom.xml
βββ README.md
| Module | Algorithm | Library | Fallback |
|---|---|---|---|
| Fraud Detection | J48 Decision Tree | Weka | Rule-based risk scoring engine |
| Price Prediction | Linear Regression (Gradient Descent) | Custom | Weighted estimation formula |
| Sentiment Analysis | Lexicon-based + Negation Handling | Custom | Seed lexicon (45+ words) |
| Spam Detection | Keyword + Pattern Scoring | Custom | Keyword matching |
| Recommendations | Collaborative Filtering (Cosine Similarity) | Custom | Empty response for unknown users |
| Image Classification | Dense Neural Network (784β256β128β64β10) | DL4J | Architecture-only (requires MNIST training) |
βββββββββββββ ββββββββββββββββ βββββββββββββββββ ββββββββββββββββ
β Request β βββΆ β Controller β βββΆ β Service β βββΆ β ML Module β
β (JSON API) β β (Validation) β β (Orchestrate) β β (Predict) β
βββββββββββββ ββββββββββββββββ βββββββββββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββ
β Response β
β (JSON + %) β
ββββββββββββββββ
- Receive a JSON request through the REST API
- Validate input using Bean Validation annotations
- Route to the appropriate service and ML module
- Predict using the trained model (or graceful fallback)
- Return a structured response with prediction, confidence, and metadata
Prerequisites: Java 17+, Maven
# Clone
git clone https://github.com/mazen-naji/ai-intelligence-platform-java-ml.git
cd ai-intelligence-platform-java-ml
# Build
mvn clean install
# Run
mvn spring-boot:runThe server starts at http://localhost:8080.
Fraud Detection
curl -X POST http://localhost:8080/api/fraud/predict \
-H "Content-Type: application/json" \
-d '{"amount": 15000, "transactionType": "online"}'Price Prediction
curl -X POST http://localhost:8080/api/price/predict \
-H "Content-Type: application/json" \
-d '{"size": 120, "rooms": 3, "location": "Beirut", "age": 10}'Sentiment Analysis
curl -X POST http://localhost:8080/api/nlp/sentiment \
-H "Content-Type: application/json" \
-d '{"text": "This product is amazing!"}'Spam Detection
curl -X POST http://localhost:8080/api/nlp/spam \
-H "Content-Type: application/json" \
-d '{"text": "WIN FREE MONEY NOW!!!"}'Recommendations
curl -X POST http://localhost:8080/api/recommend \
-H "Content-Type: application/json" \
-d '{"userId": 1, "maxResults": 5}'All datasets are inside /datasets and loaded automatically on startup.
| File | Records | Purpose |
|---|---|---|
fraud_transactions.csv |
100 | Transaction classification (fraud / legitimate) |
house_prices.csv |
100 | Real estate price regression |
sentiment_data.csv |
100 | Sentiment classification (positive / negative / neutral) |
spam_emails.csv |
100 | Email classification (spam / ham) |
recommendations.csv |
100 | User-item ratings for collaborative filtering |
mvn testUnit tests cover all ML modules: fraud detection, sentiment analysis, spam detection, price prediction, and the recommendation engine.
Adding a new ML module requires zero changes to existing code β just follow the established pattern:
// 1. Create the ML module
@Component
public class AnomalyDetector {
public Map<String, Object> detect(double[] features) {
// Your anomaly detection logic
}
}
// 2. Create the service
@Service
public class AnomalyService {
private final AnomalyDetector detector;
// Orchestration logic
}
// 3. Create the controller
@RestController
@RequestMapping("/api/anomaly")
public class AnomalyController {
@PostMapping("/detect")
public ResponseEntity<PredictionResponse> detect(@RequestBody ...) {
// Expose via REST
}
}- Docker containerization
- React frontend dashboard
- Real-time streaming with Apache Kafka
- Cloud deployment (AWS / Azure)
- JWT authentication
- Model versioning and A/B testing
- Swagger / OpenAPI documentation
| Language | Java 17+ |
| Framework | Spring Boot 4.0 |
| ML Libraries | Weka, Tribuo, Deeplearning4j, Apache OpenNLP |
| Build Tool | Maven |
| Model Export | PMML (Weka / Tribuo), ONNX (Deep Learning) |
| Testing | JUnit 5, Spring Boot Test |
Contributions are welcome! Feel free to fork and submit a pull request.
- Fork the repository
- Create your feature branch β
git checkout -b feature/new-module - Commit your changes β
git commit -m "Add anomaly detection module" - Push to the branch β
git push origin feature/new-module - Open a Pull Request
Built by Mazen Naji
β If you found this useful, a star goes a long way!