Source file feature_extraction.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
let () = Wrap_utils.init ();;
let ns = Py.import "sklearn.feature_extraction"

let get_py name = Py.Module.get ns name
module DictVectorizer = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create ?dtype ?separator ?sparse ?sort () =
   Py.Module.get_function_with_keywords ns "DictVectorizer"
     [||]
     (Wrap_utils.keyword_args [("dtype", dtype); ("separator", separator); ("sparse", sparse); ("sort", sort)])

let fit ?y ~x self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x ))])

let fit_transform ?y ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let get_feature_names self =
   Py.Module.get_function_with_keywords self "get_feature_names"
     [||]
     []

let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let inverse_transform ?dict_type ~x self =
   Py.Module.get_function_with_keywords self "inverse_transform"
     [||]
     (Wrap_utils.keyword_args [("dict_type", dict_type); ("X", Some(x |> Arr.to_pyobject))])

let restrict ?indices ~support self =
   Py.Module.get_function_with_keywords self "restrict"
     [||]
     (Wrap_utils.keyword_args [("indices", indices); ("support", Some(support |> Arr.to_pyobject))])

let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~x self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject

let vocabulary_opt self =
  match Py.Object.get_attr_string self "vocabulary_" with
  | None -> failwith "attribute vocabulary_ not found"
  | Some x -> if Py.is_none x then None else Some (Dict.of_pyobject x)

let vocabulary_ self = match vocabulary_opt self with
  | None -> raise Not_found
  | Some x -> x

let feature_names_opt self =
  match Py.Object.get_attr_string self "feature_names_" with
  | None -> failwith "attribute feature_names_ not found"
  | Some x -> if Py.is_none x then None else Some (Arr.of_pyobject x)

let feature_names_ self = match feature_names_opt self with
  | None -> raise Not_found
  | Some x -> x
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module FeatureHasher = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create ?n_features ?input_type ?dtype ?alternate_sign () =
   Py.Module.get_function_with_keywords ns "FeatureHasher"
     [||]
     (Wrap_utils.keyword_args [("n_features", Wrap_utils.Option.map n_features Py.Int.of_int); ("input_type", input_type); ("dtype", dtype); ("alternate_sign", alternate_sign)])

let fit ?x ?y self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("X", Wrap_utils.Option.map x Arr.to_pyobject); ("y", y)])

let fit_transform ?y ?fit_params ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (List.rev_append (Wrap_utils.keyword_args [("y", Wrap_utils.Option.map y Arr.to_pyobject); ("X", Some(x |> Arr.to_pyobject))]) (match fit_params with None -> [] | Some x -> x))
     |> Arr.of_pyobject
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~raw_X self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("raw_X", Some(raw_X ))])
     |> Arr.of_pyobject
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
let grid_to_graph ?n_z ?mask ?return_as ?dtype ~n_x ~n_y () =
   Py.Module.get_function_with_keywords ns "grid_to_graph"
     [||]
     (Wrap_utils.keyword_args [("n_z", n_z); ("mask", mask); ("return_as", return_as); ("dtype", dtype); ("n_x", Some(n_x |> Py.Int.of_int)); ("n_y", Some(n_y ))])

module Image = struct
let () = Wrap_utils.init ();;
let ns = Py.import "sklearn.feature_extraction.image"

let get_py name = Py.Module.get ns name
module BaseEstimator = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create () =
   Py.Module.get_function_with_keywords ns "BaseEstimator"
     [||]
     []

let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module PatchExtractor = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
                  let create ?patch_size ?max_patches ?random_state () =
                     Py.Module.get_function_with_keywords ns "PatchExtractor"
                       [||]
                       (Wrap_utils.keyword_args [("patch_size", patch_size); ("max_patches", Wrap_utils.Option.map max_patches (function
| `I x -> Py.Int.of_int x
| `F x -> Py.Float.of_float x
)); ("random_state", Wrap_utils.Option.map random_state Py.Int.of_int)])

let fit ?y ~x self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Arr.to_pyobject))])

