<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fit(self, data, estimator=None, state_names=[], complete_samples_only=True, **kwargs):
 """ Estimates the CPD for each variable based on a given data set. Parameters data: pandas DataFrame object DataFrame object with column names identical to the variable names of the network. (If some values in the data are missing the data cells should be set to `numpy.NaN`. Note that pandas converts each column containing `numpy.NaN`s to dtype `float`.) estimator: Estimator class One of: - MaximumLikelihoodEstimator (default) - BayesianEstimator: In this case, pass 'prior_type' and either 'pseudo_counts' or 'equivalent_sample_size' as additional keyword arguments. See `BayesianEstimator.get_parameters()` for usage. state_names: dict (optional) A dict indicating, for each variable, the discrete set of states that the variable can take. If unspecified, the observed values in the data set are taken to be the only possible states. complete_samples_only: bool (default `True`) Specifies how to deal with missing data, if present. If set to `True` all rows that contain `np.Nan` somewhere are ignored. If `False` then, for each variable, every row where neither the variable nor its parents are `np.NaN` is used. Examples -------- [<TabularCPD representing P(A:2) at 0x7fb98a7d50f0>, <TabularCPD representing P(B:2) at 0x7fb98a7d5588>, <TabularCPD representing P(C:2 | A:2, B:2) at 0x7fb98a7b1f98>] """


        from pgmpy.estimators import MaximumLikelihoodEstimator, BayesianEstimator, BaseEstimator

        if estimator is None:
            estimator = MaximumLikelihoodEstimator
        else:
            if not issubclass(estimator, BaseEstimator):
                raise TypeError("Estimator object should be a valid pgmpy estimator.")

        _estimator = estimator(self, data, state_names=state_names,
                               complete_samples_only=complete_samples_only)
        cpds_list = _estimator.get_parameters(**kwargs)
        self.add_cpds(*cpds_list)