input: Write a function to perform linear regression and predict the value of a target variable for a given input array. Use the provided dataset to train the model. If the input array is invalid, return a message indicating so.
  assert linear_regression([1, 2, 3, 4, 5], [3, 5, 7, 9, 13], [7]) == [15.4]
  assert linear_regression([], [], [7]) == "Invalid input arrays"
  assert linear_regression([1, 2, 3], [5, 10, 15], [4]) == [20.0]
  assert linear_regression([1, 2], [2, 4], [3]) == [6.0]
  assert linear_regression([1], [1], [2]) == [2.0]
output: def linear_regression(x_train, y_train, x_predict):
      if len(x_train) != len(y_train) or len(x_train) < 2:
          return "Invalid input arrays"
      
      n = len(x_train)
      sum_x = sum(x_train)
      sum_y = sum(y_train)
      sum_xy = sum(x * y for x, y in zip(x_train, y_train))
      sum_x2 = sum(x ** 2 for x in x_train)
      
      slope = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x ** 2)
      intercept = (sum_y - slope * sum_x) / n
      
      predicted_values = [slope * x + intercept for x in x_predict]
      return predicted_values