| DayF core 1.2.1.2 DayF (Decision at your Fingertips) is an AutoML freeware development framework that let developers works with Machine Learning models without any idea of AI, simply taking a csv dataset and the objective column

sparkbinomialmetricmetadata.py
1
4
5 '''
6 Copyright (C) e2its - All Rights Reserved
7 * Unauthorized copying of this file, via any medium is strictly prohibited
8 * Proprietary and confidential
9 *
10 * This file is part of gDayF project.
11 *
12 * Written by Jose L. Sanchez <e2its.es@gmail.com>, 2016-2019
13 '''
14
15 from collections import OrderedDict
16 from gdayf.metrics.binomialmetricmetadata import BinomialMetricMetadata
17 from pandas import DataFrame
18 import numpy as np
19 import time
20 from pyspark.mllib.evaluation import MulticlassMetrics
21 import json
22
23
24
31 class SparkBinomialMetricMetadata(BinomialMetricMetadata):
32
34 def __init__(self):
35 BinomialMetricMetadata.__init__(self)
36
37
42 def set_metrics(self, evaluator, data, objective_column):
43
44 start = time.time()
45 if evaluator is not None and data is not None:
46 self['AUC'] = evaluator.evaluate(data, {evaluator.metricName: "areaUnderROC"})
47 self['AUPR'] = evaluator.evaluate(data, {evaluator.metricName: "areaUnderPR"})
48 self['nobs'] = data.count()
49 self['model_category'] = 'Binomial'
50 self['max_criteria_and_metric_scores'] = None
51 self['RMSE'] = 10e+308
52
53 #Generating ConfusionMatrix
54 tp = data.select("prediction", data[objective_column].cast('float'))\
55 .toDF("prediction", objective_column).rdd.map(tuple)
56 metrics = MulticlassMetrics(tp)
57 pdf = DataFrame(data=np.array(metrics.confusionMatrix().values).reshape((2, 2)),
58 columns=['0', '1'])
59 pdf['total'] = pdf.sum(axis=1)
60 index = pdf.index.tolist()
61 index.append('total')
62 pdf = pdf.append(pdf.sum(axis=0), ignore_index=True)
63 pdf.index = index
64 self['cm'] = json.loads(pdf.to_json(orient='split'), object_pairs_hook=OrderedDict)
65
66 self['scoring_time'] = int(time.time() - start)
67
68
gdayf.handler_metrics.sparkbinomialmetricmetadata.SparkBinomialMetricMetadata.set_metrics
def set_metrics(self, evaluator, data, objective_column)
Method to load Binomial metrics from Spark BinaryClassificationEvaluator class.
Definition: sparkbinomialmetricmetadata.py:42
gdayf.handler_metrics.sparkbinomialmetricmetadata.SparkBinomialMetricMetadata.__init__
def __init__(self)
Method constructor.
Definition: sparkbinomialmetricmetadata.py:34
gdayf.metrics.binomialmetricmetadata
Define Binomial Metric object as OrderedDict() of common measures for all frameworks on an unified wa...
Definition: binomialmetricmetadata.py:1
gdayf.metrics.binomialmetricmetadata.BinomialMetricMetadata
Class Base for Binomial metricts as OrderedDict.
Definition: binomialmetricmetadata.py:31
gdayf.handler_metrics.sparkbinomialmetricmetadata.SparkBinomialMetricMetadata
Class Base for Binomial metricts as OrderedDict.
Definition: sparkbinomialmetricmetadata.py:31