MCPcopy Index your code
hub / github.com/geekcomputers/Python / score

Function score

scalg.py:30–103  ·  view source on GitHub ↗

Analyse and score a dataset using a range based percentual proximity algorithm and calculate the linear maximum likelihood estimation. Args: source_data (list): Data set to process. weights (list): Weights corresponding to each column from the data set. 0 if lower

(source_data: list, weights: list, *args)

Source from the content-addressed store, hash-verified

28
29
30def score(source_data: list, weights: list, *args) -> list:
31 """Analyse and score a dataset using a range based percentual proximity
32 algorithm and calculate the linear maximum likelihood estimation.
33 Args:
34 source_data (list): Data set to process.
35 weights (list): Weights corresponding to each column from the data set.
36 0 if lower values have higher weight in the data set,
37 1 if higher values have higher weight in the data set
38 Optional args:
39 "score_lists" (str): Returns a list with lists of each column scores.
40 "scores" (str): Returns only the final scores.
41 Raises:
42 ValueError: Weights can only be either 0 or 1 (int)
43 Returns:
44 list: Source data with the score of the set appended at as the last element.
45 """
46
47 # getting data
48 data_lists = []
49 for item in source_data:
50 for i, val in enumerate(item):
51 try:
52 data_lists[i].append(float(val))
53 except IndexError:
54 data_lists.append([])
55 data_lists[i].append(float(val))
56
57 # calculating price score
58 score_lists = []
59 for dlist, weight in zip(data_lists, weights):
60 mind = min(dlist)
61 maxd = max(dlist)
62
63 score = []
64 if weight == 0:
65 for item in dlist:
66 try:
67 score.append(1 - ((item - mind) / (maxd - mind)))
68 except ZeroDivisionError:
69 score.append(1)
70
71 elif weight == 1:
72 for item in dlist:
73 try:
74 score.append((item - mind) / (maxd - mind))
75 except ZeroDivisionError:
76 score.append(0)
77
78 else:
79 raise ValueError("Invalid weight of %f provided" % (weight))
80
81 score_lists.append(score)
82
83 # return score lists
84 if "score_lists" in args:
85 return score_lists
86
87 # initialize final scores

Callers 1

score_columnsFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected