Get property from the Dataset. Parameters ---------- field_name : string The field name of the information. Returns ------- info : numpy array A numpy array with information from the Dataset.
(self, field_name)
| 1236 | return self |
| 1237 | |
| 1238 | def get_field(self, field_name): |
| 1239 | """Get property from the Dataset. |
| 1240 | |
| 1241 | Parameters |
| 1242 | ---------- |
| 1243 | field_name : string |
| 1244 | The field name of the information. |
| 1245 | |
| 1246 | Returns |
| 1247 | ------- |
| 1248 | info : numpy array |
| 1249 | A numpy array with information from the Dataset. |
| 1250 | """ |
| 1251 | if self.handle is None: |
| 1252 | raise Exception("Cannot get %s before construct Dataset" % field_name) |
| 1253 | tmp_out_len = ctypes.c_int() |
| 1254 | out_type = ctypes.c_int() |
| 1255 | ret = ctypes.POINTER(ctypes.c_void_p)() |
| 1256 | _safe_call(_LIB.LGBM_DatasetGetField( |
| 1257 | self.handle, |
| 1258 | c_str(field_name), |
| 1259 | ctypes.byref(tmp_out_len), |
| 1260 | ctypes.byref(ret), |
| 1261 | ctypes.byref(out_type))) |
| 1262 | if out_type.value != FIELD_TYPE_MAPPER[field_name]: |
| 1263 | raise TypeError("Return type error for get_field") |
| 1264 | if tmp_out_len.value == 0: |
| 1265 | return None |
| 1266 | if out_type.value == C_API_DTYPE_INT32: |
| 1267 | return cint32_array_to_numpy(ctypes.cast(ret, ctypes.POINTER(ctypes.c_int32)), tmp_out_len.value) |
| 1268 | elif out_type.value == C_API_DTYPE_FLOAT32: |
| 1269 | return cfloat32_array_to_numpy(ctypes.cast(ret, ctypes.POINTER(ctypes.c_float)), tmp_out_len.value) |
| 1270 | elif out_type.value == C_API_DTYPE_FLOAT64: |
| 1271 | return cfloat64_array_to_numpy(ctypes.cast(ret, ctypes.POINTER(ctypes.c_double)), tmp_out_len.value) |
| 1272 | elif out_type.value == C_API_DTYPE_INT8: |
| 1273 | return cint8_array_to_numpy(ctypes.cast(ret, ctypes.POINTER(ctypes.c_int8)), tmp_out_len.value) |
| 1274 | else: |
| 1275 | raise TypeError("Unknown type") |
| 1276 | |
| 1277 | def set_categorical_feature(self, categorical_feature): |
| 1278 | """Set categorical features. |