mstz commited on
Commit
620782f
1 Parent(s): 568af05

Update balance_scale.py

Browse files
Files changed (1) hide show
  1. balance_scale.py +15 -4
balance_scale.py CHANGED
@@ -39,7 +39,14 @@ features_types_per_config = {
39
  "right_weight": datasets.Value("int64"),
40
  "right_distance": datasets.Value("int64"),
41
  "balance": datasets.ClassLabel(num_classes=3, names=("tips_left", "balanced", "tips_right"))
42
- }
 
 
 
 
 
 
 
43
  }
44
  features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
45
 
@@ -54,8 +61,8 @@ class Balance_Scale(datasets.GeneratorBasedBuilder):
54
  # dataset versions
55
  DEFAULT_CONFIG = "balance"
56
  BUILDER_CONFIGS = [
57
- Balance_ScaleConfig(name="balance",
58
- description="Multiclass classification of the scale balance."),
59
  ]
60
 
61
 
@@ -75,8 +82,12 @@ class Balance_Scale(datasets.GeneratorBasedBuilder):
75
  def _generate_examples(self, filepath: str):
76
  data = pandas.read_csv(filepath, header=None)
77
  data.columns = _BASE_FEATURE_NAMES
 
78
  data = data[["left_weight", "left_distance", "right_weight", "right_distance", "balance"]]
79
- data.loc[:, "balance"] = data.balance.apply(lambda x: 0 if x == "L" else 1 if x == "B" else 2)
 
 
 
80
 
81
  for row_id, row in data.iterrows():
82
  data_row = dict(row)
 
39
  "right_weight": datasets.Value("int64"),
40
  "right_distance": datasets.Value("int64"),
41
  "balance": datasets.ClassLabel(num_classes=3, names=("tips_left", "balanced", "tips_right"))
42
+ },
43
+ "is_balanced": {
44
+ "left_weight": datasets.Value("int64"),
45
+ "left_distance": datasets.Value("int64"),
46
+ "right_weight": datasets.Value("int64"),
47
+ "right_distance": datasets.Value("int64"),
48
+ "is_balanced": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
49
+ },
50
  }
51
  features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
52
 
 
61
  # dataset versions
62
  DEFAULT_CONFIG = "balance"
63
  BUILDER_CONFIGS = [
64
+ Balance_ScaleConfig(name="balance", description="Multiclass classification of the scale balance."),
65
+ Balance_ScaleConfig(name="is_balanced", description="Binary classification of the scale balance."),
66
  ]
67
 
68
 
 
82
  def _generate_examples(self, filepath: str):
83
  data = pandas.read_csv(filepath, header=None)
84
  data.columns = _BASE_FEATURE_NAMES
85
+
86
  data = data[["left_weight", "left_distance", "right_weight", "right_distance", "balance"]]
87
+ data["balance"] = data.balance.apply(lambda x: 0 if x == "L" else 1 if x == "B" else 2)
88
+ if self.config.name == "is_balanced":
89
+ data["balance"] = data.balance.apply(lambda x: 1 if x == 1 else 0)
90
+ data = data.rename(columns={"balance": "is_balanced"})
91
 
92
  for row_id, row in data.iterrows():
93
  data_row = dict(row)