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
@@ -34,6 +34,15 @@ from snowflake.ml.modeling._internal.transformer_protocols import (
34
34
  BatchInferenceKwargsTypedDict,
35
35
  ScoreKwargsTypedDict
36
36
  )
37
+ from snowflake.ml.model._signatures import utils as model_signature_utils
38
+ from snowflake.ml.model.model_signature import (
39
+ BaseFeatureSpec,
40
+ DataType,
41
+ FeatureSpec,
42
+ ModelSignature,
43
+ _infer_signature,
44
+ _rename_signature_with_snowflake_identifiers,
45
+ )
37
46
 
38
47
  from snowflake.ml.modeling._internal.model_transformer_builder import ModelTransformerBuilder
39
48
 
@@ -44,16 +53,6 @@ from snowflake.ml.modeling._internal.estimator_utils import (
44
53
  validate_sklearn_args,
45
54
  )
46
55
 
47
- from snowflake.ml.model.model_signature import (
48
- DataType,
49
- FeatureSpec,
50
- ModelSignature,
51
- _infer_signature,
52
- _rename_signature_with_snowflake_identifiers,
53
- BaseFeatureSpec,
54
- )
55
- from snowflake.ml.model._signatures import utils as model_signature_utils
56
-
57
56
  _PROJECT = "ModelDevelopment"
58
57
  # Derive subproject from module name by removing "sklearn"
59
58
  # and converting module name from underscore to CamelCase
@@ -62,12 +61,6 @@ _SUBPROJECT = "".join([s.capitalize() for s in "sklearn.feature_selection".repla
62
61
 
63
62
  DATAFRAME_TYPE = Union[DataFrame, pd.DataFrame]
64
63
 
65
- def _is_fit_transform_method_enabled() -> Callable[[Any], bool]:
66
- def check(self: BaseTransformer) -> TypeGuard[Callable[..., object]]:
67
- return False and callable(getattr(self._sklearn_object, "fit_transform", None))
68
- return check
69
-
70
-
71
64
  class GenericUnivariateSelect(BaseTransformer):
72
65
  r"""Univariate feature selector with configurable strategy
73
66
  For more details on this class, see [sklearn.feature_selection.GenericUnivariateSelect]
@@ -209,12 +202,7 @@ class GenericUnivariateSelect(BaseTransformer):
209
202
  )
210
203
  return selected_cols
211
204
 
212
- @telemetry.send_api_usage_telemetry(
213
- project=_PROJECT,
214
- subproject=_SUBPROJECT,
215
- custom_tags=dict([("autogen", True)]),
216
- )
217
- def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "GenericUnivariateSelect":
205
+ def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "GenericUnivariateSelect":
218
206
  """Run score function on (X, y) and get the appropriate features
219
207
  For more details on this function, see [sklearn.feature_selection.GenericUnivariateSelect.fit]
220
208
  (https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.GenericUnivariateSelect.html#sklearn.feature_selection.GenericUnivariateSelect.fit)
@@ -241,12 +229,14 @@ class GenericUnivariateSelect(BaseTransformer):
241
229
 
242
230
  self._snowpark_cols = dataset.select(self.input_cols).columns
243
231
 
244
- # If we are already in a stored procedure, no need to kick off another one.
232
+ # If we are already in a stored procedure, no need to kick off another one.
245
233
  if SNOWML_SPROC_ENV in os.environ:
246
234
  statement_params = telemetry.get_function_usage_statement_params(
247
235
  project=_PROJECT,
248
236
  subproject=_SUBPROJECT,
249
- function_name=telemetry.get_statement_params_full_func_name(inspect.currentframe(), GenericUnivariateSelect.__class__.__name__),
237
+ function_name=telemetry.get_statement_params_full_func_name(
238
+ inspect.currentframe(), GenericUnivariateSelect.__class__.__name__
239
+ ),
250
240
  api_calls=[Session.call],
251
241
  custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
252
242
  )
@@ -267,27 +257,24 @@ class GenericUnivariateSelect(BaseTransformer):
267
257
  )
268
258
  self._sklearn_object = model_trainer.train()
269
259
  self._is_fitted = True
270
- self._get_model_signatures(dataset)
260
+ self._generate_model_signatures(dataset)
271
261
  return self
272
262
 
273
263
  def _batch_inference_validate_snowpark(
274
264
  self,
275
265
  dataset: DataFrame,
276
266
  inference_method: str,
277
- ) -> List[str]:
278
- """Util method to run validate that batch inference can be run on a snowpark dataframe and
279
- return the available package that exists in the snowflake anaconda channel
267
+ ) -> None:
268
+ """Util method to run validate that batch inference can be run on a snowpark dataframe.
280
269
 
281
270
  Args:
282
271
  dataset: snowpark dataframe
283
272
  inference_method: the inference method such as predict, score...
284
-
273
+
285
274
  Raises:
286
275
  SnowflakeMLException: If the estimator is not fitted, raise error
287
276
  SnowflakeMLException: If the session is None, raise error
288
277
 
289
- Returns:
290
- A list of available package that exists in the snowflake anaconda channel
291
278
  """
292
279
  if not self._is_fitted:
293
280
  raise exceptions.SnowflakeMLException(
@@ -305,9 +292,7 @@ class GenericUnivariateSelect(BaseTransformer):
305
292
  "Session must not specified for snowpark dataset."
306
293
  ),
307
294
  )
308
- # Validate that key package version in user workspace are supported in snowflake conda channel
309
- return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
310
- pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
295
+
311
296
 
312
297
  @available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
313
298
  @telemetry.send_api_usage_telemetry(
@@ -341,7 +326,9 @@ class GenericUnivariateSelect(BaseTransformer):
341
326
  # when it is classifier, infer the datatype from label columns
342
327
  if expected_type_inferred == "" and 'predict' in self.model_signatures:
343
328
  # Batch inference takes a single expected output column type. Use the first columns type for now.
344
- label_cols_signatures = [row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols]
329
+ label_cols_signatures = [
330
+ row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
331
+ ]
345
332
  if len(label_cols_signatures) == 0:
346
333
  error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
347
334
  raise exceptions.SnowflakeMLException(
@@ -349,25 +336,23 @@ class GenericUnivariateSelect(BaseTransformer):
349
336
  original_exception=ValueError(error_str),
350
337
  )
351
338
 
352
- expected_type_inferred = convert_sp_to_sf_type(
353
- label_cols_signatures[0].as_snowpark_type()
354
- )
339
+ expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
355
340
 
356
- self._deps = self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
357
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
341
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
342
+ self._deps = self._get_dependencies()
343
+ assert isinstance(
344
+ dataset._session, Session
345
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
358
346
 
359
347
  transform_kwargs = dict(
360
- session = dataset._session,
361
- dependencies = self._deps,
362
- drop_input_cols = self._drop_input_cols,
363
- expected_output_cols_type = expected_type_inferred,
348
+ session=dataset._session,
349
+ dependencies=self._deps,
350
+ drop_input_cols=self._drop_input_cols,
351
+ expected_output_cols_type=expected_type_inferred,
364
352
  )
365
353
 
366
354
  elif isinstance(dataset, pd.DataFrame):
367
- transform_kwargs = dict(
368
- snowpark_input_cols = self._snowpark_cols,
369
- drop_input_cols = self._drop_input_cols
370
- )
355
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
371
356
 
372
357
  transform_handlers = ModelTransformerBuilder.build(
373
358
  dataset=dataset,
@@ -409,7 +394,7 @@ class GenericUnivariateSelect(BaseTransformer):
409
394
  Transformed dataset.
410
395
  """
411
396
  super()._check_dataset_type(dataset)
412
- inference_method="transform"
397
+ inference_method = "transform"
413
398
 
414
399
  # This dictionary contains optional kwargs for batch inference. These kwargs
415
400
  # are specific to the type of dataset used.
@@ -439,24 +424,19 @@ class GenericUnivariateSelect(BaseTransformer):
439
424
  if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
440
425
  expected_dtype = convert_sp_to_sf_type(output_types[0])
441
426
 
442
- self._deps = self._batch_inference_validate_snowpark(
443
- dataset=dataset,
444
- inference_method=inference_method,
445
- )
427
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
428
+ self._deps = self._get_dependencies()
446
429
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
447
430
 
448
431
  transform_kwargs = dict(
449
- session = dataset._session,
450
- dependencies = self._deps,
451
- drop_input_cols = self._drop_input_cols,
452
- expected_output_cols_type = expected_dtype,
432
+ session=dataset._session,
433
+ dependencies=self._deps,
434
+ drop_input_cols=self._drop_input_cols,
435
+ expected_output_cols_type=expected_dtype,
453
436
  )
454
437
 
455
438
  elif isinstance(dataset, pd.DataFrame):
456
- transform_kwargs = dict(
457
- snowpark_input_cols = self._snowpark_cols,
458
- drop_input_cols = self._drop_input_cols
459
- )
439
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
460
440
 
461
441
  transform_handlers = ModelTransformerBuilder.build(
462
442
  dataset=dataset,
@@ -475,7 +455,11 @@ class GenericUnivariateSelect(BaseTransformer):
475
455
  return output_df
476
456
 
477
457
  @available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
478
- def fit_predict(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_predict_",) -> Union[DataFrame, pd.DataFrame]:
458
+ def fit_predict(
459
+ self,
460
+ dataset: Union[DataFrame, pd.DataFrame],
461
+ output_cols_prefix: str = "fit_predict_",
462
+ ) -> Union[DataFrame, pd.DataFrame]:
479
463
  """ Method not supported for this class.
480
464
 
481
465
 
@@ -500,22 +484,106 @@ class GenericUnivariateSelect(BaseTransformer):
500
484
  )
501
485
  output_result, fitted_estimator = model_trainer.train_fit_predict(
502
486
  drop_input_cols=self._drop_input_cols,
503
- expected_output_cols_list=self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix),
487
+ expected_output_cols_list=(
488
+ self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
489
+ ),
504
490
  )
505
491
  self._sklearn_object = fitted_estimator
506
492
  self._is_fitted = True
507
493
  return output_result
508
494
 
495
+
496
+ @available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
497
+ def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
498
+ """ Fit to data, then transform it
499
+ For more details on this function, see [sklearn.feature_selection.GenericUnivariateSelect.fit_transform]
500
+ (https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.GenericUnivariateSelect.html#sklearn.feature_selection.GenericUnivariateSelect.fit_transform)
501
+
502
+
503
+ Raises:
504
+ TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
509
505
 
510
- @available_if(_is_fit_transform_method_enabled()) # type: ignore[misc]
511
- def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame]) -> Union[Any, npt.NDArray[Any]]:
512
- """
506
+ Args:
507
+ dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
508
+ Snowpark or Pandas DataFrame.
509
+ output_cols_prefix: Prefix for the response columns
513
510
  Returns:
514
511
  Transformed dataset.
515
512
  """
516
- self.fit(dataset)
517
- assert self._sklearn_object is not None
518
- return self._sklearn_object.embedding_
513
+ self._infer_input_output_cols(dataset)
514
+ super()._check_dataset_type(dataset)
515
+ model_trainer = ModelTrainerBuilder.build_fit_transform(
516
+ estimator=self._sklearn_object,
517
+ dataset=dataset,
518
+ input_cols=self.input_cols,
519
+ label_cols=self.label_cols,
520
+ sample_weight_col=self.sample_weight_col,
521
+ autogenerated=self._autogenerated,
522
+ subproject=_SUBPROJECT,
523
+ )
524
+ output_result, fitted_estimator = model_trainer.train_fit_transform(
525
+ drop_input_cols=self._drop_input_cols,
526
+ expected_output_cols_list=self.output_cols,
527
+ )
528
+ self._sklearn_object = fitted_estimator
529
+ self._is_fitted = True
530
+ return output_result
531
+
532
+
533
+ def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
534
+ """ Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
535
+ Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
536
+ """
537
+ output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
538
+ # The following condition is introduced for kneighbors methods, and not used in other methods
539
+ if output_cols:
540
+ output_cols = [
541
+ identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
542
+ for c in output_cols
543
+ ]
544
+ elif getattr(self._sklearn_object, "classes_", None) is None:
545
+ output_cols = [output_cols_prefix]
546
+ elif self._sklearn_object is not None:
547
+ classes = self._sklearn_object.classes_
548
+ if isinstance(classes, numpy.ndarray):
549
+ output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
550
+ elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
551
+ # If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
552
+ output_cols = []
553
+ for i, cl in enumerate(classes):
554
+ # For binary classification, there is only one output column for each class
555
+ # ndarray as the two classes are complementary.
556
+ if len(cl) == 2:
557
+ output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
558
+ else:
559
+ output_cols.extend([
560
+ f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
561
+ ])
562
+ else:
563
+ output_cols = []
564
+
565
+ # Make sure column names are valid snowflake identifiers.
566
+ assert output_cols is not None # Make MyPy happy
567
+ rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
568
+
569
+ return rv
570
+
571
+ def _align_expected_output_names(
572
+ self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
573
+ ) -> List[str]:
574
+ # in case the inferred output column names dimension is different
575
+ # we use one line of snowpark dataframe and put it into sklearn estimator using pandas
576
+ output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
577
+ output_df_columns = list(output_df_pd.columns)
578
+ output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
579
+ if self.sample_weight_col:
580
+ output_df_columns_set -= set(self.sample_weight_col)
581
+ # if the dimension of inferred output column names is correct; use it
582
+ if len(expected_output_cols_list) == len(output_df_columns_set):
583
+ return expected_output_cols_list
584
+ # otherwise, use the sklearn estimator's output
585
+ else:
586
+ return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
519
587
 
520
588
  @available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
521
589
  @telemetry.send_api_usage_telemetry(
@@ -547,24 +615,26 @@ class GenericUnivariateSelect(BaseTransformer):
547
615
  # are specific to the type of dataset used.
548
616
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
549
617
 
618
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
619
+
550
620
  if isinstance(dataset, DataFrame):
551
- self._deps = self._batch_inference_validate_snowpark(
552
- dataset=dataset,
553
- inference_method=inference_method,
554
- )
555
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
621
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
622
+ self._deps = self._get_dependencies()
623
+ assert isinstance(
624
+ dataset._session, Session
625
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
556
626
  transform_kwargs = dict(
557
627
  session=dataset._session,
558
628
  dependencies=self._deps,
559
- drop_input_cols = self._drop_input_cols,
629
+ drop_input_cols=self._drop_input_cols,
560
630
  expected_output_cols_type="float",
561
631
  )
632
+ expected_output_cols = self._align_expected_output_names(
633
+ inference_method, dataset, expected_output_cols, output_cols_prefix
634
+ )
562
635
 
563
636
  elif isinstance(dataset, pd.DataFrame):
564
- transform_kwargs = dict(
565
- snowpark_input_cols = self._snowpark_cols,
566
- drop_input_cols = self._drop_input_cols
567
- )
637
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
568
638
 
569
639
  transform_handlers = ModelTransformerBuilder.build(
570
640
  dataset=dataset,
@@ -576,7 +646,7 @@ class GenericUnivariateSelect(BaseTransformer):
576
646
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
577
647
  inference_method=inference_method,
578
648
  input_cols=self.input_cols,
579
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
649
+ expected_output_cols=expected_output_cols,
580
650
  **transform_kwargs
581
651
  )
582
652
  return output_df
@@ -606,29 +676,30 @@ class GenericUnivariateSelect(BaseTransformer):
606
676
  Output dataset with log probability of the sample for each class in the model.
607
677
  """
608
678
  super()._check_dataset_type(dataset)
609
- inference_method="predict_log_proba"
679
+ inference_method = "predict_log_proba"
680
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
610
681
 
611
682
  # This dictionary contains optional kwargs for batch inference. These kwargs
612
683
  # are specific to the type of dataset used.
613
684
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
614
685
 
615
686
  if isinstance(dataset, DataFrame):
616
- self._deps = self._batch_inference_validate_snowpark(
617
- dataset=dataset,
618
- inference_method=inference_method,
619
- )
620
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
687
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
688
+ self._deps = self._get_dependencies()
689
+ assert isinstance(
690
+ dataset._session, Session
691
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
621
692
  transform_kwargs = dict(
622
693
  session=dataset._session,
623
694
  dependencies=self._deps,
624
- drop_input_cols = self._drop_input_cols,
695
+ drop_input_cols=self._drop_input_cols,
625
696
  expected_output_cols_type="float",
626
697
  )
698
+ expected_output_cols = self._align_expected_output_names(
699
+ inference_method, dataset, expected_output_cols, output_cols_prefix
700
+ )
627
701
  elif isinstance(dataset, pd.DataFrame):
628
- transform_kwargs = dict(
629
- snowpark_input_cols = self._snowpark_cols,
630
- drop_input_cols = self._drop_input_cols
631
- )
702
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
632
703
 
633
704
  transform_handlers = ModelTransformerBuilder.build(
634
705
  dataset=dataset,
@@ -641,7 +712,7 @@ class GenericUnivariateSelect(BaseTransformer):
641
712
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
642
713
  inference_method=inference_method,
643
714
  input_cols=self.input_cols,
644
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
715
+ expected_output_cols=expected_output_cols,
645
716
  **transform_kwargs
646
717
  )
647
718
  return output_df
@@ -667,30 +738,32 @@ class GenericUnivariateSelect(BaseTransformer):
667
738
  Output dataset with results of the decision function for the samples in input dataset.
668
739
  """
669
740
  super()._check_dataset_type(dataset)
670
- inference_method="decision_function"
741
+ inference_method = "decision_function"
671
742
 
672
743
  # This dictionary contains optional kwargs for batch inference. These kwargs
673
744
  # are specific to the type of dataset used.
674
745
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
675
746
 
747
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
748
+
676
749
  if isinstance(dataset, DataFrame):
677
- self._deps = self._batch_inference_validate_snowpark(
678
- dataset=dataset,
679
- inference_method=inference_method,
680
- )
681
- assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
750
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
751
+ self._deps = self._get_dependencies()
752
+ assert isinstance(
753
+ dataset._session, Session
754
+ ) # mypy does not recognize the check in _batch_inference_validate_snowpark()
682
755
  transform_kwargs = dict(
683
756
  session=dataset._session,
684
757
  dependencies=self._deps,
685
- drop_input_cols = self._drop_input_cols,
758
+ drop_input_cols=self._drop_input_cols,
686
759
  expected_output_cols_type="float",
687
760
  )
761
+ expected_output_cols = self._align_expected_output_names(
762
+ inference_method, dataset, expected_output_cols, output_cols_prefix
763
+ )
688
764
 
689
765
  elif isinstance(dataset, pd.DataFrame):
690
- transform_kwargs = dict(
691
- snowpark_input_cols = self._snowpark_cols,
692
- drop_input_cols = self._drop_input_cols
693
- )
766
+ transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
694
767
 
695
768
  transform_handlers = ModelTransformerBuilder.build(
696
769
  dataset=dataset,
@@ -703,7 +776,7 @@ class GenericUnivariateSelect(BaseTransformer):
703
776
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
704
777
  inference_method=inference_method,
705
778
  input_cols=self.input_cols,
706
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
779
+ expected_output_cols=expected_output_cols,
707
780
  **transform_kwargs
708
781
  )
709
782
  return output_df
@@ -732,17 +805,17 @@ class GenericUnivariateSelect(BaseTransformer):
732
805
  Output dataset with probability of the sample for each class in the model.
733
806
  """
734
807
  super()._check_dataset_type(dataset)
735
- inference_method="score_samples"
808
+ inference_method = "score_samples"
736
809
 
737
810
  # This dictionary contains optional kwargs for batch inference. These kwargs
738
811
  # are specific to the type of dataset used.
739
812
  transform_kwargs: BatchInferenceKwargsTypedDict = dict()
740
813
 
814
+ expected_output_cols = self._get_output_column_names(output_cols_prefix)
815
+
741
816
  if isinstance(dataset, DataFrame):
742
- self._deps = self._batch_inference_validate_snowpark(
743
- dataset=dataset,
744
- inference_method=inference_method,
745
- )
817
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
818
+ self._deps = self._get_dependencies()
746
819
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
747
820
  transform_kwargs = dict(
748
821
  session=dataset._session,
@@ -750,6 +823,9 @@ class GenericUnivariateSelect(BaseTransformer):
750
823
  drop_input_cols = self._drop_input_cols,
751
824
  expected_output_cols_type="float",
752
825
  )
826
+ expected_output_cols = self._align_expected_output_names(
827
+ inference_method, dataset, expected_output_cols, output_cols_prefix
828
+ )
753
829
 
754
830
  elif isinstance(dataset, pd.DataFrame):
755
831
  transform_kwargs = dict(
@@ -768,7 +844,7 @@ class GenericUnivariateSelect(BaseTransformer):
768
844
  output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
769
845
  inference_method=inference_method,
770
846
  input_cols=self.input_cols,
771
- expected_output_cols=self._get_output_column_names(output_cols_prefix),
847
+ expected_output_cols=expected_output_cols,
772
848
  **transform_kwargs
773
849
  )
774
850
  return output_df
@@ -801,17 +877,15 @@ class GenericUnivariateSelect(BaseTransformer):
801
877
  transform_kwargs: ScoreKwargsTypedDict = dict()
802
878
 
803
879
  if isinstance(dataset, DataFrame):
804
- self._deps = self._batch_inference_validate_snowpark(
805
- dataset=dataset,
806
- inference_method="score",
807
- )
880
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
881
+ self._deps = self._get_dependencies()
808
882
  selected_cols = self._get_active_columns()
809
883
  if len(selected_cols) > 0:
810
884
  dataset = dataset.select(selected_cols)
811
885
  assert isinstance(dataset._session, Session) # keep mypy happy
812
886
  transform_kwargs = dict(
813
887
  session=dataset._session,
814
- dependencies=["snowflake-snowpark-python"] + self._deps,
888
+ dependencies=self._deps,
815
889
  score_sproc_imports=['sklearn'],
816
890
  )
817
891
  elif isinstance(dataset, pd.DataFrame):
@@ -876,11 +950,8 @@ class GenericUnivariateSelect(BaseTransformer):
876
950
 
877
951
  if isinstance(dataset, DataFrame):
878
952
 
879
- self._deps = self._batch_inference_validate_snowpark(
880
- dataset=dataset,
881
- inference_method=inference_method,
882
-
883
- )
953
+ self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
954
+ self._deps = self._get_dependencies()
884
955
  assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
885
956
  transform_kwargs = dict(
886
957
  session = dataset._session,
@@ -913,50 +984,84 @@ class GenericUnivariateSelect(BaseTransformer):
913
984
  )
914
985
  return output_df
915
986
 
987
+
988
+
989
+ def to_sklearn(self) -> Any:
990
+ """Get sklearn.feature_selection.GenericUnivariateSelect object.
991
+ """
992
+ if self._sklearn_object is None:
993
+ self._sklearn_object = self._create_sklearn_object()
994
+ return self._sklearn_object
995
+
996
+ def to_xgboost(self) -> Any:
997
+ raise exceptions.SnowflakeMLException(
998
+ error_code=error_codes.METHOD_NOT_ALLOWED,
999
+ original_exception=AttributeError(
1000
+ modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1001
+ "to_xgboost()",
1002
+ "to_sklearn()"
1003
+ )
1004
+ ),
1005
+ )
916
1006
 
917
- def _get_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
1007
+ def to_lightgbm(self) -> Any:
1008
+ raise exceptions.SnowflakeMLException(
1009
+ error_code=error_codes.METHOD_NOT_ALLOWED,
1010
+ original_exception=AttributeError(
1011
+ modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1012
+ "to_lightgbm()",
1013
+ "to_sklearn()"
1014
+ )
1015
+ ),
1016
+ )
1017
+
1018
+ def _get_dependencies(self) -> List[str]:
1019
+ return self._deps
1020
+
1021
+
1022
+ def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
918
1023
  self._model_signature_dict = dict()
919
1024
 
920
1025
  PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
921
1026
 
922
- inputs = list(_infer_signature(dataset[self.input_cols], "input"))
1027
+ inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
923
1028
  outputs: List[BaseFeatureSpec] = []
924
1029
  if hasattr(self, "predict"):
925
1030
  # keep mypy happy
926
- assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
1031
+ assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
927
1032
  # For classifier, the type of predict is the same as the type of label
928
- if self._sklearn_object._estimator_type == 'classifier':
929
- # label columns is the desired type for output
1033
+ if self._sklearn_object._estimator_type == "classifier":
1034
+ # label columns is the desired type for output
930
1035
  outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
931
1036
  # rename the output columns
932
1037
  outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
933
- self._model_signature_dict["predict"] = ModelSignature(inputs,
934
- ([] if self._drop_input_cols else inputs)
935
- + outputs)
1038
+ self._model_signature_dict["predict"] = ModelSignature(
1039
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1040
+ )
936
1041
  # For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
937
1042
  # For outlier models, returns -1 for outliers and 1 for inliers.
938
- # Clusterer returns int64 cluster labels.
1043
+ # Clusterer returns int64 cluster labels.
939
1044
  elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
940
1045
  outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
941
- self._model_signature_dict["predict"] = ModelSignature(inputs,
942
- ([] if self._drop_input_cols else inputs)
943
- + outputs)
944
-
1046
+ self._model_signature_dict["predict"] = ModelSignature(
1047
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1048
+ )
1049
+
945
1050
  # For regressor, the type of predict is float64
946
- elif self._sklearn_object._estimator_type == 'regressor':
1051
+ elif self._sklearn_object._estimator_type == "regressor":
947
1052
  outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
948
- self._model_signature_dict["predict"] = ModelSignature(inputs,
949
- ([] if self._drop_input_cols else inputs)
950
- + outputs)
951
-
1053
+ self._model_signature_dict["predict"] = ModelSignature(
1054
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1055
+ )
1056
+
952
1057
  for prob_func in PROB_FUNCTIONS:
953
1058
  if hasattr(self, prob_func):
954
1059
  output_cols_prefix: str = f"{prob_func}_"
955
1060
  output_column_names = self._get_output_column_names(output_cols_prefix)
956
1061
  outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
957
- self._model_signature_dict[prob_func] = ModelSignature(inputs,
958
- ([] if self._drop_input_cols else inputs)
959
- + outputs)
1062
+ self._model_signature_dict[prob_func] = ModelSignature(
1063
+ inputs, ([] if self._drop_input_cols else inputs) + outputs
1064
+ )
960
1065
 
961
1066
  # Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
962
1067
  items = list(self._model_signature_dict.items())
@@ -969,10 +1074,10 @@ class GenericUnivariateSelect(BaseTransformer):
969
1074
  """Returns model signature of current class.
970
1075
 
971
1076
  Raises:
972
- exceptions.SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
1077
+ SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
973
1078
 
974
1079
  Returns:
975
- Dict[str, ModelSignature]: each method and its input output signature
1080
+ Dict with each method and its input output signature
976
1081
  """
977
1082
  if self._model_signature_dict is None:
978
1083
  raise exceptions.SnowflakeMLException(
@@ -980,35 +1085,3 @@ class GenericUnivariateSelect(BaseTransformer):
980
1085
  original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
981
1086
  )
982
1087
  return self._model_signature_dict
983
-
984
- def to_sklearn(self) -> Any:
985
- """Get sklearn.feature_selection.GenericUnivariateSelect object.
986
- """
987
- if self._sklearn_object is None:
988
- self._sklearn_object = self._create_sklearn_object()
989
- return self._sklearn_object
990
-
991
- def to_xgboost(self) -> Any:
992
- raise exceptions.SnowflakeMLException(
993
- error_code=error_codes.METHOD_NOT_ALLOWED,
994
- original_exception=AttributeError(
995
- modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
996
- "to_xgboost()",
997
- "to_sklearn()"
998
- )
999
- ),
1000
- )
1001
-
1002
- def to_lightgbm(self) -> Any:
1003
- raise exceptions.SnowflakeMLException(
1004
- error_code=error_codes.METHOD_NOT_ALLOWED,
1005
- original_exception=AttributeError(
1006
- modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
1007
- "to_lightgbm()",
1008
- "to_sklearn()"
1009
- )
1010
- ),
1011
- )
1012
-
1013
- def _get_dependencies(self) -> List[str]:
1014
- return self._deps