code: def classifier_factory(clf):
      
      required_methods = ['fit', 'score', 'predict']
  
      for method in required_methods:
          if not hasattr(clf, method):
              raise TypeError('"{}" is not in clf. Did you pass a '
                              'classifier instance?'.format(method))
  
      optional_methods = ['predict_proba']
  
      for method in optional_methods:
          if not hasattr(clf, method):
              warnings.warn('{} not in clf. Some plots may '
                            'not be possible to generate.'.format(method))
  
      additional_methods = {
          'plot_learning_curve': plot_learning_curve,
          'plot_confusion_matrix': plot_confusion_matrix_with_cv,
          'plot_roc_curve': plot_roc_curve_with_cv,
          'plot_ks_statistic': plot_ks_statistic_with_cv,
          'plot_precision_recall_curve': plot_precision_recall_curve_with_cv,
          'plot_feature_importances': plot_feature_importances
      }
  
      for key, fn in six.iteritems(additional_methods):
          if hasattr(clf, key):
              warnings.warn('"{}" method already in clf. '
                            'Overriding anyway. This may '
                            'result in unintended behavior.'.format(key))
          setattr(clf, key, types.MethodType(fn, clf))
      return clf
docs: Embeds scikit-plot instance methods in an sklearn classifier.
  
      Args:
          clf: Scikit-learn classifier instance
  
      Returns:
          The same scikit-learn classifier instance passed in **clf**
          with embedded scikit-plot instance methods.
  
      Raises:
          ValueError: If **clf** does not contain the instance methods
              necessary for scikit-plot instance methods.