class_docstr: Logistic regression estimator.
  
  .. versionadded:: 3.5.0
  
  Examples
  --------
  >>> from pyspark.ml.connect.classification import LogisticRegression, LogisticRegressionModel
  >>> lor = LogisticRegression(maxIter=20, learningRate=0.01)
  >>> dataset = spark.createDataFrame([
  ...     ([1.0, 2.0], 1),
  ...     ([2.0, -1.0], 1),
  ...     ([-3.0, -2.0], 0),
  ...     ([-1.0, -2.0], 0),
  ... ], schema=['features', 'label'])
  >>> lor_model = lor.fit(dataset)
  >>> transformed_dataset = lor_model.transform(dataset)
  >>> transformed_dataset.show()
  +------------+-----+----------+--------------------+
  |    features|label|prediction|         probability|
  +------------+-----+----------+--------------------+
  |  [1.0, 2.0]|    1|         1|[0.02423273026943...|
  | [2.0, -1.0]|    1|         1|[0.09334788471460...|
  |[-3.0, -2.0]|    0|         0|[0.99808156490325...|
  |[-1.0, -2.0]|    0|         0|[0.96210002899169...|
  +------------+-----+----------+--------------------+
  >>> lor_model.saveToLocal("/tmp/lor_model")
  >>> LogisticRegressionModel.loadFromLocal("/tmp/lor_model")
  LogisticRegression_...
class_docstr_tok: ["Logistic","regression","estimator",".","..","versionadded",":",":","3.5.0","Examples","--","--","--","--",">",">",">","from","pyspark.ml.connect.classification","import","LogisticRegression",",","LogisticRegressionModel",">",">",">","lor","=","LogisticRegression","(","maxIter=20",",","learningRate=0.01",")",">",">",">","dataset","=","spark.createDataFrame","(","[","...","(","[","1.0",",","2.0","]",",","1",")",",","...","(","[","2.0",",","-1.0","]",",","1",")",",","...","(","[","-3.0",",","-2.0","]",",","0",")",",","...","(","[","-1.0",",","-2.0","]",",","0",")",",","...","]",",","schema=","[","'features","'",",","'label","'","]",")",">",">",">","lor_model","=","lor.fit","(","dataset",")",">",">",">","transformed_dataset","=","lor_model.transform","(","dataset",")",">",">",">","transformed_dataset.show","(",")","+","--","--","--","--","--","--","+","--","--","-+","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","--","+","|","features|label|prediction|","probability|","+","--","--","--","--","--","--","+","--","--","-+","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","--","+","|","[","1.0",",","2.0","]","|","1|","1|","[","0.02423273026943","...","|","|","[","2.0",",","-1.0","]","|","1|","1|","[","0.09334788471460","...","|","|","[","-3.0",",","-2.0","]","|","0|","0|","[","0.99808156490325","...","|","|","[","-1.0",",","-2.0","]","|","0|","0|","[","0.96210002899169","...","|","+","--","--","--","--","--","--","+","--","--","-+","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","--","+",">",">",">","lor_model.saveToLocal","(","``","\/tmp\/lor_model","''",")",">",">",">","LogisticRegressionModel.loadFromLocal","(","``","\/tmp\/lor_model","''",")","LogisticRegression_","..."]
code: def _fit(
      self, dataset: Union[DataFrame, pd.DataFrame]
  ) -> "LogisticRegressionModel":
      if isinstance(dataset, pd.DataFrame):
          # TODO: support pandas dataframe fitting
          raise NotImplementedError(
              "Fitting pandas dataframe is not supported yet."
          )
  
      num_train_workers = self.getNumTrainWorkers()
      batch_size = self.getBatchSize()
  
      # We don't need to persist the dataset because the shuffling result from the repartition
      # has been cached.
      dataset = dataset.select(
          self.getFeaturesCol(), self.getLabelCol()
      ).repartition(num_train_workers)
  
      num_rows, num_features, classes = dataset.select(
          sf.count(sf.lit(1)),
          sf.first(sf.array_size(self.getFeaturesCol())),
          sf.collect_set(self.getLabelCol()),
      ).head()  # type: ignore[misc]
  
      num_classes = len(classes)
      if num_classes < 2:
          raise ValueError(
              "Training dataset distinct labels must >= 2."
          )
      if any(c not in range(0, num_classes) for c in classes):
          raise ValueError(
              "Training labels must be integers in [0, numClasses)."
          )
  
      num_batches_per_worker = math.ceil(
          num_rows / num_train_workers / batch_size
      )
      num_samples_per_worker = num_batches_per_worker * batch_size
  
      # TODO: support GPU.
      distributor = TorchDistributor(
          local_mode=False,
          use_gpu=False,
          num_processes=num_train_workers,
      )
      model_state_dict = distributor._train_on_dataframe(
          _train_logistic_regression_model_worker_fn,
          dataset,
          num_samples_per_worker=num_samples_per_worker,
          num_features=num_features,
          batch_size=batch_size,
          max_iter=self.getMaxIter(),
          num_classes=num_classes,
          learning_rate=self.getLearningRate(),
          momentum=self.getMomentum(),
          fit_intercept=self.getFitIntercept(),
          seed=self.getSeed(),
      )
  
      dataset.unpersist()
  
      torch_model = torch_nn.Linear(
          num_features,
          num_classes,
          bias=self.getFitIntercept(),
          dtype=torch.float32,
      )
      torch_model.load_state_dict(model_state_dict)
  
      lor_model = LogisticRegressionModel(
          torch_model,
          num_features=num_features,
          num_classes=num_classes,
      )
      lor_model._resetUid(self.uid)
      return self._copyValues(lor_model)
  
imports: from typing import Any, Dict, Union, List, Tuple, Callable, Optional
  import math
  import torch
  import torch.nn
  import numpy
  import pandas
  from pyspark import keyword_only
  from pyspark.ml.connect.base import _PredictorParams
  from pyspark.ml.param.shared import HasProbabilityCol
  from pyspark.sql import DataFrame
  from pyspark.ml.common import inherit_doc
  from pyspark.ml.torch.distributor import TorchDistributor
  from pyspark.ml.param.shared import HasMaxIter, HasFitIntercept, HasTol, HasWeightCol, HasSeed, HasNumTrainWorkers, HasBatchSize, HasLearningRate, HasMomentum
  from pyspark.ml.connect.base import Predictor, PredictionModel
  from pyspark.ml.connect.io_utils import ParamsReadWrite, CoreModelReadWrite
  from pyspark.sql import functions
label_desc: Use image node_id 2 for calling the LogisticRegression obj's underlying member method code with example usage: obj._fit(dataset) and returns: self