Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Synthetic Dataset Generator for the Chinese Credit System in Rongcheng City
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sirajeddine Ben Zinab
Synthetic Dataset Generator for the Chinese Credit System in Rongcheng City
Commits
fcb0e149
Commit
fcb0e149
authored
2 years ago
by
benzinab
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
29ad73fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/data_processing/selection.py
+12
-4
12 additions, 4 deletions
src/data_processing/selection.py
with
12 additions
and
4 deletions
src/data_processing/selection.py
+
12
−
4
View file @
fcb0e149
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
"
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment