Set property into the Dataset. Parameters ---------- field_name : string The field name of the information. data : list, numpy 1-D array, pandas Series or None The array of data to be set. Returns ------- self : Datase
(self, field_name, data)
| 1188 | return self |
| 1189 | |
| 1190 | def set_field(self, field_name, data): |
| 1191 | """Set property into the Dataset. |
| 1192 | |
| 1193 | Parameters |
| 1194 | ---------- |
| 1195 | field_name : string |
| 1196 | The field name of the information. |
| 1197 | data : list, numpy 1-D array, pandas Series or None |
| 1198 | The array of data to be set. |
| 1199 | |
| 1200 | Returns |
| 1201 | ------- |
| 1202 | self : Dataset |
| 1203 | Dataset with set property. |
| 1204 | """ |
| 1205 | if self.handle is None: |
| 1206 | raise Exception("Cannot set %s before construct dataset" % field_name) |
| 1207 | if data is None: |
| 1208 | # set to None |
| 1209 | _safe_call(_LIB.LGBM_DatasetSetField( |
| 1210 | self.handle, |
| 1211 | c_str(field_name), |
| 1212 | None, |
| 1213 | ctypes.c_int(0), |
| 1214 | ctypes.c_int(FIELD_TYPE_MAPPER[field_name]))) |
| 1215 | return self |
| 1216 | dtype = np.float32 |
| 1217 | if field_name == 'group': |
| 1218 | dtype = np.int32 |
| 1219 | elif field_name == 'init_score': |
| 1220 | dtype = np.float64 |
| 1221 | data = list_to_1d_numpy(data, dtype, name=field_name) |
| 1222 | if data.dtype == np.float32 or data.dtype == np.float64: |
| 1223 | ptr_data, type_data, _ = c_float_array(data) |
| 1224 | elif data.dtype == np.int32: |
| 1225 | ptr_data, type_data, _ = c_int_array(data) |
| 1226 | else: |
| 1227 | raise TypeError("Expected np.float32/64 or np.int32, met type({})".format(data.dtype)) |
| 1228 | if type_data != FIELD_TYPE_MAPPER[field_name]: |
| 1229 | raise TypeError("Input type error for set_field") |
| 1230 | _safe_call(_LIB.LGBM_DatasetSetField( |
| 1231 | self.handle, |
| 1232 | c_str(field_name), |
| 1233 | ptr_data, |
| 1234 | ctypes.c_int(len(data)), |
| 1235 | ctypes.c_int(type_data))) |
| 1236 | return self |
| 1237 | |
| 1238 | def get_field(self, field_name): |
| 1239 | """Get property from the Dataset. |
no test coverage detected