Skip to content

Commit 67047ce

Browse files
committed
Refactoring 'predict_y_values' function by using list comprehensions
1 parent b5b3e1c commit 67047ce

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

machine_learning/linear_discriminant_analysis.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,7 @@ def predict_y_values(x_items: list, means: list, variance: float, probabilities:
145145

146146
print("Generated Discriminants: \n", results)
147147

148-
predicted_index = (
149-
[]
150-
) # An empty list to store predicted indexes
151-
# for loop iterates over elements in 'results'
152-
for l in results:
153-
# after calculating the discriminant value for each class , the class with the largest
154-
# discriminant value is taken as the prediction, than we try to get index of that.
155-
predicted_index.append(l.index(max(l)))
156-
return predicted_index
148+
return [l.index(max(l)) for l in results]
157149

158150

159151
# Calculating Accuracy

0 commit comments

Comments
 (0)