let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~x self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
let as_strided ?shape ?strides ?subok ?writeable ~x () =
   Py.Module.get_function_with_keywords ns "as_strided"
     [||]
     (Wrap_utils.keyword_args [("shape", Wrap_utils.Option.map shape (fun ml -> Py.List.of_list_map Py.Int.of_int ml)); ("strides", strides); ("subok", subok); ("writeable", Wrap_utils.Option.map writeable Py.Bool.of_bool); ("x", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject
                  let check_array ?accept_sparse ?accept_large_sparse ?dtype ?order ?copy ?force_all_finite ?ensure_2d ?allow_nd ?ensure_min_samples ?ensure_min_features ?warn_on_dtype ?estimator ~array () =
                     Py.Module.get_function_with_keywords ns "check_array"
                       [||]
                       (Wrap_utils.keyword_args [("accept_sparse", Wrap_utils.Option.map accept_sparse (function
| `S x -> Py.String.of_string x
| `Bool x -> Py.Bool.of_bool x
| `StringList x -> (Py.List.of_list_map Py.String.of_string) x
)); ("accept_large_sparse", Wrap_utils.Option.map accept_large_sparse Py.Bool.of_bool); ("dtype", Wrap_utils.Option.map dtype (function
| `S x -> Py.String.of_string x
| `Dtype x -> Wrap_utils.id x
| `TypeList x -> Wrap_utils.id x
| `None -> Py.none
)); ("order", Wrap_utils.Option.map order (function
| `F -> Py.String.of_string "F"
| `C -> Py.String.of_string "C"
)); ("copy", Wrap_utils.Option.map copy Py.Bool.of_bool); ("force_all_finite", Wrap_utils.Option.map force_all_finite (function
| `Bool x -> Py.Bool.of_bool x
| `Allow_nan -> Py.String.of_string "allow-nan"
)); ("ensure_2d", Wrap_utils.Option.map ensure_2d Py.Bool.of_bool); ("allow_nd", Wrap_utils.Option.map allow_nd Py.Bool.of_bool); ("ensure_min_samples", Wrap_utils.Option.map ensure_min_samples Py.Int.of_int); ("ensure_min_features", Wrap_utils.Option.map ensure_min_features Py.Int.of_int); ("warn_on_dtype", Wrap_utils.Option.map warn_on_dtype Py.Bool.of_bool); ("estimator", Wrap_utils.Option.map estimator (function
| `S x -> Py.String.of_string x
| `Estimator x -> Wrap_utils.id x
)); ("array", Some(array ))])

                  let check_random_state ~seed () =
                     Py.Module.get_function_with_keywords ns "check_random_state"
                       [||]
                       (Wrap_utils.keyword_args [("seed", Some(seed |> (function
| `I x -> Py.Int.of_int x
| `RandomState x -> Wrap_utils.id x
| `None -> Py.none
)))])

module Deprecated = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create ?extra () =
   Py.Module.get_function_with_keywords ns "deprecated"
     [||]
     (Wrap_utils.keyword_args [("extra", Wrap_utils.Option.map extra Py.String.of_string)])

let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
                  let extract_patches ?patch_shape ?extraction_step ~arr () =
                     Py.Module.get_function_with_keywords ns "extract_patches"
                       [||]
                       (Wrap_utils.keyword_args [("patch_shape", Wrap_utils.Option.map patch_shape (function
| `I x -> Py.Int.of_int x
| `Tuple x -> Wrap_utils.id x
)); ("extraction_step", Wrap_utils.Option.map extraction_step (function
| `I x -> Py.Int.of_int x
| `Tuple x -> Wrap_utils.id x
)); ("arr", Some(arr |> Arr.to_pyobject))])

                  let extract_patches_2d ?max_patches ?random_state ~image ~patch_size () =
                     Py.Module.get_function_with_keywords ns "extract_patches_2d"
                       [||]
                       (Wrap_utils.keyword_args [("max_patches", Wrap_utils.Option.map max_patches (function
| `I x -> Py.Int.of_int x
| `F x -> Py.Float.of_float x
)); ("random_state", Wrap_utils.Option.map random_state Py.Int.of_int); ("image", Some(image |> (function
| `Arr x -> Arr.to_pyobject x
| `Or x -> Wrap_utils.id x
))); ("patch_size", Some(patch_size ))])

let grid_to_graph ?n_z ?mask ?return_as ?dtype ~n_x ~n_y () =
   Py.Module.get_function_with_keywords ns "grid_to_graph"
     [||]
     (Wrap_utils.keyword_args [("n_z", n_z); ("mask", mask); ("return_as", return_as); ("dtype", dtype); ("n_x", Some(n_x |> Py.Int.of_int)); ("n_y", Some(n_y ))])

                  let img_to_graph ?mask ?return_as ?dtype ~img () =
                     Py.Module.get_function_with_keywords ns "img_to_graph"
                       [||]
                       (Wrap_utils.keyword_args [("mask", mask); ("return_as", return_as); ("dtype", dtype); ("img", Some(img |> (function
| `Arr x -> Arr.to_pyobject x
| `PyObject x -> Wrap_utils.id x
)))])

                  let reconstruct_from_patches_2d ~patches ~image_size () =
                     Py.Module.get_function_with_keywords ns "reconstruct_from_patches_2d"
                       [||]
                       (Wrap_utils.keyword_args [("patches", Some(patches |> (function
| `Arr x -> Arr.to_pyobject x
| `Or x -> Wrap_utils.id x
))); ("image_size", Some(image_size ))])


end
                  let img_to_graph ?mask ?return_as ?dtype ~img () =
                     Py.Module.get_function_with_keywords ns "img_to_graph"
                       [||]
                       (Wrap_utils.keyword_args [("mask", mask); ("return_as", return_as); ("dtype", dtype); ("img", Some(img |> (function
| `Arr x -> Arr.to_pyobject x
| `PyObject x -> Wrap_utils.id x
)))])

module Text = struct
let () = Wrap_utils.init ();;
let ns = Py.import "sklearn.feature_extraction.text"

let get_py name = Py.Module.get ns name
module BaseEstimator = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create () =
   Py.Module.get_function_with_keywords ns "BaseEstimator"
     [||]
     []

let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module CountVectorizer = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
                  let create ?input ?encoding ?decode_error ?strip_accents ?lowercase ?preprocessor ?tokenizer ?stop_words ?token_pattern ?ngram_range ?analyzer ?max_df ?min_df ?max_features ?vocabulary ?binary ?dtype () =
                     Py.Module.get_function_with_keywords ns "CountVectorizer"
                       [||]
                       (Wrap_utils.keyword_args [("input", Wrap_utils.Option.map input (function
| `Filename -> Py.String.of_string "filename"
| `File -> Py.String.of_string "file"
| `Content -> Py.String.of_string "content"
)); ("encoding", Wrap_utils.Option.map encoding (function
| `S x -> Py.String.of_string x
| `T_utf_8_by x -> Wrap_utils.id x
)); ("decode_error", Wrap_utils.Option.map decode_error (function
| `Strict -> Py.String.of_string "strict"
| `Ignore -> Py.String.of_string "ignore"
| `Replace -> Py.String.of_string "replace"
)); ("strip_accents", Wrap_utils.Option.map strip_accents (function
| `Ascii -> Py.String.of_string "ascii"
| `Unicode -> Py.String.of_string "unicode"
)); ("lowercase", Wrap_utils.Option.map lowercase Py.Bool.of_bool); ("preprocessor", preprocessor); ("tokenizer", tokenizer); ("stop_words", Wrap_utils.Option.map stop_words (function
| `English -> Py.String.of_string "english"
| `Arr x -> Arr.to_pyobject x
)); ("token_pattern", Wrap_utils.Option.map token_pattern Py.String.of_string); ("ngram_range", ngram_range); ("analyzer", Wrap_utils.Option.map analyzer (function
| `S x -> Py.String.of_string x
| `Word -> Py.String.of_string "word"
| `Char -> Py.String.of_string "char"
| `Char_wb -> Py.String.of_string "char_wb"
| `Callable x -> Wrap_utils.id x
)); ("max_df", Wrap_utils.Option.map max_df (function
| `F x -> Py.Float.of_float x
| `I x -> Py.Int.of_int x
)); ("min_df", Wrap_utils.Option.map min_df (function
| `F x -> Py.Float.of_float x
| `I x -> Py.Int.of_int x
)); ("max_features", Wrap_utils.Option.map max_features Py.Int.of_int); ("vocabulary", Wrap_utils.Option.map vocabulary (function
| `Mapping x -> Wrap_utils.id x
| `Arr x -> Arr.to_pyobject x
)); ("binary", Wrap_utils.Option.map binary Py.Bool.of_bool); ("dtype", dtype)])

let build_analyzer self =
   Py.Module.get_function_with_keywords self "build_analyzer"
     [||]
     []

let build_preprocessor self =
   Py.Module.get_function_with_keywords self "build_preprocessor"
     [||]
     []

let build_tokenizer self =
   Py.Module.get_function_with_keywords self "build_tokenizer"
     [||]
     []

let decode ~doc self =
   Py.Module.get_function_with_keywords self "decode"
     [||]
     (Wrap_utils.keyword_args [("doc", Some(doc |> Py.String.of_string))])
     |> Py.String.to_string
let fit ?y ~raw_documents self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("raw_documents", Some(raw_documents |> Arr.to_pyobject))])

let fit_transform ?y ~raw_documents self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("raw_documents", Some(raw_documents |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let get_feature_names self =
   Py.Module.get_function_with_keywords self "get_feature_names"
     [||]
     []
     |> (Py.List.to_list_map Py.String.to_string)
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let get_stop_words self =
   Py.Module.get_function_with_keywords self "get_stop_words"
     [||]
     []

let inverse_transform ~x self =
   Py.Module.get_function_with_keywords self "inverse_transform"
     [||]
     (Wrap_utils.keyword_args [("X", Some(x |> Arr.to_pyobject))])

let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~raw_documents self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("raw_documents", Some(raw_documents |> Arr.to_pyobject))])
     |> Arr.of_pyobject

let vocabulary_opt self =
  match Py.Object.get_attr_string self "vocabulary_" with
  | None -> failwith "attribute vocabulary_ not found"
  | Some x -> if Py.is_none x then None else Some (Dict.of_pyobject x)

let vocabulary_ self = match vocabulary_opt self with
  | None -> raise Not_found
  | Some x -> x

let fixed_vocabulary_opt self =
  match Py.Object.get_attr_string self "fixed_vocabulary_" with
  | None -> failwith "attribute fixed_vocabulary_ not found"
  | Some x -> if Py.is_none x then None else Some (Py.Bool.to_bool x)

let fixed_vocabulary_ self = match fixed_vocabulary_opt self with
  | None -> raise Not_found
  | Some x -> x

let stop_words_opt self =
  match Py.Object.get_attr_string self "stop_words_" with
  | None -> failwith "attribute stop_words_ not found"
  | Some x -> if Py.is_none x then None else Some (Wrap_utils.id x)

let stop_words_ self = match stop_words_opt self with
  | None -> raise Not_found
  | Some x -> x
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module FeatureHasher = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create ?n_features ?input_type ?dtype ?alternate_sign () =
   Py.Module.get_function_with_keywords ns "FeatureHasher"
     [||]
     (Wrap_utils.keyword_args [("n_features", Wrap_utils.Option.map n_features Py.Int.of_int); ("input_type", input_type); ("dtype", dtype); ("alternate_sign", alternate_sign)])

let fit ?x ?y self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("X", Wrap_utils.Option.map x Arr.to_pyobject); ("y", y)])

let fit_transform ?y ?fit_params ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (List.rev_append (Wrap_utils.keyword_args [("y", Wrap_utils.Option.map y Arr.to_pyobject); ("X", Some(x |> Arr.to_pyobject))]) (match fit_params with None -> [] | Some x -> x))
     |> Arr.of_pyobject
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~raw_X self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("raw_X", Some(raw_X ))])
     |> Arr.of_pyobject
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module HashingVectorizer = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
                  let create ?input ?encoding ?decode_error ?strip_accents ?lowercase ?preprocessor ?tokenizer ?stop_words ?token_pattern ?ngram_range ?analyzer ?n_features ?binary ?norm ?alternate_sign ?dtype () =
                     Py.Module.get_function_with_keywords ns "HashingVectorizer"
                       [||]
                       (Wrap_utils.keyword_args [("input", Wrap_utils.Option.map input (function
| `Filename -> Py.String.of_string "filename"
| `File -> Py.String.of_string "file"
| `Content -> Py.String.of_string "content"
)); ("encoding", Wrap_utils.Option.map encoding Py.String.of_string); ("decode_error", Wrap_utils.Option.map decode_error (function
| `Strict -> Py.String.of_string "strict"
| `Ignore -> Py.String.of_string "ignore"
| `Replace -> Py.String.of_string "replace"
)); ("strip_accents", Wrap_utils.Option.map strip_accents (function
| `Ascii -> Py.String.of_string "ascii"
| `Unicode -> Py.String.of_string "unicode"
)); ("lowercase", Wrap_utils.Option.map lowercase Py.Bool.of_bool); ("preprocessor", preprocessor); ("tokenizer", tokenizer); ("stop_words", Wrap_utils.Option.map stop_words (function
| `English -> Py.String.of_string "english"
| `Arr x -> Arr.to_pyobject x
)); ("token_pattern", Wrap_utils.Option.map token_pattern Py.String.of_string); ("ngram_range", ngram_range); ("analyzer", Wrap_utils.Option.map analyzer (function
| `S x -> Py.String.of_string x
| `Word -> Py.String.of_string "word"
| `Char -> Py.String.of_string "char"
| `Char_wb -> Py.String.of_string "char_wb"
| `Callable x -> Wrap_utils.id x
)); ("n_features", Wrap_utils.Option.map n_features Py.Int.of_int); ("binary", Wrap_utils.Option.map binary Py.Bool.of_bool); ("norm", Wrap_utils.Option.map norm (function
| `L1 -> Py.String.of_string "l1"
| `L2 -> Py.String.of_string "l2"
| `None -> Py.none
)); ("alternate_sign", Wrap_utils.Option.map alternate_sign Py.Bool.of_bool); ("dtype", dtype)])

let build_analyzer self =
   Py.Module.get_function_with_keywords self "build_analyzer"
     [||]
     []

let build_preprocessor self =
   Py.Module.get_function_with_keywords self "build_preprocessor"
     [||]
     []

let build_tokenizer self =
   Py.Module.get_function_with_keywords self "build_tokenizer"
     [||]
     []

let decode ~doc self =
   Py.Module.get_function_with_keywords self "decode"
     [||]
     (Wrap_utils.keyword_args [("doc", Some(doc |> Py.String.of_string))])
     |> Py.String.to_string
let fit ?y ~x self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Arr.to_pyobject))])

let fit_transform ?y ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let get_stop_words self =
   Py.Module.get_function_with_keywords self "get_stop_words"
     [||]
     []

let partial_fit ?y ~x self =
   Py.Module.get_function_with_keywords self "partial_fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Arr.to_pyobject))])

let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ~x self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module TfidfTransformer = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
                  let create ?norm ?use_idf ?smooth_idf ?sublinear_tf () =
                     Py.Module.get_function_with_keywords ns "TfidfTransformer"
                       [||]
                       (Wrap_utils.keyword_args [("norm", Wrap_utils.Option.map norm (function
| `L1 -> Py.String.of_string "l1"
| `L2 -> Py.String.of_string "l2"
| `None -> Py.none
)); ("use_idf", Wrap_utils.Option.map use_idf Py.Bool.of_bool); ("smooth_idf", Wrap_utils.Option.map smooth_idf Py.Bool.of_bool); ("sublinear_tf", Wrap_utils.Option.map sublinear_tf Py.Bool.of_bool)])

let fit ?y ~x self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("X", Some(x |> Csr_matrix.to_pyobject))])

let fit_transform ?y ?fit_params ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (List.rev_append (Wrap_utils.keyword_args [("y", Wrap_utils.Option.map y Arr.to_pyobject); ("X", Some(x |> Arr.to_pyobject))]) (match fit_params with None -> [] | Some x -> x))
     |> Arr.of_pyobject
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ?copy ~x self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("copy", Wrap_utils.Option.map copy Py.Bool.of_bool); ("X", Some(x |> Arr.to_pyobject))])
     |> Arr.of_pyobject

let idf_opt self =
  match Py.Object.get_attr_string self "idf_" with
  | None -> failwith "attribute idf_ not found"
  | Some x -> if Py.is_none x then None else Some (Arr.of_pyobject x)

let idf_ self = match idf_opt self with
  | None -> raise Not_found
  | Some x -> x
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module TfidfVectorizer = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
                  let create ?input ?encoding ?decode_error ?strip_accents ?lowercase ?preprocessor ?tokenizer ?analyzer ?stop_words ?token_pattern ?ngram_range ?max_df ?min_df ?max_features ?vocabulary ?binary ?dtype ?norm ?use_idf ?smooth_idf ?sublinear_tf () =
                     Py.Module.get_function_with_keywords ns "TfidfVectorizer"
                       [||]
                       (Wrap_utils.keyword_args [("input", Wrap_utils.Option.map input (function
| `Filename -> Py.String.of_string "filename"
| `File -> Py.String.of_string "file"
| `Content -> Py.String.of_string "content"
)); ("encoding", Wrap_utils.Option.map encoding Py.String.of_string); ("decode_error", Wrap_utils.Option.map decode_error (function
| `Strict -> Py.String.of_string "strict"
| `Ignore -> Py.String.of_string "ignore"
| `Replace -> Py.String.of_string "replace"
)); ("strip_accents", Wrap_utils.Option.map strip_accents (function
| `Ascii -> Py.String.of_string "ascii"
| `Unicode -> Py.String.of_string "unicode"
)); ("lowercase", Wrap_utils.Option.map lowercase Py.Bool.of_bool); ("preprocessor", preprocessor); ("tokenizer", tokenizer); ("analyzer", Wrap_utils.Option.map analyzer (function
| `S x -> Py.String.of_string x
| `Word -> Py.String.of_string "word"
| `Char -> Py.String.of_string "char"
| `Char_wb -> Py.String.of_string "char_wb"
| `Callable x -> Wrap_utils.id x
)); ("stop_words", Wrap_utils.Option.map stop_words (function
| `English -> Py.String.of_string "english"
| `Arr x -> Arr.to_pyobject x
)); ("token_pattern", Wrap_utils.Option.map token_pattern Py.String.of_string); ("ngram_range", ngram_range); ("max_df", Wrap_utils.Option.map max_df (function
| `F x -> Py.Float.of_float x
| `I x -> Py.Int.of_int x
)); ("min_df", Wrap_utils.Option.map min_df (function
| `F x -> Py.Float.of_float x
| `I x -> Py.Int.of_int x
)); ("max_features", Wrap_utils.Option.map max_features Py.Int.of_int); ("vocabulary", Wrap_utils.Option.map vocabulary (function
| `Mapping x -> Wrap_utils.id x
| `Arr x -> Arr.to_pyobject x
)); ("binary", Wrap_utils.Option.map binary Py.Bool.of_bool); ("dtype", dtype); ("norm", Wrap_utils.Option.map norm (function
| `L1 -> Py.String.of_string "l1"
| `L2 -> Py.String.of_string "l2"
| `None -> Py.none
)); ("use_idf", Wrap_utils.Option.map use_idf Py.Bool.of_bool); ("smooth_idf", Wrap_utils.Option.map smooth_idf Py.Bool.of_bool); ("sublinear_tf", Wrap_utils.Option.map sublinear_tf Py.Bool.of_bool)])

