MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / update

Method update

python-package/lightgbmmt/basic.py:1944–2007  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 13

trainFunction · 0.95
testMethod · 0.95
get_paramsMethod · 0.80
_callbackFunction · 0.80
_update_paramsMethod · 0.80
__setstate__Method · 0.80
reset_parameterMethod · 0.80
cvFunction · 0.80

Calls 8

reset_parameterMethod · 0.95
__inner_predictMethod · 0.95
__boostMethod · 0.95
typeEnum · 0.85
LightGBMErrorClass · 0.85
_safe_callFunction · 0.85
formatMethod · 0.80
constructMethod · 0.80

Tested by 6

testMethod · 0.76
test_plot_metricsMethod · 0.64