|
| 1 | +from sklearn.naive_bayes import ComplementNB as Op |
| 2 | + |
| 3 | +from lale.docstrings import set_docstrings |
| 4 | +from lale.operators import make_operator |
| 5 | + |
| 6 | +_hyperparams_schema = { |
| 7 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 8 | + "description": "The Complement Naive Bayes classifier described in Rennie et al. (2003).", |
| 9 | + "allOf": [ |
| 10 | + { |
| 11 | + "type": "object", |
| 12 | + "required": ["alpha", "fit_prior", "class_prior", "norm"], |
| 13 | + "relevantToOptimizer": [], |
| 14 | + "additionalProperties": False, |
| 15 | + "properties": { |
| 16 | + "alpha": { |
| 17 | + "type": "number", |
| 18 | + "default": 1.0, |
| 19 | + "description": "Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).", |
| 20 | + }, |
| 21 | + "fit_prior": { |
| 22 | + "type": "boolean", |
| 23 | + "default": True, |
| 24 | + "description": "Only used in edge case with a single class in the training set.", |
| 25 | + }, |
| 26 | + "class_prior": { |
| 27 | + "anyOf": [ |
| 28 | + {"type": "array", "items": {"type": "number"}}, |
| 29 | + {"enum": [None]}, |
| 30 | + ], |
| 31 | + "default": None, |
| 32 | + "description": "Prior probabilities of the classes. Not used.", |
| 33 | + }, |
| 34 | + "norm": { |
| 35 | + "type": "boolean", |
| 36 | + "default": False, |
| 37 | + "description": "Whether or not a second normalization of the weights is performed", |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + ], |
| 42 | +} |
| 43 | +_input_fit_schema = { |
| 44 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 45 | + "description": "Fit Naive Bayes classifier according to X, y", |
| 46 | + "type": "object", |
| 47 | + "required": ["X", "y"], |
| 48 | + "properties": { |
| 49 | + "X": { |
| 50 | + "type": "array", |
| 51 | + "items": {"type": "array", "items": {"type": "number"}}, |
| 52 | + "description": "Training vectors, where n_samples is the number of samples and n_features is the number of features.", |
| 53 | + }, |
| 54 | + "y": { |
| 55 | + "type": "array", |
| 56 | + "items": {"type": "number"}, |
| 57 | + "description": "Target values.", |
| 58 | + }, |
| 59 | + "sample_weight": { |
| 60 | + "anyOf": [{"type": "array", "items": {"type": "number"}}, {"enum": [None]}], |
| 61 | + "default": None, |
| 62 | + "description": "Weights applied to individual samples (1", |
| 63 | + }, |
| 64 | + }, |
| 65 | +} |
| 66 | +_input_predict_schema = { |
| 67 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 68 | + "description": "Perform classification on an array of test vectors X.", |
| 69 | + "type": "object", |
| 70 | + "required": ["X"], |
| 71 | + "properties": { |
| 72 | + "X": {"type": "array", "items": {"type": "array", "items": {"type": "number"}}} |
| 73 | + }, |
| 74 | +} |
| 75 | +_output_predict_schema = { |
| 76 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 77 | + "description": "Predicted target values for X", |
| 78 | + "type": "array", |
| 79 | + "items": {"type": "number"}, |
| 80 | +} |
| 81 | +_input_predict_proba_schema = { |
| 82 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 83 | + "description": "Return probability estimates for the test vector X.", |
| 84 | + "type": "object", |
| 85 | + "required": ["X"], |
| 86 | + "properties": { |
| 87 | + "X": {"type": "array", "items": {"type": "array", "items": {"type": "number"}}} |
| 88 | + }, |
| 89 | +} |
| 90 | +_output_predict_proba_schema = { |
| 91 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 92 | + "description": "Returns the probability of the samples for each class in the model", |
| 93 | + "type": "array", |
| 94 | + "items": {"type": "array", "items": {"type": "number"}}, |
| 95 | +} |
| 96 | +_combined_schemas = { |
| 97 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 98 | + "description": """`Complement Naive Bayes`_ classifier described in Rennie et al. (2003). |
| 99 | +
|
| 100 | +.. _`Complement Naive Bayes`: https://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.ComplementNB |
| 101 | + """, |
| 102 | + "documentation_url": "https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.complement_nb.html", |
| 103 | + "import_from": "sklearn.naive_bayes", |
| 104 | + "type": "object", |
| 105 | + "tags": {"pre": [], "op": ["estimator"], "post": []}, |
| 106 | + "properties": { |
| 107 | + "hyperparams": _hyperparams_schema, |
| 108 | + "input_fit": _input_fit_schema, |
| 109 | + "input_predict": _input_predict_schema, |
| 110 | + "output_predict": _output_predict_schema, |
| 111 | + "input_predict_proba": _input_predict_proba_schema, |
| 112 | + "output_predict_proba": _output_predict_proba_schema, |
| 113 | + }, |
| 114 | +} |
| 115 | +ComplementNB = make_operator(Op, _combined_schemas) |
| 116 | + |
| 117 | +set_docstrings(ComplementNB) |
0 commit comments