let build_analyzer self =
   Py.Module.get_function_with_keywords self "build_analyzer"
     [||]
     []

let build_preprocessor self =
   Py.Module.get_function_with_keywords self "build_preprocessor"
     [||]
     []

let build_tokenizer self =
   Py.Module.get_function_with_keywords self "build_tokenizer"
     [||]
     []

let decode ~doc self =
   Py.Module.get_function_with_keywords self "decode"
     [||]
     (Wrap_utils.keyword_args [("doc", Some(doc |> Py.String.of_string))])
     |> Py.String.to_string
let fit ?y ~raw_documents self =
   Py.Module.get_function_with_keywords self "fit"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("raw_documents", Some(raw_documents |> Arr.to_pyobject))])

let fit_transform ?y ~raw_documents self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (Wrap_utils.keyword_args [("y", y); ("raw_documents", Some(raw_documents |> Arr.to_pyobject))])
     |> Arr.of_pyobject
let get_feature_names self =
   Py.Module.get_function_with_keywords self "get_feature_names"
     [||]
     []
     |> (Py.List.to_list_map Py.String.to_string)
let get_params ?deep self =
   Py.Module.get_function_with_keywords self "get_params"
     [||]
     (Wrap_utils.keyword_args [("deep", Wrap_utils.Option.map deep Py.Bool.of_bool)])
     |> Dict.of_pyobject
