Case 2. Phishing email filter – MLPClassifier in RubixML

Implementation in RubixML

We build a multilayer neural network that classifies suspicious emails. EmailFeatureExtractor turns an email into five numeric features (link, unknown sender, urgent words, password request, attachment), the vectors are wrapped into a Labeled dataset, and a multilayer perceptron (5 → 8 → 4 → output) is trained with Adam and CrossEntropy. After training we get the class and the phishing probability, and the application decides whether to block the email. RubixML does not replace backpropagation – it automates it inside train().

Example of code: Class EmailFeatureExtractor:

 
<?php

namespace app\classes;

class 
EmailFeatureExtractor {
    public function 
extract(array $email): array {
        return [
            
$this->hasLink($email['body']),
            
$email['unknown_sender'] ? 1 : 0,
            
$this->hasUrgentWords($email['body']),
            
$this->hasPasswordRequest($email['body']),
            
$email['attachment'] ? 1 : 0,
        ];
    }

    private function 
hasLink(string $text): int {
        return 
str_contains($text, 'http') ? 1 : 0;
    }

    private function 
hasUrgentWords(string $text): int {
        
$words = [
            
'urgent',
            
'immediately',
            
'today',
        ];

        foreach (
$words as $word) {
            if (
stripos($text, $word) !== false) {
                return 
1;
            }
        }

        return 
0;
    }

    private function 
hasPasswordRequest(string $text): int {
        return 
str_contains(strtolower($text), 'password') ? 1 : 0;
    }
}