input: Write a function to implement a logistic regression classifier in Python to classify handwritten digits from the MNIST dataset. The function should load the MNIST dataset, prepare the training, validation, and test data, and then train the logistic regression model using gradient descent. The function should return the trained weights and print the accuracy on the training, validation, and test sets.
  assert LogisticRegression('./mnist_dataset/mnist.pkl.gz', 1000, 0.001) == (weights, 0.9, 0.85, 0.87)
output: import numpy as np
  import gzip
  import pickle
  from sklearn.linear_model import LogisticRegression
  from sklearn.metrics import accuracy_score
  
  def LogisticRegression(dataset_path, max_iter, learning_rate):
      with gzip.open(dataset_path, 'rb') as f:
          train_set, valid_set, test_set = pickle.load(f, encoding='latin1')
      
      X_train, y_train = train_set
      X_valid, y_valid = valid_set
      X_test, y_test = test_set
      
      model = LogisticRegression(max_iter=max_iter, solver='sag', multi_class='multinomial', C=1/learning_rate)
      model.fit(X_train, y_train)
      
      train_accuracy = accuracy_score(y_train, model.predict(X_train))
      valid_accuracy = accuracy_score(y_valid, model.predict(X_valid))
      test_accuracy = accuracy_score(y_test, model.predict(X_test))
      
      print(f"Training Accuracy: {train_accuracy:.2f}")
      print(f"Validation Accuracy: {valid_accuracy:.2f}")
      print(f"Test Accuracy: {test_accuracy:.2f}")
      
      return model.coef_