let get_stop_words self =
   Py.Module.get_function_with_keywords self "get_stop_words"
     [||]
     []

let inverse_transform ~x self =
   Py.Module.get_function_with_keywords self "inverse_transform"
     [||]
     (Wrap_utils.keyword_args [("X", Some(x |> Arr.to_pyobject))])

let set_params ?params self =
   Py.Module.get_function_with_keywords self "set_params"
     [||]
     (match params with None -> [] | Some x -> x)

let transform ?copy ~raw_documents self =
   Py.Module.get_function_with_keywords self "transform"
     [||]
     (Wrap_utils.keyword_args [("copy", Wrap_utils.Option.map copy Py.Bool.of_bool); ("raw_documents", Some(raw_documents |> Arr.to_pyobject))])
     |> Arr.of_pyobject

let vocabulary_opt self =
  match Py.Object.get_attr_string self "vocabulary_" with
  | None -> failwith "attribute vocabulary_ not found"
  | Some x -> if Py.is_none x then None else Some (Dict.of_pyobject x)

let vocabulary_ self = match vocabulary_opt self with
  | None -> raise Not_found
  | Some x -> x

let fixed_vocabulary_opt self =
  match Py.Object.get_attr_string self "fixed_vocabulary_" with
  | None -> failwith "attribute fixed_vocabulary_ not found"
  | Some x -> if Py.is_none x then None else Some (Py.Bool.to_bool x)

let fixed_vocabulary_ self = match fixed_vocabulary_opt self with
  | None -> raise Not_found
  | Some x -> x

let idf_opt self =
  match Py.Object.get_attr_string self "idf_" with
  | None -> failwith "attribute idf_ not found"
  | Some x -> if Py.is_none x then None else Some (Arr.of_pyobject x)

let idf_ self = match idf_opt self with
  | None -> raise Not_found
  | Some x -> x

let stop_words_opt self =
  match Py.Object.get_attr_string self "stop_words_" with
  | None -> failwith "attribute stop_words_ not found"
  | Some x -> if Py.is_none x then None else Some (Wrap_utils.id x)

let stop_words_ self = match stop_words_opt self with
  | None -> raise Not_found
  | Some x -> x
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
module TransformerMixin = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create () =
   Py.Module.get_function_with_keywords ns "TransformerMixin"
     [||]
     []

let fit_transform ?y ?fit_params ~x self =
   Py.Module.get_function_with_keywords self "fit_transform"
     [||]
     (List.rev_append (Wrap_utils.keyword_args [("y", Wrap_utils.Option.map y Arr.to_pyobject); ("X", Some(x |> Arr.to_pyobject))]) (match fit_params with None -> [] | Some x -> x))
     |> Arr.of_pyobject
let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
                  let check_array ?accept_sparse ?accept_large_sparse ?dtype ?order ?copy ?force_all_finite ?ensure_2d ?allow_nd ?ensure_min_samples ?ensure_min_features ?warn_on_dtype ?estimator ~array () =
                     Py.Module.get_function_with_keywords ns "check_array"
                       [||]
                       (Wrap_utils.keyword_args [("accept_sparse", Wrap_utils.Option.map accept_sparse (function
| `S x -> Py.String.of_string x
| `Bool x -> Py.Bool.of_bool x
| `StringList x -> (Py.List.of_list_map Py.String.of_string) x
)); ("accept_large_sparse", Wrap_utils.Option.map accept_large_sparse Py.Bool.of_bool); ("dtype", Wrap_utils.Option.map dtype (function
| `S x -> Py.String.of_string x
| `Dtype x -> Wrap_utils.id x
| `TypeList x -> Wrap_utils.id x
| `None -> Py.none
)); ("order", Wrap_utils.Option.map order (function
| `F -> Py.String.of_string "F"
| `C -> Py.String.of_string "C"
)); ("copy", Wrap_utils.Option.map copy Py.Bool.of_bool); ("force_all_finite", Wrap_utils.Option.map force_all_finite (function
| `Bool x -> Py.Bool.of_bool x
| `Allow_nan -> Py.String.of_string "allow-nan"
)); ("ensure_2d", Wrap_utils.Option.map ensure_2d Py.Bool.of_bool); ("allow_nd", Wrap_utils.Option.map allow_nd Py.Bool.of_bool); ("ensure_min_samples", Wrap_utils.Option.map ensure_min_samples Py.Int.of_int); ("ensure_min_features", Wrap_utils.Option.map ensure_min_features Py.Int.of_int); ("warn_on_dtype", Wrap_utils.Option.map warn_on_dtype Py.Bool.of_bool); ("estimator", Wrap_utils.Option.map estimator (function
| `S x -> Py.String.of_string x
| `Estimator x -> Wrap_utils.id x
)); ("array", Some(array ))])

                  let check_is_fitted ?attributes ?msg ?all_or_any ~estimator () =
                     Py.Module.get_function_with_keywords ns "check_is_fitted"
                       [||]
                       (Wrap_utils.keyword_args [("attributes", Wrap_utils.Option.map attributes (function
| `S x -> Py.String.of_string x
| `Arr x -> Arr.to_pyobject x
| `StringList x -> (Py.List.of_list_map Py.String.of_string) x
)); ("msg", Wrap_utils.Option.map msg Py.String.of_string); ("all_or_any", Wrap_utils.Option.map all_or_any (function
| `Callable x -> Wrap_utils.id x
| `PyObject x -> Wrap_utils.id x
)); ("estimator", Some(estimator ))])

