Skip to content
Snippets Groups Projects
Commit fcb0e149 authored by benzinab's avatar benzinab
Browse files

cleanup

parent 29ad73fd
No related branches found
No related tags found
No related merge requests found
import json
import re
import random
import numpy as np
# Define the classification thresholds
......@@ -13,6 +14,7 @@ classifications = {
"D": (0, 599),
}
def init_criteria():
# Load the actions from the JSON file
with open("../../data/raw/actions/example_actions.json") as f:
......@@ -31,7 +33,8 @@ def init_criteria():
# Check if the regular expression matched any numeric characters
if rating:
try:
likelihood = (101 - abs(int(criterion["rating"])))/100 * subcategory_likelihoods[subcategory["name"]]
likelihood = (101 - abs(int(criterion["rating"]))) / 100 * subcategory_likelihoods[
subcategory["name"]]
except KeyError:
likelihood = 0
criteria.append({"name": criterion["name"],
......@@ -42,19 +45,21 @@ def init_criteria():
# Calculate the likelihood of each action
for criterion in criteria:
try:
criterion["likelihood"] = (101 - abs(criterion["rating"]))/100 * subcategory_likelihoods[criterion["subcategory_name"]]
criterion["likelihood"] = (101 - abs(criterion["rating"])) / 100 * subcategory_likelihoods[
criterion["subcategory_name"]]
except KeyError:
# you can set default value for the likelihood, for example
criterion["likelihood"] = 0
break
return criteria
# Define a function that applies a random action to a given citizen
def apply_random_action(citizen, criteria):
# Select an action based on the likelihood
likelihoods = [c["likelihood"] for c in criteria]
normalizing_factor = sum(likelihoods)
normalized_likelihoods = [likelihood/normalizing_factor for likelihood in likelihoods]
normalized_likelihoods = [likelihood / normalizing_factor for likelihood in likelihoods]
action_index = np.random.choice(len(criteria), p=normalized_likelihoods)
action = criteria[action_index]
......@@ -69,6 +74,7 @@ def apply_random_action(citizen, criteria):
citizen["classification"] = classification
break
# Define the main function that generates synthetic data for a sample of citizens
def generate_synthetic_data(n_citizens, max_actions):
# Initialize a list of citizens with 100 credit score and classification "A"
......@@ -83,9 +89,11 @@ def generate_synthetic_data(n_citizens, max_actions):
# Return the list of citizens with updated credit scores, applied actions, and classifications
return citizens
# Generate synthetic data for 10 citizens
citizens = generate_synthetic_data(10, 5)
# Print the list of citizens with their updated credit scores, applied actions, and classifications
for citizen in citizens:
print("SCORE: ", citizen["credit_score"], "| CLASS: ", citizen["classification"], "| ACTIONS: ", citizen["applied_actions"])
\ No newline at end of file
print("SCORE: ", citizen["credit_score"], "| CLASS: ", citizen["classification"], "| ACTIONS: ",
citizen["applied_actions"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment