| 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

utils.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 hashlib import md5 as md5
16 from hashlib import sha256 as sha256
17 from pandas import read_json
18 from json import dumps
19 from copy import deepcopy
20 from numpy.random import rand
21 from gdayf.common.dfmetada import compare_dict
22
23
27 def hash_key(hash_type, filename):
28 if hash_type == 'MD5':
29 try:
30 return md5(open(filename, 'rb').read()).hexdigest()
31 except IOError:
32 raise
33 elif hash_type == 'SHA256':
34 try:
35 return sha256(open(filename, 'rb').read()).hexdigest()
36 except IOError:
37 raise
38
39
40
44 def decode_json_to_dataframe(json_string, orient='split'):
45 return read_json(json_string, orient=orient)
46
47
48
52 def decode_ordered_dict_to_dataframe(ordered_dict, orient='split'):
53 json_string = dumps(ordered_dict)
54 return decode_json_to_dataframe(json_string, orient='split')
55
56
57
61 def compare_list_ordered_dict(list1, list2):
62 if list1[0] is None or list2[0] is None:
63 return list1[0] is None and list2[0] is None
64 elif len(list1) != len(list2):
65 return False
66 else:
67 for i in range(0, len(list1)):
68 if not compare_dict(list1[i], list2[i]):
69 return False
70 return True
71
72
73
78 def compare_sorted_list_dict(list1, list2):
79 if list1 is None or list2 is None:
80 return list1 is None and list2 is None
81 elif len(list1) != len(list2):
82 return False
83 else:
84 for i in range(0, len(list1)):
85 if not (list1[i] == list2[i]):
86 return False
87 return True
88
89 def get_model_fw(model):
90 return list(model['model_parameters'].keys())[0]
91
92
93
96 def get_model_ns(model):
97 return deepcopy(model['normalizations_set'])
98
99
100
104 def pandas_split_data(df, train_perc=0.9):
105 df['train'] = rand(len(df)) < train_perc
106 train = df[df.train == 1].drop('train', axis=1)
107 test = df[df.train == 0].drop('train', axis=1)
108 return train, test
109
110
111
114 def xstr(s):
115 if s is None:
116 return ''
117 return str(s)
gdayf.common.utils.compare_sorted_list_dict
def compare_sorted_list_dict(list1, list2)
Function oriented compare two normalizations_sets based on cmp functions Need to be sorted in same or...
Definition: utils.py:78
gdayf.common.dfmetada
Define all objects, functions and structured related to Data Analysis of input data on OrderedDict fo...
Definition: dfmetada.py:1
gdayf.common.utils.hash_key
def hash_key(hash_type, filename)
Function oriented to get the hash_key for a file.
Definition: utils.py:27
gdayf.common.utils.decode_ordered_dict_to_dataframe
def decode_ordered_dict_to_dataframe(ordered_dict, orient='split')
Function oriented convert a OrderedDict() dataframe string structure on pandas.dataframe() ...
Definition: utils.py:52
gdayf.common.utils.decode_json_to_dataframe
def decode_json_to_dataframe(json_string, orient='split')
Function oriented convert a json dataframe string structure on pandas.dataframe() ...
Definition: utils.py:44
gdayf.common.utils.get_model_ns
def get_model_ns(model)
Function to get normalization_sets structure from ar.json model description.
Definition: utils.py:96
gdayf.common.utils.compare_list_ordered_dict
def compare_list_ordered_dict(list1, list2)
Function oriented compare two normalizations_sets based on hash_key(json transformations) ...
Definition: utils.py:61
gdayf.common.utils.get_model_fw
def get_model_fw(model)
Function to get framework from ar.json model description.
Definition: utils.py:89
gdayf.common.utils.pandas_split_data
def pandas_split_data(df, train_perc=0.9)
Function to get pandas dataframe split without copy.
Definition: utils.py:104
gdayf.common.utils.xstr
def xstr(s)
Function to return empty string if String variable is None.
Definition: utils.py:114