MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / main

Function main

machine_learning/linear_discriminant_analysis.py:283–399  ·  view source on GitHub ↗

This function starts execution phase

()

Source from the content-addressed store, hash-verified

281
282# Main Function
283def main():
284 """This function starts execution phase"""
285 while True:
286 print(" Linear Discriminant Analysis ".center(50, "*"))
287 print("*" * 50, "\n")
288 print("First of all we should specify the number of classes that")
289 print("we want to generate as training dataset")
290 # Trying to get number of classes
291 n_classes = valid_input(
292 input_type=int,
293 condition=lambda x: x > 0,
294 input_msg="Enter the number of classes (Data Groupings): ",
295 err_msg="Number of classes should be positive!",
296 )
297
298 print("-" * 100)
299
300 # Trying to get the value of standard deviation
301 std_dev = valid_input(
302 input_type=float,
303 condition=lambda x: x >= 0,
304 input_msg=(
305 "Enter the value of standard deviation"
306 "(Default value is 1.0 for all classes): "
307 ),
308 err_msg="Standard deviation should not be negative!",
309 default="1.0",
310 )
311
312 print("-" * 100)
313
314 # Trying to get number of instances in classes and theirs means to generate
315 # dataset
316 counts = [] # An empty list to store instance counts of classes in dataset
317 for i in range(n_classes):
318 user_count = valid_input(
319 input_type=int,
320 condition=lambda x: x > 0,
321 input_msg=(f"Enter The number of instances for class_{i + 1}: "),
322 err_msg="Number of instances should be positive!",
323 )
324 counts.append(user_count)
325 print("-" * 100)
326
327 # An empty list to store values of user-entered means of classes
328 user_means = []
329 for a in range(n_classes):
330 user_mean = valid_input(
331 input_type=float,
332 input_msg=(f"Enter the value of mean for class_{a + 1}: "),
333 err_msg="This is an invalid value.",
334 )
335 user_means.append(user_mean)
336 print("-" * 100)
337
338 print("Standard deviation: ", std_dev)
339 # print out the number of instances in classes in separated line
340 for i, count in enumerate(counts, 1):

Callers 1

Calls 9

valid_inputFunction · 0.85
gaussian_distributionFunction · 0.85
y_generatorFunction · 0.85
calculate_meanFunction · 0.85
calculate_probabilitiesFunction · 0.85
calculate_varianceFunction · 0.85
predict_y_valuesFunction · 0.85
accuracyFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected