cli/streamingphish/streamingphish/trainer.py
def _compute_metrics(self):
        """
        Computes metrics from the newly trained classifier important to evaluating
        the classifier's performance and accuracy, i.e.:
            accuracy
                TPR, FPR, precision, recall, AUC, confusion matrix,
                accuracy against training/test
            info
                algorithm, parameters, date/time, training set makeup
            performance
                training speed, analysis speed

        Args:
            None, as all artifacts needed for computation are assigned as class attributes.
        """
        tqdm.tqdm.write("[*] Computing classifier metrics...")
        result = {}

        # First, gather info about the trained classifier.
        result['info'] = {}
        result['info']['algorithm'] = str(self._classifier).split('(')[0]
        result['info']['parameters'] = self._classifier.get_params()
        result['info']['training_date'] = str(datetime.now())
        result['info']['training_samples'] = {}
        result['info']['training_samples']['not_phishing'] = np.count_nonzero(self._labels == 0)
        result['info']['training_samples']['phishing'] = np.count_nonzero(self._labels == 1)
        result['info']['feature_vector_size'] = len(self._feature_vector)

        # Next, grab accuracy info.
        result['accuracy'] = {}
        result['accuracy']['training_set_accuracy'] = "{:.4f}".format(self._classifier.score(
            self._x_train, self._y_train))
        result['accuracy']['test_set_accuracy'] = "{:.4f}".format(self._classifier.score(
            self._x_test, self._y_test))

        # Accuracy - TPR, FPR, AUC score.
        # Also consider that not all algorithms support the predict_proba function.
        fpr, tpr, thresholds = roc_curve(self._y_test, self._classifier.predict_proba(
            self._x_test)[:, 1])
        close_zero = np.argmin(np.abs(thresholds - 0.5))
        result['accuracy']['true_positive_rate'] = "{:.4f}".format(tpr[close_zero])
        result['accuracy']['false_positive_rate'] = "{:.4f}".format(fpr[close_zero])
        auc = roc_auc_score(self._y_test, self._classifier.predict_proba(self._x_test)[:, 1] > 0.5)
        result['accuracy']['auc_score'] = "{:.4f}".format(auc)

        # Accuracy - precision and recall.
        precision, recall, thresholds = \
            precision_recall_curve(self._y_test, self._classifier.predict_proba(self._x_test)[:, 1])
        close_zero = np.argmin(np.abs(thresholds - 0.5))
        result['accuracy']['precision'] = "{:.4f}".format(precision[close_zero])
        result['accuracy']['recall'] = "{:.4f}".format(recall[close_zero])

        # Accuracy - confusion matrix.
        predictions = self._classifier.predict_proba(self._x_test)[:, 1] > 0.5
        confusion = confusion_matrix(self._y_test, predictions)
        result['accuracy']['confusion_matrix'] = confusion.tolist()

        tqdm.tqdm.write("[+] Classifier metrics available.")
        self._metrics = result

        Computes metrics from the newly trained classifier important to evaluating
        the classifier's performance and accuracy, i.e.:
            accuracy
                TPR, FPR, precision, recall, AUC, confusion matrix,
                accuracy against training/test
            info
                algorithm, parameters, date/time, training set makeup
            performance
                training speed, analysis speed

        Args:
            None, as all artifacts needed for computation are assigned as class attributes.
        
Computes metrics from the newly trained classifier important to evaluating
the classifier's performance and accuracy, i.e.:
accuracy
TPR, FPR, precision, recall, AUC, confusion matrix,
accuracy against training/test
info
algorithm, parameters, date/time, training set makeup
performance
training speed, analysis speed

None, as all artifacts needed for computation are assigned as class attributes.
Computes metrics from the newly trained classifier important to evaluating the classifier ' s performance and accuracy i . e . : accuracy TPR FPR precision recall AUC confusion matrix accuracy against training / test info algorithm parameters date / time training set makeup performance training speed analysis speed None as all artifacts needed for computation are assigned as class attributes .
def _compute_metrics(self):
        tqdm.tqdm.write("[*] Computing classifier metrics...")
        result = {}
        result['info'] = {}
        result['info']['algorithm'] = str(self._classifier).split('(')[0]
        result['info']['parameters'] = self._classifier.get_params()
        result['info']['training_date'] = str(datetime.now())
        result['info']['training_samples'] = {}
        result['info']['training_samples']['not_phishing'] = np.count_nonzero(self._labels == 0)
        result['info']['training_samples']['phishing'] = np.count_nonzero(self._labels == 1)
        result['info']['feature_vector_size'] = len(self._feature_vector)
        result['accuracy'] = {}
        result['accuracy']['training_set_accuracy'] = "{:.4f}".format(self._classifier.score(
            self._x_train, self._y_train))
        result['accuracy']['test_set_accuracy'] = "{:.4f}".format(self._classifier.score(
            self._x_test, self._y_test))
        fpr, tpr, thresholds = roc_curve(self._y_test, self._classifier.predict_proba(
            self._x_test)[:, 1])
        close_zero = np.argmin(np.abs(thresholds - 0.5))
        result['accuracy']['true_positive_rate'] = "{:.4f}".format(tpr[close_zero])
        result['accuracy']['false_positive_rate'] = "{:.4f}".format(fpr[close_zero])
        auc = roc_auc_score(self._y_test, self._classifier.predict_proba(self._x_test)[:, 1] > 0.5)
        result['accuracy']['auc_score'] = "{:.4f}".format(auc)
        precision, recall, thresholds = \
            precision_recall_curve(self._y_test, self._classifier.predict_proba(self._x_test)[:, 1])
        close_zero = np.argmin(np.abs(thresholds - 0.5))
        result['accuracy']['precision'] = "{:.4f}".format(precision[close_zero])
        result['accuracy']['recall'] = "{:.4f}".format(recall[close_zero])
        predictions = self._classifier.predict_proba(self._x_test)[:, 1] > 0.5
        confusion = confusion_matrix(self._y_test, predictions)
        result['accuracy']['confusion_matrix'] = confusion.tolist()
        tqdm.tqdm.write("[+] Classifier metrics available.")
        self._metrics = result
