mstz commited on
Commit
56f86c7
·
1 Parent(s): ff648f2

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +18 -0
  2. student_performance.py +8 -12
README.md CHANGED
@@ -18,3 +18,21 @@ configs:
18
  ---
19
  # Student performance
20
  The [Student performance dataset](https://www.kaggle.com/datasets/ulrikthygepedersen/student_performances) is cool.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ---
19
  # Student performance
20
  The [Student performance dataset](https://www.kaggle.com/datasets/ulrikthygepedersen/student_performances) is cool.
21
+
22
+ # Configurations and tasks
23
+ - `encoding`, encoding dictionaries mapping binary and ordinal features to their value;
24
+ - `math` binary classification: has the student passed the math exam?
25
+ - `writing` binary classification: has the student passed the writing exam?
26
+ - `reading` binary classification: has the student passed the reading exam?
27
+
28
+ # Features
29
+ |**Feature** |**Type** |
30
+ |-----------------------------------|-----------|
31
+ |`sex` |`int8` |
32
+ |`ethnicity` |`string` |
33
+ |`parental_level_of_education` |`int8` |
34
+ |`has_standard_lunch` |`int8` |
35
+ |`has_completed_preparation_test` |`string` |
36
+ |`reading_score` |`int64` |
37
+ |`writing_score` |`int64` |
38
+ |`math_score` |`int64` |
student_performance.py CHANGED
@@ -130,8 +130,13 @@ class StudentPerformance(datasets.GeneratorBasedBuilder):
130
  ]
131
 
132
  def _generate_examples(self, filepath: str):
133
- data = pandas.read_csv(filepath)
134
- data = self.preprocess(data, config=self.config.name)
 
 
 
 
 
135
 
136
  for row_id, row in data.iterrows():
137
  data_row = dict(row)
@@ -139,9 +144,6 @@ class StudentPerformance(datasets.GeneratorBasedBuilder):
139
  yield row_id, data_row
140
 
141
  def preprocess(self, data: pandas.DataFrame, config: str = "cut") -> pandas.DataFrame:
142
- if config == "encoding":
143
- return self.encoding_dics()
144
-
145
  data.columns = _BASE_FEATURE_NAMES
146
  for feature in _ENCODING_DICS:
147
  encoding_function = partial(self.encode, feature)
@@ -162,22 +164,16 @@ class StudentPerformance(datasets.GeneratorBasedBuilder):
162
  data.loc[:, "has_passed_writing_exam"] = data.has_passed_writing_exam.apply(lambda x: int(x > 60))
163
 
164
  return data[list(features_types_per_config["writing"].keys())]
165
- else:
166
- raise ValueError(f"Unknown config: {config}")
167
 
168
  def encode(self, feature, value):
169
  return _ENCODING_DICS[feature][value]
170
 
171
  def encoding_dics(self):
172
- print("encoding...\n\n\n")
173
  data = [pandas.DataFrame([(feature, original, encoded) for original, encoded in d.items()])
174
  for feature, d in _ENCODING_DICS.items()]
175
- print("done...\n\n\n")
176
  data = pandas.concat(data, axis="rows").reset_index()
177
  data.drop("index", axis="columns", inplace=True)
178
- print(data)
179
- print(data.dtypes)
180
  data.columns = ["feature", "original_value", "encoded_value"]
181
- print("done...\n\n\n")
182
 
183
  return data
 
130
  ]
131
 
132
  def _generate_examples(self, filepath: str):
133
+ if self.config.name not in features_types_per_config:
134
+ raise ValueError(f"Unknown config: {self.config.name}")
135
+ elif self.config.name == "encoding":
136
+ data = self.encoding_dics()
137
+ else:
138
+ data = pandas.read_csv(filepath)
139
+ data = self.preprocess(data, config=self.config.name)
140
 
141
  for row_id, row in data.iterrows():
142
  data_row = dict(row)
 
144
  yield row_id, data_row
145
 
146
  def preprocess(self, data: pandas.DataFrame, config: str = "cut") -> pandas.DataFrame:
 
 
 
147
  data.columns = _BASE_FEATURE_NAMES
148
  for feature in _ENCODING_DICS:
149
  encoding_function = partial(self.encode, feature)
 
164
  data.loc[:, "has_passed_writing_exam"] = data.has_passed_writing_exam.apply(lambda x: int(x > 60))
165
 
166
  return data[list(features_types_per_config["writing"].keys())]
167
+
 
168
 
169
  def encode(self, feature, value):
170
  return _ENCODING_DICS[feature][value]
171
 
172
  def encoding_dics(self):
 
173
  data = [pandas.DataFrame([(feature, original, encoded) for original, encoded in d.items()])
174
  for feature, d in _ENCODING_DICS.items()]
 
175
  data = pandas.concat(data, axis="rows").reset_index()
176
  data.drop("index", axis="columns", inplace=True)
 
 
177
  data.columns = ["feature", "original_value", "encoded_value"]
 
178
 
179
  return data