Update Booster for one iteration. Parameters ---------- train_set : Dataset or None, optional (default=None) Training data. If None, last training data is used. fobj : callable or None, optional (default=None) Customized objective
(self, train_set=None, fobj=None, ep = None)
| 1942 | return self |
| 1943 | |
| 1944 | def update(self, train_set=None, fobj=None, ep = None): |
| 1945 | """Update Booster for one iteration. |
| 1946 | |
| 1947 | Parameters |
| 1948 | ---------- |
| 1949 | train_set : Dataset or None, optional (default=None) |
| 1950 | Training data. |
| 1951 | If None, last training data is used. |
| 1952 | fobj : callable or None, optional (default=None) |
| 1953 | Customized objective function. |
| 1954 | Should accept two parameters: preds, train_data, |
| 1955 | and return (grad, hess). |
| 1956 | |
| 1957 | preds : list or numpy 1-D array |
| 1958 | The predicted values. |
| 1959 | train_data : Dataset |
| 1960 | The training dataset. |
| 1961 | grad : list or numpy 1-D array |
| 1962 | The value of the first order derivative (gradient) for each sample point. |
| 1963 | hess : list or numpy 1-D array |
| 1964 | The value of the second order derivative (Hessian) for each sample point. |
| 1965 | |
| 1966 | For multi-class task, the preds is group by class_id first, then group by row_id. |
| 1967 | If you want to get i-th row preds in j-th class, the access way is score[j * num_data + i] |
| 1968 | and you should group grad and hess in this way as well. |
| 1969 | |
| 1970 | Returns |
| 1971 | ------- |
| 1972 | is_finished : bool |
| 1973 | Whether the update was successfully finished. |
| 1974 | """ |
| 1975 | # need reset training data |
| 1976 | if train_set is not None and train_set is not self.train_set: |
| 1977 | if not isinstance(train_set, Dataset): |
| 1978 | raise TypeError('Training data should be Dataset instance, met {}' |
| 1979 | .format(type(train_set).__name__)) |
| 1980 | if train_set._predictor is not self.__init_predictor: |
| 1981 | raise LightGBMError("Replace training data failed, " |
| 1982 | "you should use same predictor for these data") |
| 1983 | self.train_set = train_set |
| 1984 | _safe_call(_LIB.LGBM_BoosterResetTrainingData( |
| 1985 | self.handle, |
| 1986 | self.train_set.construct().handle)) |
| 1987 | self.__inner_predict_buffer[0] = None |
| 1988 | is_finished = ctypes.c_int(0) |
| 1989 | if fobj is None: |
| 1990 | if self.__set_objective_to_none: |
| 1991 | raise LightGBMError('Cannot update due to null objective function.') |
| 1992 | _safe_call(_LIB.LGBM_BoosterUpdateOneIter( |
| 1993 | self.handle, |
| 1994 | ctypes.byref(is_finished))) |
| 1995 | self.__is_predicted_cur_iter = [False for _ in range_(self.__num_dataset)] |
| 1996 | return is_finished.value == 1 |
| 1997 | else: |
| 1998 | if not self.__set_objective_to_none: |
| 1999 | self.reset_parameter({"objective": "none"}).__set_objective_to_none = True |
| 2000 | |
| 2001 | if self.num_labels__ > 1: |