module Deprecated = struct
type t = Py.Object.t
let of_pyobject x = x
let to_pyobject x = x
let create ?extra () =
   Py.Module.get_function_with_keywords ns "deprecated"
     [||]
     (Wrap_utils.keyword_args [("extra", Wrap_utils.Option.map extra Py.String.of_string)])

let to_string self = Py.Object.to_string self
let show self = to_string self
let pp formatter self = Format.fprintf formatter "%s" (show self)

end
                  let normalize ?norm ?axis ?copy ?return_norm ~x () =
                     Py.Module.get_function_with_keywords ns "normalize"
                       [||]
                       (Wrap_utils.keyword_args [("norm", Wrap_utils.Option.map norm (function
| `L1 -> Py.String.of_string "l1"
| `L2 -> Py.String.of_string "l2"
| `Max -> Py.String.of_string "max"
| `T_l2_by x -> Wrap_utils.id x
)); ("axis", Wrap_utils.Option.map axis (function
| `Zero -> Py.Int.of_int 0
| `One -> Py.Int.of_int 1
| `T_1_by x -> Wrap_utils.id x
)); ("copy", Wrap_utils.Option.map copy Py.Bool.of_bool); ("return_norm", Wrap_utils.Option.map return_norm Py.Bool.of_bool); ("X", Some(x |> Arr.to_pyobject))])
                       |> (fun x -> ((Arr.of_pyobject (Py.Tuple.get x 0)), (Wrap_utils.id (Py.Tuple.get x 1))))
let strip_accents_ascii ~s () =
   Py.Module.get_function_with_keywords ns "strip_accents_ascii"
     [||]
     (Wrap_utils.keyword_args [("s", Some(s |> Py.String.of_string))])

let strip_accents_unicode ~s () =
   Py.Module.get_function_with_keywords ns "strip_accents_unicode"
     [||]
     (Wrap_utils.keyword_args [("s", Some(s |> Py.String.of_string))])

let strip_tags ~s () =
   Py.Module.get_function_with_keywords ns "strip_tags"
     [||]
     (Wrap_utils.keyword_args [("s", Some(s |> Py.String.of_string))])


end