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 training, validation, and test data from a pre-compressed pickle file, augment the data with a bias term, train the logistic regression model using gradient descent, and return the accuracy of the model on the training, validation, and test datasets.
  
  
  assert LogisticRegression('./mnist_dataset/mnist.pkl.gz', 1000, 0.001) == (train_accuracy, valid_accuracy, test_accuracy)
  assert LogisticRegression('./mnist_dataset/mnist.pkl.gz', 500, 0.005) == (train_accuracy, valid_accuracy, test_accuracy)
  assert LogisticRegression('./mnist_dataset/mnist.pkl.gz', 2000, 0.0005) == (train_accuracy, valid_accuracy, test_accuracy)
  
output: 
  def LogisticRegression(file_path, num_iterations, learning_rate):
      import gzip
      import pickle
      import numpy as np
  
      with gzip.open(file_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
  
      X_train = np.hstack((np.ones((X_train.shape[0], 1)), X_train))
      X_valid = np.hstack((np.ones((X_valid.shape[0], 1)), X_valid))
      X_test = np.hstack((np.ones((X_test.shape[0], 1)), X_test))
  
      num_features = X_train.shape[1]
      num_classes = 10
  
      weights = np.zeros((num_features, num_classes))
  
      def softmax(z):
          exp_z = np.exp(z - np.max(z, axis=1, keepdims=True))
          return exp_z / np.sum(exp_z, axis=1, keepdims=True)
  
      def loss_gradient(X, y, weights):
          z = np.dot(X, weights)
          y_hat = softmax(z)
          y_one_hot = np.zeros_like(y_hat)
          y_one_hot[np.arange(len(y)), y] = 1
          gradient = np.dot(X.T, (y_hat - y_one_hot)) / len(y)
          return gradient
  
      for _ in range(num_iterations):
          gradient = loss_gradient(X_train, y_train, weights)
          weights -= learning_rate * gradient
  
      def predict(X, weights):
          return np.argmax(np.dot(X, weights), axis=1)
  
      train_preds = predict(X_train, weights)
      valid_preds = predict(X_valid, weights)
      test_preds = predict(X_test, weights)
  
      train_accuracy = np.mean(train_preds == y_train)
      valid_accuracy = np.mean(valid_preds == y_valid)
      test_accuracy = np.mean(test_preds == y_test)
  
      return train_accuracy, valid_accuracy, test_accuracy
  