import random import csv attributes = { 1: ["empty", "low", "medium", "high"], 2: ["empty", "full"], 3: ["none", "available"], 4: ["none", "available"], 5: ["unavailable", "available"], 6: ["low", "medium", "high"], 7: ["no", "yes"], 8: ["no", "yes"] } dataset = [] while len(dataset) < 200: data = {} # Generate random values for attributes 1-7 for attr in range(1, 8): data[attr] = random.choice(attributes[attr]) # Apply the rules to determine the value of attribute 8 if data[1] in ["empty", "low"]: data[8] = "no" elif data[2] == "full" and data[4] == "none": data[8] = "no" elif data[2] == "empty" and data[3] == "none": data[8] = "no" elif data[3] == "none" and data[4] == "none": data[8] = "no" elif data[5] == "unavailable": data[8] = "no" elif data[6] == "low": data[8] = "no" elif data[7] == "yes": data[8] = "no" else: data[8] = "yes" # Check if the generated data already exists in the dataset if data not in dataset: dataset.append(data) # Print the generated dataset for data in dataset: print(data) with open("dataset/Dataset.csv", "w", newline="") as csvfile: writer = csv.writer(csvfile) # Write the header row writer.writerow(["Battery Charge", "Fullness", "Ready orders", "Waiting tables","Availability", "Cleanliness", "Error", "To go"]) # Write the data rows for data in dataset: row = [data[attr] for attr in range(1, 9)] writer.writerow(row)