def _compute_metrics ( self ) : tqdm . tqdm . write ( "[*] Computing classifier metrics..." ) result = { } result [ 'info' ] = { } result [ 'info' ] [ 'algorithm' ] = str ( self . _classifier ) . split ( '(' ) [ 0 ] result [ 'info' ] [ 'parameters' ] = self . _classifier . get_params ( ) result [ 'info' ] [ 'training_date' ] = str ( datetime . now ( ) ) result [ 'info' ] [ 'training_samples' ] = { } result [ 'info' ] [ 'training_samples' ] [ 'not_phishing' ] = np . count_nonzero ( self . _labels == 0 ) result [ 'info' ] [ 'training_samples' ] [ 'phishing' ] = np . count_nonzero ( self . _labels == 1 ) result [ 'info' ] [ 'feature_vector_size' ] = len ( self . _feature_vector ) result [ 'accuracy' ] = { } result [ 'accuracy' ] [ 'training_set_accuracy' ] = "{:.4f}" . format ( self . _classifier . score ( self . _x_train , self . _y_train ) ) result [ 'accuracy' ] [ 'test_set_accuracy' ] = "{:.4f}" . format ( self . _classifier . score ( self . _x_test , self . _y_test ) ) fpr , tpr , thresholds = roc_curve ( self . _y_test , self . _classifier . predict_proba ( self . _x_test ) [ : , 1 ] ) close_zero = np . argmin ( np . abs ( thresholds - 0.5 ) ) result [ 'accuracy' ] [ 'true_positive_rate' ] = "{:.4f}" . format ( tpr [ close_zero ] ) result [ 'accuracy' ] [ 'false_positive_rate' ] = "{:.4f}" . format ( fpr [ close_zero ] ) auc = roc_auc_score ( self . _y_test , self . _classifier . predict_proba ( self . _x_test ) [ : , 1 ] > 0.5 ) result [ 'accuracy' ] [ 'auc_score' ] = "{:.4f}" . format ( auc ) precision , recall , thresholds = precision_recall_curve ( self . _y_test , self . _classifier . predict_proba ( self . _x_test ) [ : , 1 ] ) close_zero = np . argmin ( np . abs ( thresholds - 0.5 ) ) result [ 'accuracy' ] [ 'precision' ] = "{:.4f}" . format ( precision [ close_zero ] ) result [ 'accuracy' ] [ 'recall' ] = "{:.4f}" . format ( recall [ close_zero ] ) predictions = self . _classifier . predict_proba ( self . _x_test ) [ : , 1 ] > 0.5 confusion = confusion_matrix ( self . _y_test , predictions ) result [ 'accuracy' ] [ 'confusion_matrix' ] = confusion . tolist ( ) tqdm . tqdm . write ( "[+] Classifier metrics available." ) self . _metrics = result
Computes metrics from the newly trained classifier important to evaluating
the classifier's performance and accuracy, i.e.
Computes metrics from the newly trained classifier important to evaluating the classifier ' s performance and accuracy i . e .
"""
        Computes metrics from the newly trained classifier important to evaluating
        the classifier's performance and accuracy, i.e.:
            accuracy
                TPR, FPR, precision, recall, AUC, confusion matrix,
                accuracy against training/test
            info
                algorithm, parameters, date/time, training set makeup
            performance
                training speed, analysis speed

        Args:
            None, as all artifacts needed for computation are assigned as class attributes.
        """ # First, gather info about the trained classifier. # Next, grab accuracy info. # Accuracy - TPR, FPR, AUC score. # Also consider that not all algorithms support the predict_proba function. # Accuracy - precision and recall. # Accuracy - confusion matrix.
self