snowflake-ml-python 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. snowflake/ml/_internal/env_utils.py +77 -32
  2. snowflake/ml/_internal/exceptions/dataset_error_messages.py +5 -0
  3. snowflake/ml/_internal/exceptions/dataset_errors.py +24 -0
  4. snowflake/ml/_internal/exceptions/error_codes.py +3 -0
  5. snowflake/ml/_internal/lineage/data_source.py +10 -0
  6. snowflake/ml/_internal/lineage/dataset_dataframe.py +44 -0
  7. snowflake/ml/_internal/utils/identifier.py +3 -1
  8. snowflake/ml/_internal/utils/sql_identifier.py +2 -6
  9. snowflake/ml/dataset/__init__.py +10 -0
  10. snowflake/ml/dataset/dataset.py +454 -129
  11. snowflake/ml/dataset/dataset_factory.py +53 -0
  12. snowflake/ml/dataset/dataset_metadata.py +103 -0
  13. snowflake/ml/dataset/dataset_reader.py +202 -0
  14. snowflake/ml/feature_store/feature_store.py +531 -332
  15. snowflake/ml/feature_store/feature_view.py +40 -23
  16. snowflake/ml/fileset/embedded_stage_fs.py +146 -0
  17. snowflake/ml/fileset/sfcfs.py +56 -54
  18. snowflake/ml/fileset/snowfs.py +159 -0
  19. snowflake/ml/fileset/stage_fs.py +49 -17
  20. snowflake/ml/model/__init__.py +2 -2
  21. snowflake/ml/model/_api.py +16 -1
  22. snowflake/ml/model/_client/model/model_impl.py +27 -0
  23. snowflake/ml/model/_client/model/model_version_impl.py +137 -50
  24. snowflake/ml/model/_client/ops/model_ops.py +159 -40
  25. snowflake/ml/model/_client/sql/model.py +25 -2
  26. snowflake/ml/model/_client/sql/model_version.py +131 -2
  27. snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +5 -1
  28. snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +1 -0
  29. snowflake/ml/model/_deploy_client/snowservice/deploy.py +2 -0
  30. snowflake/ml/model/_deploy_client/utils/constants.py +0 -5
  31. snowflake/ml/model/_deploy_client/utils/snowservice_client.py +21 -50
  32. snowflake/ml/model/_model_composer/model_composer.py +22 -1
  33. snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +38 -51
  34. snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +19 -1
  35. snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
  36. snowflake/ml/model/_packager/model_env/model_env.py +41 -0
  37. snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
  38. snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
  39. snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
  40. snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
  41. snowflake/ml/model/_packager/model_meta/model_meta.py +37 -11
  42. snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
  43. snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
  44. snowflake/ml/model/_packager/model_packager.py +2 -5
  45. snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
  46. snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
  47. snowflake/ml/model/type_hints.py +21 -2
  48. snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
  49. snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
  50. snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +55 -3
  51. snowflake/ml/modeling/_internal/ml_runtime_implementations/ml_runtime_handlers.py +34 -18
  52. snowflake/ml/modeling/_internal/model_trainer.py +7 -0
  53. snowflake/ml/modeling/_internal/model_trainer_builder.py +42 -9
  54. snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +13 -14
  55. snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +29 -7
  56. snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +261 -16
  57. snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +246 -175
  58. snowflake/ml/modeling/cluster/affinity_propagation.py +246 -175
  59. snowflake/ml/modeling/cluster/agglomerative_clustering.py +246 -175
  60. snowflake/ml/modeling/cluster/birch.py +248 -175
  61. snowflake/ml/modeling/cluster/bisecting_k_means.py +248 -175
  62. snowflake/ml/modeling/cluster/dbscan.py +246 -175
  63. snowflake/ml/modeling/cluster/feature_agglomeration.py +248 -175
  64. snowflake/ml/modeling/cluster/k_means.py +248 -175
  65. snowflake/ml/modeling/cluster/mean_shift.py +246 -175
  66. snowflake/ml/modeling/cluster/mini_batch_k_means.py +248 -175
  67. snowflake/ml/modeling/cluster/optics.py +246 -175
  68. snowflake/ml/modeling/cluster/spectral_biclustering.py +246 -175
  69. snowflake/ml/modeling/cluster/spectral_clustering.py +246 -175
  70. snowflake/ml/modeling/cluster/spectral_coclustering.py +246 -175
  71. snowflake/ml/modeling/compose/column_transformer.py +248 -175
  72. snowflake/ml/modeling/compose/transformed_target_regressor.py +246 -175
  73. snowflake/ml/modeling/covariance/elliptic_envelope.py +246 -175
  74. snowflake/ml/modeling/covariance/empirical_covariance.py +246 -175
  75. snowflake/ml/modeling/covariance/graphical_lasso.py +246 -175
  76. snowflake/ml/modeling/covariance/graphical_lasso_cv.py +246 -175
  77. snowflake/ml/modeling/covariance/ledoit_wolf.py +246 -175
  78. snowflake/ml/modeling/covariance/min_cov_det.py +246 -175
  79. snowflake/ml/modeling/covariance/oas.py +246 -175
  80. snowflake/ml/modeling/covariance/shrunk_covariance.py +246 -175
  81. snowflake/ml/modeling/decomposition/dictionary_learning.py +248 -175
  82. snowflake/ml/modeling/decomposition/factor_analysis.py +248 -175
  83. snowflake/ml/modeling/decomposition/fast_ica.py +248 -175
  84. snowflake/ml/modeling/decomposition/incremental_pca.py +248 -175
  85. snowflake/ml/modeling/decomposition/kernel_pca.py +248 -175
  86. snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +248 -175
  87. snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +248 -175
  88. snowflake/ml/modeling/decomposition/pca.py +248 -175
  89. snowflake/ml/modeling/decomposition/sparse_pca.py +248 -175
  90. snowflake/ml/modeling/decomposition/truncated_svd.py +248 -175
  91. snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +248 -175
  92. snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +246 -175
  93. snowflake/ml/modeling/ensemble/ada_boost_classifier.py +246 -175
  94. snowflake/ml/modeling/ensemble/ada_boost_regressor.py +246 -175
  95. snowflake/ml/modeling/ensemble/bagging_classifier.py +246 -175
  96. snowflake/ml/modeling/ensemble/bagging_regressor.py +246 -175
  97. snowflake/ml/modeling/ensemble/extra_trees_classifier.py +246 -175
  98. snowflake/ml/modeling/ensemble/extra_trees_regressor.py +246 -175
  99. snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +246 -175
  100. snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +246 -175
  101. snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +246 -175
  102. snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +246 -175
  103. snowflake/ml/modeling/ensemble/isolation_forest.py +246 -175
  104. snowflake/ml/modeling/ensemble/random_forest_classifier.py +246 -175
  105. snowflake/ml/modeling/ensemble/random_forest_regressor.py +246 -175
  106. snowflake/ml/modeling/ensemble/stacking_regressor.py +248 -175
  107. snowflake/ml/modeling/ensemble/voting_classifier.py +248 -175
  108. snowflake/ml/modeling/ensemble/voting_regressor.py +248 -175
  109. snowflake/ml/modeling/feature_selection/generic_univariate_select.py +248 -175
  110. snowflake/ml/modeling/feature_selection/select_fdr.py +248 -175
  111. snowflake/ml/modeling/feature_selection/select_fpr.py +248 -175
  112. snowflake/ml/modeling/feature_selection/select_fwe.py +248 -175
  113. snowflake/ml/modeling/feature_selection/select_k_best.py +248 -175
  114. snowflake/ml/modeling/feature_selection/select_percentile.py +248 -175
  115. snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +248 -175
  116. snowflake/ml/modeling/feature_selection/variance_threshold.py +248 -175
  117. snowflake/ml/modeling/framework/_utils.py +8 -1
  118. snowflake/ml/modeling/framework/base.py +72 -37
  119. snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +246 -175
  120. snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +246 -175
  121. snowflake/ml/modeling/impute/iterative_imputer.py +248 -175
  122. snowflake/ml/modeling/impute/knn_imputer.py +248 -175
  123. snowflake/ml/modeling/impute/missing_indicator.py +248 -175
  124. snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +248 -175
  125. snowflake/ml/modeling/kernel_approximation/nystroem.py +248 -175
  126. snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +248 -175
  127. snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +248 -175
  128. snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +248 -175
  129. snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +246 -175
  130. snowflake/ml/modeling/lightgbm/lgbm_classifier.py +246 -175
  131. snowflake/ml/modeling/lightgbm/lgbm_regressor.py +246 -175
  132. snowflake/ml/modeling/linear_model/ard_regression.py +246 -175
  133. snowflake/ml/modeling/linear_model/bayesian_ridge.py +246 -175
  134. snowflake/ml/modeling/linear_model/elastic_net.py +246 -175
  135. snowflake/ml/modeling/linear_model/elastic_net_cv.py +246 -175
  136. snowflake/ml/modeling/linear_model/gamma_regressor.py +246 -175
  137. snowflake/ml/modeling/linear_model/huber_regressor.py +246 -175
  138. snowflake/ml/modeling/linear_model/lars.py +246 -175
  139. snowflake/ml/modeling/linear_model/lars_cv.py +246 -175
  140. snowflake/ml/modeling/linear_model/lasso.py +246 -175
  141. snowflake/ml/modeling/linear_model/lasso_cv.py +246 -175
  142. snowflake/ml/modeling/linear_model/lasso_lars.py +246 -175
  143. snowflake/ml/modeling/linear_model/lasso_lars_cv.py +246 -175
  144. snowflake/ml/modeling/linear_model/lasso_lars_ic.py +246 -175
  145. snowflake/ml/modeling/linear_model/linear_regression.py +246 -175
  146. snowflake/ml/modeling/linear_model/logistic_regression.py +246 -175
  147. snowflake/ml/modeling/linear_model/logistic_regression_cv.py +246 -175
  148. snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +246 -175
  149. snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +246 -175
  150. snowflake/ml/modeling/linear_model/multi_task_lasso.py +246 -175
  151. snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +246 -175
  152. snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +246 -175
  153. snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +246 -175
  154. snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +246 -175
  155. snowflake/ml/modeling/linear_model/perceptron.py +246 -175
  156. snowflake/ml/modeling/linear_model/poisson_regressor.py +246 -175
  157. snowflake/ml/modeling/linear_model/ransac_regressor.py +246 -175
  158. snowflake/ml/modeling/linear_model/ridge.py +246 -175
  159. snowflake/ml/modeling/linear_model/ridge_classifier.py +246 -175
  160. snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +246 -175
  161. snowflake/ml/modeling/linear_model/ridge_cv.py +246 -175
  162. snowflake/ml/modeling/linear_model/sgd_classifier.py +246 -175
  163. snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +246 -175
  164. snowflake/ml/modeling/linear_model/sgd_regressor.py +246 -175
  165. snowflake/ml/modeling/linear_model/theil_sen_regressor.py +246 -175
  166. snowflake/ml/modeling/linear_model/tweedie_regressor.py +246 -175
  167. snowflake/ml/modeling/manifold/isomap.py +248 -175
  168. snowflake/ml/modeling/manifold/mds.py +248 -175
  169. snowflake/ml/modeling/manifold/spectral_embedding.py +248 -175
  170. snowflake/ml/modeling/manifold/tsne.py +248 -175
  171. snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +246 -175
  172. snowflake/ml/modeling/mixture/gaussian_mixture.py +246 -175
  173. snowflake/ml/modeling/model_selection/grid_search_cv.py +63 -41
  174. snowflake/ml/modeling/model_selection/randomized_search_cv.py +80 -38
  175. snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +246 -175
  176. snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +246 -175
  177. snowflake/ml/modeling/multiclass/output_code_classifier.py +246 -175
  178. snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +246 -175
  179. snowflake/ml/modeling/naive_bayes/categorical_nb.py +246 -175
  180. snowflake/ml/modeling/naive_bayes/complement_nb.py +246 -175
  181. snowflake/ml/modeling/naive_bayes/gaussian_nb.py +246 -175
  182. snowflake/ml/modeling/naive_bayes/multinomial_nb.py +246 -175
  183. snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +246 -175
  184. snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +246 -175
  185. snowflake/ml/modeling/neighbors/kernel_density.py +246 -175
  186. snowflake/ml/modeling/neighbors/local_outlier_factor.py +246 -175
  187. snowflake/ml/modeling/neighbors/nearest_centroid.py +246 -175
  188. snowflake/ml/modeling/neighbors/nearest_neighbors.py +246 -175
  189. snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +248 -175
  190. snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +246 -175
  191. snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +246 -175
  192. snowflake/ml/modeling/neural_network/bernoulli_rbm.py +248 -175
  193. snowflake/ml/modeling/neural_network/mlp_classifier.py +246 -175
  194. snowflake/ml/modeling/neural_network/mlp_regressor.py +246 -175
  195. snowflake/ml/modeling/pipeline/pipeline.py +517 -35
  196. snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
  197. snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
  198. snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
  199. snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
  200. snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
  201. snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
  202. snowflake/ml/modeling/preprocessing/one_hot_encoder.py +13 -5
  203. snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
  204. snowflake/ml/modeling/preprocessing/polynomial_features.py +248 -175
  205. snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
  206. snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
  207. snowflake/ml/modeling/semi_supervised/label_propagation.py +246 -175
  208. snowflake/ml/modeling/semi_supervised/label_spreading.py +246 -175
  209. snowflake/ml/modeling/svm/linear_svc.py +246 -175
  210. snowflake/ml/modeling/svm/linear_svr.py +246 -175
  211. snowflake/ml/modeling/svm/nu_svc.py +246 -175
  212. snowflake/ml/modeling/svm/nu_svr.py +246 -175
  213. snowflake/ml/modeling/svm/svc.py +246 -175
  214. snowflake/ml/modeling/svm/svr.py +246 -175
  215. snowflake/ml/modeling/tree/decision_tree_classifier.py +246 -175
  216. snowflake/ml/modeling/tree/decision_tree_regressor.py +246 -175
  217. snowflake/ml/modeling/tree/extra_tree_classifier.py +246 -175
  218. snowflake/ml/modeling/tree/extra_tree_regressor.py +246 -175
  219. snowflake/ml/modeling/xgboost/xgb_classifier.py +246 -175
  220. snowflake/ml/modeling/xgboost/xgb_regressor.py +246 -175
  221. snowflake/ml/modeling/xgboost/xgbrf_classifier.py +246 -175
  222. snowflake/ml/modeling/xgboost/xgbrf_regressor.py +246 -175
  223. snowflake/ml/registry/model_registry.py +3 -149
  224. snowflake/ml/registry/registry.py +1 -1
  225. snowflake/ml/version.py +1 -1
  226. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/METADATA +129 -57
  227. snowflake_ml_python-1.5.0.dist-info/RECORD +380 -0
  228. snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
  229. snowflake/ml/registry/_artifact_manager.py +0 -156
  230. snowflake/ml/registry/artifact.py +0 -46
  231. snowflake_ml_python-1.4.0.dist-info/RECORD +0 -370
  232. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/LICENSE.txt +0 -0
  233. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/WHEEL +0 -0
  234. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/top_level.txt +0 -0
@@ -32,6 +32,15 @@ from snowflake.ml.modeling._internal.transformer_protocols import (
32
32
  BatchInferenceKwargsTypedDict,
33
33
  ScoreKwargsTypedDict
34
34
  )
35
+ from snowflake.ml.model._signatures import utils as model_signature_utils
36
+ from snowflake.ml.model.model_signature import (
37
+ BaseFeatureSpec,
38
+ DataType,
39
+ FeatureSpec,
40
+ ModelSignature,
41
+ _infer_signature,
42
+ _rename_signature_with_snowflake_identifiers,
43
+ )
35
44
 
36
45
  from snowflake.ml.modeling._internal.model_transformer_builder import ModelTransformerBuilder
37
46
 
@@ -42,16 +51,6 @@ from snowflake.ml.modeling._internal.estimator_utils import (
42
51
  validate_sklearn_args,
43
52
  )
44
53
 
45
- from snowflake.ml.model.model_signature import (
46
- DataType,
47
- FeatureSpec,
48
- ModelSignature,
49
- _infer_signature,
50
- _rename_signature_with_snowflake_identifiers,
51
- BaseFeatureSpec,
52
- )
53
- from snowflake.ml.model._signatures import utils as model_signature_utils
54
-
55
54
  _PROJECT = "ModelDevelopment"
56
55
  # Derive subproject from module name by removing "sklearn"
57
56
  # and converting module name from underscore to CamelCase
@@ -60,12 +59,6 @@ _SUBPROJECT = "".join([s.capitalize() for s in "xgboost".replace("sklearn.", "")
60
59
 
61
60
  DATAFRAME_TYPE = Union[DataFrame, pd.DataFrame]
62
61
 
63
- def _is_fit_transform_method_enabled() -> Callable[[Any], bool]:
64
- def check(self: BaseTransformer) -> TypeGuard[Callable[..., object]]:
65
- return False and callable(getattr(self._sklearn_object, "fit_transform", None))
66
- return check
67
-
68
-
69
62
  class XGBRFRegressor(BaseTransformer):
70
63
  r"""scikit-learn API for XGBoost random forest regression
71
64
  For more details on this class, see [xgboost.XGBRFRegressor]
@@ -426,12 +419,7 @@ class XGBRFRegressor(BaseTransformer):
426
419
  )
427
420
  return selected_cols
428
421
 
429
- @telemetry.send_api_usage_telemetry(
430
- project=_PROJECT,
431
- subproject=_SUBPROJECT,
432
- custom_tags=dict([("autogen", True)]),
433
- )
434
- def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "XGBRFRegressor":
422
+ def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "XGBRFRegressor":
435
423
  """Fit gradient boosting model
436
424
  For more details on this function, see [xgboost.XGBRFRegressor.fit]
437
425
  (https://xgboost.readthedocs.io/en/stable/python/python_api.html#xgboost.XGBRFRegressor.fit)
@@ -458,12 +446,14 @@ class XGBRFRegressor(BaseTransformer):
458
446
 
459
447
  self._snowpark_cols = dataset.select(self.input_cols).columns
460
448
 
461
- # If we are already in a stored procedure, no need to kick off another one.
449
+ # If we are already in a stored procedure, no need to kick off another one.
462
450
  if SNOWML_SPROC_ENV in os.environ:
463
451
  statement_params = telemetry.get_function_usage_statement_params(
464
452
  project=_PROJECT,
465
453
  subproject=_SUBPROJECT,
466
- function_name=telemetry.get_statement_params_full_func_name(inspect.currentframe(), XGBRFRegressor.__class__.__name__),
454
+ function_name=telemetry.get_statement_params_full_func_name(
455
+ inspect.currentframe(), XGBRFRegressor.__class__.__name__
456
+ ),
467
457
  api_calls=[Session.call],
468
458
  custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
469
459
  )
@@ -484,27 +474,24 @@ class XGBRFRegressor(BaseTransformer):
484
474
  )
485
475
  self._sklearn_object = model_trainer.train()
486
476
  self._is_fitted = True
487
- self._get_model_signatures(dataset)
477
+ self._generate_model_signatures(dataset)
488
478
  return self
489
479
 
490
480
  def _batch_inference_validate_snowpark(
491
481
  self,
492
482
  dataset: DataFrame,
493
483
  inference_method: str,
494
- ) -> List[str]:
495
- """Util method to run validate that batch inference can be run on a snowpark dataframe and
496
- return the available package that exists in the snowflake anaconda channel
484
+ ) -> None:
485
+ """Util method to run validate that batch inference can be run on a snowpark dataframe.
497
486
 
498
487
  Args:
499
488
  dataset: snowpark dataframe
500
489
  inference_method: the inference method such as predict, score...
501
-
490
+
502
491
  Raises:
503
492
  SnowflakeMLException: If the estimator is not fitted, raise error
504
493
  SnowflakeMLException: If the session is None, raise error
505
494
 
506
- Returns:
507
- A list of available package that exists in the snowflake anaconda channel
508
495
  """
509
496
  if not self._is_fitted:
510
497
  raise exceptions.SnowflakeMLException(
@@ -522,9 +509,7 @@ class XGBRFRegressor(BaseTransformer):
522
509
  "Session must not specified for snowpark dataset."
523
510
  ),
524
511
  )
525
- # Validate that key package version in user workspace are supported in snowflake conda channel
526
- return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
527
- pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
512
+
528
513
 
529
514
  @available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
530
515
  @telemetry.send_api_usage_telemetry(
@@ -560,7 +545,9 @@ class XGBRFRegressor(BaseTransformer):
560
545
  # when it is classifier, infer the datatype from label columns
561
546
  if expected_type_inferred == "" and 'predict' in self.model_signatures:
562
547
  # Batch inference takes a single expected output column type. Use the first columns type for now.
563
- label_cols_signatures = [row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols]
548
+ label_cols_signatures = [
549
+ row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
550
+ ]
564
551
  if len(label_cols_signatures) == 0:
565
552
  error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
566
553
  raise exceptions.SnowflakeMLException(
@@ -568,25 +555,23 @@ class XGBRFRegressor(BaseTransformer):
568
555
  original_exception=ValueError(error_str),
569
556
  )
570
557
 
571
- expected_type_inferred = convert_sp_to_sf_type(
572
- label_cols_signatures[0].as_snowpark_type()
573
- )
558
+ expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
574
559
 
575
- self._deps = self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
576
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
560
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
561
+ self._deps = self._get_dependencies()
562
+ assert isinstance(
563
+ dataset._session, Session
564
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
577
565
 
578
566
  transform_kwargs = dict(
579
- session = dataset._session,
580
- dependencies = self._deps,
581
- drop_input_cols = self._drop_input_cols,
582
- expected_output_cols_type = expected_type_inferred,
567
+ session=dataset._session,
568
+ dependencies=self._deps,
569
+ drop_input_cols=self._drop_input_cols,
570
+ expected_output_cols_type=expected_type_inferred,
583
571
  )
584
572
 
585
573
  elif isinstance(dataset, pd.DataFrame):
586
- transform_kwargs = dict(
587
- snowpark_input_cols = self._snowpark_cols,
588
- drop_input_cols = self._drop_input_cols
589
- )
574
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
590
575
 
591
576
  transform_handlers = ModelTransformerBuilder.build(
592
577
  dataset=dataset,
@@ -626,7 +611,7 @@ class XGBRFRegressor(BaseTransformer):
626
611
  Transformed dataset.
627
612
  """
628
613
  super()._check_dataset_type(dataset)
629
- inference_method="transform"
614
+ inference_method = "transform"
630
615
 
631
616
  # This dictionary contains optional kwargs for batch inference. These kwargs
632
617
  # are specific to the type of dataset used.
@@ -656,24 +641,19 @@ class XGBRFRegressor(BaseTransformer):
656
641
  if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
657
642
  expected_dtype = convert_sp_to_sf_type(output_types[0])
658
643
 
659
- self._deps = self._batch_inference_validate_snowpark(
660
- dataset=dataset,
661
- inference_method=inference_method,
662
- )
644
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
645
+ self._deps = self._get_dependencies()
663
646
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
664
647
 
665
648
  transform_kwargs = dict(
666
- session = dataset._session,
667
- dependencies = self._deps,
668
- drop_input_cols = self._drop_input_cols,
669
- expected_output_cols_type = expected_dtype,
649
+ session=dataset._session,
650
+ dependencies=self._deps,
651
+ drop_input_cols=self._drop_input_cols,
652
+ expected_output_cols_type=expected_dtype,
670
653
  )
671
654
 
672
655
  elif isinstance(dataset, pd.DataFrame):
673
- transform_kwargs = dict(
674
- snowpark_input_cols = self._snowpark_cols,
675
- drop_input_cols = self._drop_input_cols
676
- )
656
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
677
657
 
678
658
  transform_handlers = ModelTransformerBuilder.build(
679
659
  dataset=dataset,
@@ -692,7 +672,11 @@ class XGBRFRegressor(BaseTransformer):
692
672
  return output_df
693
673
 
694
674
  @available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
695
- def fit_predict(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_predict_",) -> Union[DataFrame, pd.DataFrame]:
675
+ def fit_predict(
676
+ self,
677
+ dataset: Union[DataFrame, pd.DataFrame],
678
+ output_cols_prefix: str = "fit_predict_",
679
+ ) -> Union[DataFrame, pd.DataFrame]:
696
680
  """ Method not supported for this class.
697
681
 
698
682
 
@@ -717,22 +701,104 @@ class XGBRFRegressor(BaseTransformer):
717
701
  )
718
702
  output_result, fitted_estimator = model_trainer.train_fit_predict(
719
703
  drop_input_cols=self._drop_input_cols,
720
- expected_output_cols_list=self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix),
704
+ expected_output_cols_list=(
705
+ self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
706
+ ),
721
707
  )
722
708
  self._sklearn_object = fitted_estimator
723
709
  self._is_fitted = True
724
710
  return output_result
725
711
 
712
+
713
+ @available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
714
+ def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
715
+ """ Method not supported for this class.
716
+
726
717
 
727
- @available_if(_is_fit_transform_method_enabled()) # type: ignore[misc]
728
- def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame]) -> Union[Any, npt.NDArray[Any]]:
729
- """
718
+ Raises:
719
+ TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
720
+
721
+ Args:
722
+ dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
723
+ Snowpark or Pandas DataFrame.
724
+ output_cols_prefix: Prefix for the response columns
730
725
  Returns:
731
726
  Transformed dataset.
732
727
  """
733
- self.fit(dataset)
734
- assert self._sklearn_object is not None
735
- return self._sklearn_object.embedding_
728
+ self._infer_input_output_cols(dataset)
729
+ super()._check_dataset_type(dataset)
730
+ model_trainer = ModelTrainerBuilder.build_fit_transform(
731
+ estimator=self._sklearn_object,
732
+ dataset=dataset,
733
+ input_cols=self.input_cols,
734
+ label_cols=self.label_cols,
735
+ sample_weight_col=self.sample_weight_col,
736
+ autogenerated=self._autogenerated,
737
+ subproject=_SUBPROJECT,
738
+ )
739
+ output_result, fitted_estimator = model_trainer.train_fit_transform(
740
+ drop_input_cols=self._drop_input_cols,
741
+ expected_output_cols_list=self.output_cols,
742
+ )
743
+ self._sklearn_object = fitted_estimator
744
+ self._is_fitted = True
745
+ return output_result
746
+
747
+
748
+ def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
749
+ """ Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
750
+ Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
751
+ """
752
+ output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
753
+ # The following condition is introduced for kneighbors methods, and not used in other methods
754
+ if output_cols:
755
+ output_cols = [
756
+ identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
757
+ for c in output_cols
758
+ ]
759
+ elif getattr(self._sklearn_object, "classes_", None) is None:
760
+ output_cols = [output_cols_prefix]
761
+ elif self._sklearn_object is not None:
762
+ classes = self._sklearn_object.classes_
763
+ if isinstance(classes, numpy.ndarray):
764
+ output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
765
+ elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
766
+ # If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
767
+ output_cols = []
768
+ for i, cl in enumerate(classes):
769
+ # For binary classification, there is only one output column for each class
770
+ # ndarray as the two classes are complementary.
771
+ if len(cl) == 2:
772
+ output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
773
+ else:
774
+ output_cols.extend([
775
+ f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
776
+ ])
777
+ else:
778
+ output_cols = []
779
+
780
+ # Make sure column names are valid snowflake identifiers.
781
+ assert output_cols is not None # Make MyPy happy
782
+ rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
783
+
784
+ return rv
785
+
786
+ def _align_expected_output_names(
787
+ self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
788
+ ) -> List[str]:
789
+ # in case the inferred output column names dimension is different
790
+ # we use one line of snowpark dataframe and put it into sklearn estimator using pandas
791
+ output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
792
+ output_df_columns = list(output_df_pd.columns)
793
+ output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
794
+ if self.sample_weight_col:
795
+ output_df_columns_set -= set(self.sample_weight_col)
796
+ # if the dimension of inferred output column names is correct; use it
797
+ if len(expected_output_cols_list) == len(output_df_columns_set):
798
+ return expected_output_cols_list
799
+ # otherwise, use the sklearn estimator's output
800
+ else:
801
+ return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
736
802
 
737
803
  @available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
738
804
  @telemetry.send_api_usage_telemetry(
@@ -764,24 +830,26 @@ class XGBRFRegressor(BaseTransformer):
764
830
  # are specific to the type of dataset used.
765
831
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
766
832
 
833
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
834
+
767
835
  if isinstance(dataset, DataFrame):
768
- self._deps = self._batch_inference_validate_snowpark(
769
- dataset=dataset,
770
- inference_method=inference_method,
771
- )
772
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
836
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
837
+ self._deps = self._get_dependencies()
838
+ assert isinstance(
839
+ dataset._session, Session
840
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
773
841
  transform_kwargs = dict(
774
842
  session=dataset._session,
775
843
  dependencies=self._deps,
776
- drop_input_cols = self._drop_input_cols,
844
+ drop_input_cols=self._drop_input_cols,
777
845
  expected_output_cols_type="float",
778
846
  )
847
+ expected_output_cols = self._align_expected_output_names(
848
+ inference_method, dataset, expected_output_cols, output_cols_prefix
849
+ )
779
850
 
780
851
  elif isinstance(dataset, pd.DataFrame):
781
- transform_kwargs = dict(
782
- snowpark_input_cols = self._snowpark_cols,
783
- drop_input_cols = self._drop_input_cols
784
- )
852
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
785
853
 
786
854
  transform_handlers = ModelTransformerBuilder.build(
787
855
  dataset=dataset,
@@ -793,7 +861,7 @@ class XGBRFRegressor(BaseTransformer):
793
861
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
794
862
  inference_method=inference_method,
795
863
  input_cols=self.input_cols,
796
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
864
+ expected_output_cols=expected_output_cols,
797
865
  **transform_kwargs
798
866
  )
799
867
  return output_df
@@ -823,29 +891,30 @@ class XGBRFRegressor(BaseTransformer):
823
891
  Output dataset with log probability of the sample for each class in the model.
824
892
  """
825
893
  super()._check_dataset_type(dataset)
826
- inference_method="predict_log_proba"
894
+ inference_method = "predict_log_proba"
895
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
827
896
 
828
897
  # This dictionary contains optional kwargs for batch inference. These kwargs
829
898
  # are specific to the type of dataset used.
830
899
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
831
900
 
832
901
  if isinstance(dataset, DataFrame):
833
- self._deps = self._batch_inference_validate_snowpark(
834
- dataset=dataset,
835
- inference_method=inference_method,
836
- )
837
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
902
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
903
+ self._deps = self._get_dependencies()
904
+ assert isinstance(
905
+ dataset._session, Session
906
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
838
907
  transform_kwargs = dict(
839
908
  session=dataset._session,
840
909
  dependencies=self._deps,
841
- drop_input_cols = self._drop_input_cols,
910
+ drop_input_cols=self._drop_input_cols,
842
911
  expected_output_cols_type="float",
843
912
  )
913
+ expected_output_cols = self._align_expected_output_names(
914
+ inference_method, dataset, expected_output_cols, output_cols_prefix
915
+ )
844
916
  elif isinstance(dataset, pd.DataFrame):
845
- transform_kwargs = dict(
846
- snowpark_input_cols = self._snowpark_cols,
847
- drop_input_cols = self._drop_input_cols
848
- )
917
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
849
918
 
850
919
  transform_handlers = ModelTransformerBuilder.build(
851
920
  dataset=dataset,
@@ -858,7 +927,7 @@ class XGBRFRegressor(BaseTransformer):
858
927
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
859
928
  inference_method=inference_method,
860
929
  input_cols=self.input_cols,
861
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
930
+ expected_output_cols=expected_output_cols,
862
931
  **transform_kwargs
863
932
  )
864
933
  return output_df
@@ -884,30 +953,32 @@ class XGBRFRegressor(BaseTransformer):
884
953
  Output dataset with results of the decision function for the samples in input dataset.
885
954
  """
886
955
  super()._check_dataset_type(dataset)
887
- inference_method="decision_function"
956
+ inference_method = "decision_function"
888
957
 
889
958
  # This dictionary contains optional kwargs for batch inference. These kwargs
890
959
  # are specific to the type of dataset used.
891
960
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
892
961
 
962
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
963
+
893
964
  if isinstance(dataset, DataFrame):
894
- self._deps = self._batch_inference_validate_snowpark(
895
- dataset=dataset,
896
- inference_method=inference_method,
897
- )
898
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
965
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
966
+ self._deps = self._get_dependencies()
967
+ assert isinstance(
968
+ dataset._session, Session
969
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
899
970
  transform_kwargs = dict(
900
971
  session=dataset._session,
901
972
  dependencies=self._deps,
902
- drop_input_cols = self._drop_input_cols,
973
+ drop_input_cols=self._drop_input_cols,
903
974
  expected_output_cols_type="float",
904
975
  )
976
+ expected_output_cols = self._align_expected_output_names(
977
+ inference_method, dataset, expected_output_cols, output_cols_prefix
978
+ )
905
979
 
906
980
  elif isinstance(dataset, pd.DataFrame):
907
- transform_kwargs = dict(
908
- snowpark_input_cols = self._snowpark_cols,
909
- drop_input_cols = self._drop_input_cols
910
- )
981
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
911
982
 
912
983
  transform_handlers = ModelTransformerBuilder.build(
913
984
  dataset=dataset,
@@ -920,7 +991,7 @@ class XGBRFRegressor(BaseTransformer):
920
991
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
921
992
  inference_method=inference_method,
922
993
  input_cols=self.input_cols,
923
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
994
+ expected_output_cols=expected_output_cols,
924
995
  **transform_kwargs
925
996
  )
926
997
  return output_df
@@ -949,17 +1020,17 @@ class XGBRFRegressor(BaseTransformer):
949
1020
  Output dataset with probability of the sample for each class in the model.
950
1021
  """
951
1022
  super()._check_dataset_type(dataset)
952
- inference_method="score_samples"
1023
+ inference_method = "score_samples"
953
1024
 
954
1025
  # This dictionary contains optional kwargs for batch inference. These kwargs
955
1026
  # are specific to the type of dataset used.
956
1027
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
957
1028
 
1029
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
1030
+
958
1031
  if isinstance(dataset, DataFrame):
959
- self._deps = self._batch_inference_validate_snowpark(
960
- dataset=dataset,
961
- inference_method=inference_method,
962
- )
1032
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
1033
+ self._deps = self._get_dependencies()
963
1034
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
964
1035
  transform_kwargs = dict(
965
1036
  session=dataset._session,
@@ -967,6 +1038,9 @@ class XGBRFRegressor(BaseTransformer):
967
1038
  drop_input_cols = self._drop_input_cols,
968
1039
  expected_output_cols_type="float",
969
1040
  )
1041
+ expected_output_cols = self._align_expected_output_names(
1042
+ inference_method, dataset, expected_output_cols, output_cols_prefix
1043
+ )
970
1044
 
971
1045
  elif isinstance(dataset, pd.DataFrame):
972
1046
  transform_kwargs = dict(
@@ -985,7 +1059,7 @@ class XGBRFRegressor(BaseTransformer):
985
1059
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
986
1060
  inference_method=inference_method,
987
1061
  input_cols=self.input_cols,
988
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
1062
+ expected_output_cols=expected_output_cols,
989
1063
  **transform_kwargs
990
1064
  )
991
1065
  return output_df
@@ -1020,17 +1094,15 @@ class XGBRFRegressor(BaseTransformer):
1020
1094
  transform_kwargs: ScoreKwargsTypedDict = dict()
1021
1095
 
1022
1096
  if isinstance(dataset, DataFrame):
1023
- self._deps = self._batch_inference_validate_snowpark(
1024
- dataset=dataset,
1025
- inference_method="score",
1026
- )
1097
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
1098
+ self._deps = self._get_dependencies()
1027
1099
  selected_cols = self._get_active_columns()
1028
1100
  if len(selected_cols) > 0:
1029
1101
  dataset = dataset.select(selected_cols)
1030
1102
  assert isinstance(dataset._session, Session) # keep mypy happy
1031
1103
  transform_kwargs = dict(
1032
1104
  session=dataset._session,
1033
- dependencies=["snowflake-snowpark-python"] + self._deps,
1105
+ dependencies=self._deps,
1034
1106
  score_sproc_imports=['xgboost'],
1035
1107
  )
1036
1108
  elif isinstance(dataset, pd.DataFrame):
@@ -1095,11 +1167,8 @@ class XGBRFRegressor(BaseTransformer):
1095
1167
 
1096
1168
  if isinstance(dataset, DataFrame):
1097
1169
 
1098
- self._deps = self._batch_inference_validate_snowpark(
1099
- dataset=dataset,
1100
- inference_method=inference_method,
1101
-
1102
- )
1170
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
1171
+ self._deps = self._get_dependencies()
1103
1172
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
1104
1173
  transform_kwargs = dict(
1105
1174
  session = dataset._session,
@@ -1132,50 +1201,84 @@ class XGBRFRegressor(BaseTransformer):
1132
1201
  )
1133
1202
  return output_df
1134
1203
 
1204
+
1205
+
1206
+ def to_xgboost(self) -> Any:
1207
+ """Get xgboost.XGBRFRegressor object.
1208
+ """
1209
+ if self._sklearn_object is None:
1210
+ self._sklearn_object = self._create_sklearn_object()
1211
+ return self._sklearn_object
1212
+
1213
+ def to_sklearn(self) -> Any:
1214
+ raise exceptions.SnowflakeMLException(
1215
+ error_code=error_codes.METHOD_NOT_ALLOWED,
1216
+ original_exception=AttributeError(
1217
+ modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1218
+ "to_sklearn()",
1219
+ "to_xgboost()"
1220
+ )
1221
+ ),
1222
+ )
1223
+
1224
+ def to_lightgbm(self) -> Any:
1225
+ raise exceptions.SnowflakeMLException(
1226
+ error_code=error_codes.METHOD_NOT_ALLOWED,
1227
+ original_exception=AttributeError(
1228
+ modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1229
+ "to_lightgbm()",
1230
+ "to_xgboost()"
1231
+ )
1232
+ ),
1233
+ )
1234
+
1235
+ def _get_dependencies(self) -> List[str]:
1236
+ return self._deps
1237
+
1135
1238
 
1136
- def _get_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
1239
+ def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
1137
1240
  self._model_signature_dict = dict()
1138
1241
 
1139
1242
  PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
1140
1243
 
1141
- inputs = list(_infer_signature(dataset[self.input_cols], "input"))
1244
+ inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
1142
1245
  outputs: List[BaseFeatureSpec] = []
1143
1246
  if hasattr(self, "predict"):
1144
1247
  # keep mypy happy
1145
- assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
1248
+ assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
1146
1249
  # For classifier, the type of predict is the same as the type of label
1147
- if self._sklearn_object._estimator_type == 'classifier':
1148
- # label columns is the desired type for output
1250
+ if self._sklearn_object._estimator_type == "classifier":
1251
+ # label columns is the desired type for output
1149
1252
  outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
1150
1253
  # rename the output columns
1151
1254
  outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
1152
- self._model_signature_dict["predict"] = ModelSignature(inputs,
1153
- ([] if self._drop_input_cols else inputs)
1154
- + outputs)
1255
+ self._model_signature_dict["predict"] = ModelSignature(
1256
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1257
+ )
1155
1258
  # For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
1156
1259
  # For outlier models, returns -1 for outliers and 1 for inliers.
1157
- # Clusterer returns int64 cluster labels.
1260
+ # Clusterer returns int64 cluster labels.
1158
1261
  elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
1159
1262
  outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
1160
- self._model_signature_dict["predict"] = ModelSignature(inputs,
1161
- ([] if self._drop_input_cols else inputs)
1162
- + outputs)
1163
-
1263
+ self._model_signature_dict["predict"] = ModelSignature(
1264
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1265
+ )
1266
+
1164
1267
  # For regressor, the type of predict is float64
1165
- elif self._sklearn_object._estimator_type == 'regressor':
1268
+ elif self._sklearn_object._estimator_type == "regressor":
1166
1269
  outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
1167
- self._model_signature_dict["predict"] = ModelSignature(inputs,
1168
- ([] if self._drop_input_cols else inputs)
1169
- + outputs)
1170
-
1270
+ self._model_signature_dict["predict"] = ModelSignature(
1271
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1272
+ )
1273
+
1171
1274
  for prob_func in PROB_FUNCTIONS:
1172
1275
  if hasattr(self, prob_func):
1173
1276
  output_cols_prefix: str = f"{prob_func}_"
1174
1277
  output_column_names = self._get_output_column_names(output_cols_prefix)
1175
1278
  outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
1176
- self._model_signature_dict[prob_func] = ModelSignature(inputs,
1177
- ([] if self._drop_input_cols else inputs)
1178
- + outputs)
1279
+ self._model_signature_dict[prob_func] = ModelSignature(
1280
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1281
+ )
1179
1282
 
1180
1283
  # Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
1181
1284
  items = list(self._model_signature_dict.items())
@@ -1188,10 +1291,10 @@ class XGBRFRegressor(BaseTransformer):
1188
1291
  """Returns model signature of current class.
1189
1292
 
1190
1293
  Raises:
1191
- exceptions.SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
1294
+ SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
1192
1295
 
1193
1296
  Returns:
1194
- Dict[str, ModelSignature]: each method and its input output signature
1297
+ Dict with each method and its input output signature
1195
1298
  """
1196
1299
  if self._model_signature_dict is None:
1197
1300
  raise exceptions.SnowflakeMLException(
@@ -1199,35 +1302,3 @@ class XGBRFRegressor(BaseTransformer):
1199
1302
  original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
1200
1303
  )
1201
1304
  return self._model_signature_dict
1202
-
1203
- def to_xgboost(self) -> Any:
1204
- """Get xgboost.XGBRFRegressor object.
1205
- """
1206
- if self._sklearn_object is None:
1207
- self._sklearn_object = self._create_sklearn_object()
1208
- return self._sklearn_object
1209
-
1210
- def to_sklearn(self) -> Any:
1211
- raise exceptions.SnowflakeMLException(
1212
- error_code=error_codes.METHOD_NOT_ALLOWED,
1213
- original_exception=AttributeError(
1214
- modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1215
- "to_sklearn()",
1216
- "to_xgboost()"
1217
- )
1218
- ),
1219
- )
1220
-
1221
- def to_lightgbm(self) -> Any:
1222
- raise exceptions.SnowflakeMLException(
1223
- error_code=error_codes.METHOD_NOT_ALLOWED,
1224
- original_exception=AttributeError(
1225
- modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1226
- "to_lightgbm()",
1227
- "to_xgboost()"
1228
- )
1229
- ),
1230
- )
1231
-
1232
- def _get_dependencies(self) -> List[str]:
1233
- return self._deps