input: Write a function to analyze the sentiment of a given text and categorize it into positive, negative, or neutral sentiments. The function should split the text into sentences, classify each sentence into either negative or positive using a NaiveBayesClassifier, and then determine the overall sentiment based on the counts of positive and negative sentences. If the given text is empty then return 'neutral'.
  assert analyze_sentiment("I love this product! It's amazing.") == 'positive'
  assert analyze_sentiment("I hate this product. It's terrible.") == 'negative'
  assert analyze_sentiment("This product is okay.") == 'neutral'
  assert analyze_sentiment("") == 'neutral'
  assert analyze_sentiment("This product is great. Why do they make it so expensive?") == 'positive'
output: def analyze_sentiment(text):
      if not text:
          return 'neutral'
      
      from nltk.tokenize import sent_tokenize
      from nltk.classify import NaiveBayesClassifier
      from nltk.corpus import subjectivity
      from nltk.sentiment import SentimentAnalyzer
      from nltk.sentiment.util import extract_unigram_feats
      
      sentences = sent_tokenize(text)
      if not sentences:
          return 'neutral'
      
      positive_count = 0
      negative_count = 0
      
      n_instances = 100
      subj_docs = [(sent, 'subj') for sent in subjectivity.sents(categories='subj')[:n_instances]]
      obj_docs = [(sent, 'obj') for sent in subjectivity.sents(categories='obj')[:n_instances]]
      
      train_data = subj_docs + obj_docs
      sentim_analyzer = SentimentAnalyzer()
      all_words_neg = sentim_analyzer.all_words([extract_unigram_feats(doc, unigrams) for doc in train_data])
      unigram_feats = sentim_analyzer.unigram_word_feats(all_words_neg, min_freq=4)
      sentim_analyzer.add_feat_extractor(extract_unigram_feats, unigrams=unigram_feats)
      training_set = sentim_analyzer.apply_features(train_data)
      trainer = NaiveBayesClassifier.train
      classifier = sentim_analyzer.train(trainer, training_set)
      
      for sentence in sentences:
          res = classifier.classify(extract_unigram_feats(sentence.split(), unigram_feats))
          if res == 'subj':
              positive_count += 1
          else:
              negative_count += 1
      
      if positive_count > negative_count:
          return 'positive'
      elif negative_count > positive_count:
          return 'negative'
      else:
          return 'neutral'