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.
- snowflake/ml/_internal/env_utils.py +77 -32
- snowflake/ml/_internal/exceptions/dataset_error_messages.py +5 -0
- snowflake/ml/_internal/exceptions/dataset_errors.py +24 -0
- snowflake/ml/_internal/exceptions/error_codes.py +3 -0
- snowflake/ml/_internal/lineage/data_source.py +10 -0
- snowflake/ml/_internal/lineage/dataset_dataframe.py +44 -0
- snowflake/ml/_internal/utils/identifier.py +3 -1
- snowflake/ml/_internal/utils/sql_identifier.py +2 -6
- snowflake/ml/dataset/__init__.py +10 -0
- snowflake/ml/dataset/dataset.py +454 -129
- snowflake/ml/dataset/dataset_factory.py +53 -0
- snowflake/ml/dataset/dataset_metadata.py +103 -0
- snowflake/ml/dataset/dataset_reader.py +202 -0
- snowflake/ml/feature_store/feature_store.py +531 -332
- snowflake/ml/feature_store/feature_view.py +40 -23
- snowflake/ml/fileset/embedded_stage_fs.py +146 -0
- snowflake/ml/fileset/sfcfs.py +56 -54
- snowflake/ml/fileset/snowfs.py +159 -0
- snowflake/ml/fileset/stage_fs.py +49 -17
- snowflake/ml/model/__init__.py +2 -2
- snowflake/ml/model/_api.py +16 -1
- snowflake/ml/model/_client/model/model_impl.py +27 -0
- snowflake/ml/model/_client/model/model_version_impl.py +137 -50
- snowflake/ml/model/_client/ops/model_ops.py +159 -40
- snowflake/ml/model/_client/sql/model.py +25 -2
- snowflake/ml/model/_client/sql/model_version.py +131 -2
- snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +5 -1
- snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +1 -0
- snowflake/ml/model/_deploy_client/snowservice/deploy.py +2 -0
- snowflake/ml/model/_deploy_client/utils/constants.py +0 -5
- snowflake/ml/model/_deploy_client/utils/snowservice_client.py +21 -50
- snowflake/ml/model/_model_composer/model_composer.py +22 -1
- snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +38 -51
- snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +19 -1
- snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
- snowflake/ml/model/_packager/model_env/model_env.py +41 -0
- snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
- snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
- snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
- snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
- snowflake/ml/model/_packager/model_meta/model_meta.py +37 -11
- snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
- snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
- snowflake/ml/model/_packager/model_packager.py +2 -5
- snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
- snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
- snowflake/ml/model/type_hints.py +21 -2
- snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
- snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
- snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +55 -3
- snowflake/ml/modeling/_internal/ml_runtime_implementations/ml_runtime_handlers.py +34 -18
- snowflake/ml/modeling/_internal/model_trainer.py +7 -0
- snowflake/ml/modeling/_internal/model_trainer_builder.py +42 -9
- snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +13 -14
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +29 -7
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +261 -16
- snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +246 -175
- snowflake/ml/modeling/cluster/affinity_propagation.py +246 -175
- snowflake/ml/modeling/cluster/agglomerative_clustering.py +246 -175
- snowflake/ml/modeling/cluster/birch.py +248 -175
- snowflake/ml/modeling/cluster/bisecting_k_means.py +248 -175
- snowflake/ml/modeling/cluster/dbscan.py +246 -175
- snowflake/ml/modeling/cluster/feature_agglomeration.py +248 -175
- snowflake/ml/modeling/cluster/k_means.py +248 -175
- snowflake/ml/modeling/cluster/mean_shift.py +246 -175
- snowflake/ml/modeling/cluster/mini_batch_k_means.py +248 -175
- snowflake/ml/modeling/cluster/optics.py +246 -175
- snowflake/ml/modeling/cluster/spectral_biclustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_clustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_coclustering.py +246 -175
- snowflake/ml/modeling/compose/column_transformer.py +248 -175
- snowflake/ml/modeling/compose/transformed_target_regressor.py +246 -175
- snowflake/ml/modeling/covariance/elliptic_envelope.py +246 -175
- snowflake/ml/modeling/covariance/empirical_covariance.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso_cv.py +246 -175
- snowflake/ml/modeling/covariance/ledoit_wolf.py +246 -175
- snowflake/ml/modeling/covariance/min_cov_det.py +246 -175
- snowflake/ml/modeling/covariance/oas.py +246 -175
- snowflake/ml/modeling/covariance/shrunk_covariance.py +246 -175
- snowflake/ml/modeling/decomposition/dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/factor_analysis.py +248 -175
- snowflake/ml/modeling/decomposition/fast_ica.py +248 -175
- snowflake/ml/modeling/decomposition/incremental_pca.py +248 -175
- snowflake/ml/modeling/decomposition/kernel_pca.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/pca.py +248 -175
- snowflake/ml/modeling/decomposition/sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/truncated_svd.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/isolation_forest.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/stacking_regressor.py +248 -175
- snowflake/ml/modeling/ensemble/voting_classifier.py +248 -175
- snowflake/ml/modeling/ensemble/voting_regressor.py +248 -175
- snowflake/ml/modeling/feature_selection/generic_univariate_select.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fdr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fpr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fwe.py +248 -175
- snowflake/ml/modeling/feature_selection/select_k_best.py +248 -175
- snowflake/ml/modeling/feature_selection/select_percentile.py +248 -175
- snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +248 -175
- snowflake/ml/modeling/feature_selection/variance_threshold.py +248 -175
- snowflake/ml/modeling/framework/_utils.py +8 -1
- snowflake/ml/modeling/framework/base.py +72 -37
- snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +246 -175
- snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +246 -175
- snowflake/ml/modeling/impute/iterative_imputer.py +248 -175
- snowflake/ml/modeling/impute/knn_imputer.py +248 -175
- snowflake/ml/modeling/impute/missing_indicator.py +248 -175
- snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/nystroem.py +248 -175
- snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +248 -175
- snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_classifier.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ard_regression.py +246 -175
- snowflake/ml/modeling/linear_model/bayesian_ridge.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/gamma_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/huber_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/lars.py +246 -175
- snowflake/ml/modeling/linear_model/lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_ic.py +246 -175
- snowflake/ml/modeling/linear_model/linear_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/perceptron.py +246 -175
- snowflake/ml/modeling/linear_model/poisson_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ransac_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ridge.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_cv.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/theil_sen_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/tweedie_regressor.py +246 -175
- snowflake/ml/modeling/manifold/isomap.py +248 -175
- snowflake/ml/modeling/manifold/mds.py +248 -175
- snowflake/ml/modeling/manifold/spectral_embedding.py +248 -175
- snowflake/ml/modeling/manifold/tsne.py +248 -175
- snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +246 -175
- snowflake/ml/modeling/mixture/gaussian_mixture.py +246 -175
- snowflake/ml/modeling/model_selection/grid_search_cv.py +63 -41
- snowflake/ml/modeling/model_selection/randomized_search_cv.py +80 -38
- snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/output_code_classifier.py +246 -175
- snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/categorical_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/complement_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/gaussian_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/multinomial_nb.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neighbors/kernel_density.py +246 -175
- snowflake/ml/modeling/neighbors/local_outlier_factor.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_centroid.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_neighbors.py +246 -175
- snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +248 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neural_network/bernoulli_rbm.py +248 -175
- snowflake/ml/modeling/neural_network/mlp_classifier.py +246 -175
- snowflake/ml/modeling/neural_network/mlp_regressor.py +246 -175
- snowflake/ml/modeling/pipeline/pipeline.py +517 -35
- snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
- snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
- snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
- snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
- snowflake/ml/modeling/preprocessing/one_hot_encoder.py +13 -5
- snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/polynomial_features.py +248 -175
- snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
- snowflake/ml/modeling/semi_supervised/label_propagation.py +246 -175
- snowflake/ml/modeling/semi_supervised/label_spreading.py +246 -175
- snowflake/ml/modeling/svm/linear_svc.py +246 -175
- snowflake/ml/modeling/svm/linear_svr.py +246 -175
- snowflake/ml/modeling/svm/nu_svc.py +246 -175
- snowflake/ml/modeling/svm/nu_svr.py +246 -175
- snowflake/ml/modeling/svm/svc.py +246 -175
- snowflake/ml/modeling/svm/svr.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_regressor.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_regressor.py +246 -175
- snowflake/ml/registry/model_registry.py +3 -149
- snowflake/ml/registry/registry.py +1 -1
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/METADATA +129 -57
- snowflake_ml_python-1.5.0.dist-info/RECORD +380 -0
- snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
- snowflake/ml/registry/_artifact_manager.py +0 -156
- snowflake/ml/registry/artifact.py +0 -46
- snowflake_ml_python-1.4.0.dist-info/RECORD +0 -370
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/LICENSE.txt +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/WHEEL +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/top_level.txt +0 -0
snowflake/ml/modeling/svm/svc.py
CHANGED
@@ -33,6 +33,15 @@ from snowflake.ml.modeling._internal.transformer_protocols import (
|
|
33
33
|
BatchInferenceKwargsTypedDict,
|
34
34
|
ScoreKwargsTypedDict
|
35
35
|
)
|
36
|
+
from snowflake.ml.model._signatures import utils as model_signature_utils
|
37
|
+
from snowflake.ml.model.model_signature import (
|
38
|
+
BaseFeatureSpec,
|
39
|
+
DataType,
|
40
|
+
FeatureSpec,
|
41
|
+
ModelSignature,
|
42
|
+
_infer_signature,
|
43
|
+
_rename_signature_with_snowflake_identifiers,
|
44
|
+
)
|
36
45
|
|
37
46
|
from snowflake.ml.modeling._internal.model_transformer_builder import ModelTransformerBuilder
|
38
47
|
|
@@ -43,16 +52,6 @@ from snowflake.ml.modeling._internal.estimator_utils import (
|
|
43
52
|
validate_sklearn_args,
|
44
53
|
)
|
45
54
|
|
46
|
-
from snowflake.ml.model.model_signature import (
|
47
|
-
DataType,
|
48
|
-
FeatureSpec,
|
49
|
-
ModelSignature,
|
50
|
-
_infer_signature,
|
51
|
-
_rename_signature_with_snowflake_identifiers,
|
52
|
-
BaseFeatureSpec,
|
53
|
-
)
|
54
|
-
from snowflake.ml.model._signatures import utils as model_signature_utils
|
55
|
-
|
56
55
|
_PROJECT = "ModelDevelopment"
|
57
56
|
# Derive subproject from module name by removing "sklearn"
|
58
57
|
# and converting module name from underscore to CamelCase
|
@@ -61,12 +60,6 @@ _SUBPROJECT = "".join([s.capitalize() for s in "sklearn.svm".replace("sklearn.",
|
|
61
60
|
|
62
61
|
DATAFRAME_TYPE = Union[DataFrame, pd.DataFrame]
|
63
62
|
|
64
|
-
def _is_fit_transform_method_enabled() -> Callable[[Any], bool]:
|
65
|
-
def check(self: BaseTransformer) -> TypeGuard[Callable[..., object]]:
|
66
|
-
return False and callable(getattr(self._sklearn_object, "fit_transform", None))
|
67
|
-
return check
|
68
|
-
|
69
|
-
|
70
63
|
class SVC(BaseTransformer):
|
71
64
|
r"""C-Support Vector Classification
|
72
65
|
For more details on this class, see [sklearn.svm.SVC]
|
@@ -302,12 +295,7 @@ class SVC(BaseTransformer):
|
|
302
295
|
)
|
303
296
|
return selected_cols
|
304
297
|
|
305
|
-
|
306
|
-
project=_PROJECT,
|
307
|
-
subproject=_SUBPROJECT,
|
308
|
-
custom_tags=dict([("autogen", True)]),
|
309
|
-
)
|
310
|
-
def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "SVC":
|
298
|
+
def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "SVC":
|
311
299
|
"""Fit the SVM model according to the given training data
|
312
300
|
For more details on this function, see [sklearn.svm.SVC.fit]
|
313
301
|
(https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.fit)
|
@@ -334,12 +322,14 @@ class SVC(BaseTransformer):
|
|
334
322
|
|
335
323
|
self._snowpark_cols = dataset.select(self.input_cols).columns
|
336
324
|
|
337
|
-
|
325
|
+
# If we are already in a stored procedure, no need to kick off another one.
|
338
326
|
if SNOWML_SPROC_ENV in os.environ:
|
339
327
|
statement_params = telemetry.get_function_usage_statement_params(
|
340
328
|
project=_PROJECT,
|
341
329
|
subproject=_SUBPROJECT,
|
342
|
-
function_name=telemetry.get_statement_params_full_func_name(
|
330
|
+
function_name=telemetry.get_statement_params_full_func_name(
|
331
|
+
inspect.currentframe(), SVC.__class__.__name__
|
332
|
+
),
|
343
333
|
api_calls=[Session.call],
|
344
334
|
custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
|
345
335
|
)
|
@@ -360,27 +350,24 @@ class SVC(BaseTransformer):
|
|
360
350
|
)
|
361
351
|
self._sklearn_object = model_trainer.train()
|
362
352
|
self._is_fitted = True
|
363
|
-
self.
|
353
|
+
self._generate_model_signatures(dataset)
|
364
354
|
return self
|
365
355
|
|
366
356
|
def _batch_inference_validate_snowpark(
|
367
357
|
self,
|
368
358
|
dataset: DataFrame,
|
369
359
|
inference_method: str,
|
370
|
-
) ->
|
371
|
-
"""Util method to run validate that batch inference can be run on a snowpark dataframe
|
372
|
-
return the available package that exists in the snowflake anaconda channel
|
360
|
+
) -> None:
|
361
|
+
"""Util method to run validate that batch inference can be run on a snowpark dataframe.
|
373
362
|
|
374
363
|
Args:
|
375
364
|
dataset: snowpark dataframe
|
376
365
|
inference_method: the inference method such as predict, score...
|
377
|
-
|
366
|
+
|
378
367
|
Raises:
|
379
368
|
SnowflakeMLException: If the estimator is not fitted, raise error
|
380
369
|
SnowflakeMLException: If the session is None, raise error
|
381
370
|
|
382
|
-
Returns:
|
383
|
-
A list of available package that exists in the snowflake anaconda channel
|
384
371
|
"""
|
385
372
|
if not self._is_fitted:
|
386
373
|
raise exceptions.SnowflakeMLException(
|
@@ -398,9 +385,7 @@ class SVC(BaseTransformer):
|
|
398
385
|
"Session must not specified for snowpark dataset."
|
399
386
|
),
|
400
387
|
)
|
401
|
-
|
402
|
-
return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
|
403
|
-
pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
|
388
|
+
|
404
389
|
|
405
390
|
@available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
|
406
391
|
@telemetry.send_api_usage_telemetry(
|
@@ -436,7 +421,9 @@ class SVC(BaseTransformer):
|
|
436
421
|
# when it is classifier, infer the datatype from label columns
|
437
422
|
if expected_type_inferred == "" and 'predict' in self.model_signatures:
|
438
423
|
# Batch inference takes a single expected output column type. Use the first columns type for now.
|
439
|
-
label_cols_signatures = [
|
424
|
+
label_cols_signatures = [
|
425
|
+
row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
|
426
|
+
]
|
440
427
|
if len(label_cols_signatures) == 0:
|
441
428
|
error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
|
442
429
|
raise exceptions.SnowflakeMLException(
|
@@ -444,25 +431,23 @@ class SVC(BaseTransformer):
|
|
444
431
|
original_exception=ValueError(error_str),
|
445
432
|
)
|
446
433
|
|
447
|
-
expected_type_inferred = convert_sp_to_sf_type(
|
448
|
-
label_cols_signatures[0].as_snowpark_type()
|
449
|
-
)
|
434
|
+
expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
|
450
435
|
|
451
|
-
self.
|
452
|
-
|
436
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
437
|
+
self._deps = self._get_dependencies()
|
438
|
+
assert isinstance(
|
439
|
+
dataset._session, Session
|
440
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
453
441
|
|
454
442
|
transform_kwargs = dict(
|
455
|
-
session
|
456
|
-
dependencies
|
457
|
-
drop_input_cols
|
458
|
-
expected_output_cols_type
|
443
|
+
session=dataset._session,
|
444
|
+
dependencies=self._deps,
|
445
|
+
drop_input_cols=self._drop_input_cols,
|
446
|
+
expected_output_cols_type=expected_type_inferred,
|
459
447
|
)
|
460
448
|
|
461
449
|
elif isinstance(dataset, pd.DataFrame):
|
462
|
-
transform_kwargs = dict(
|
463
|
-
snowpark_input_cols = self._snowpark_cols,
|
464
|
-
drop_input_cols = self._drop_input_cols
|
465
|
-
)
|
450
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
466
451
|
|
467
452
|
transform_handlers = ModelTransformerBuilder.build(
|
468
453
|
dataset=dataset,
|
@@ -502,7 +487,7 @@ class SVC(BaseTransformer):
|
|
502
487
|
Transformed dataset.
|
503
488
|
"""
|
504
489
|
super()._check_dataset_type(dataset)
|
505
|
-
inference_method="transform"
|
490
|
+
inference_method = "transform"
|
506
491
|
|
507
492
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
508
493
|
# are specific to the type of dataset used.
|
@@ -532,24 +517,19 @@ class SVC(BaseTransformer):
|
|
532
517
|
if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
|
533
518
|
expected_dtype = convert_sp_to_sf_type(output_types[0])
|
534
519
|
|
535
|
-
self.
|
536
|
-
|
537
|
-
inference_method=inference_method,
|
538
|
-
)
|
520
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
521
|
+
self._deps = self._get_dependencies()
|
539
522
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
540
523
|
|
541
524
|
transform_kwargs = dict(
|
542
|
-
session
|
543
|
-
dependencies
|
544
|
-
drop_input_cols
|
545
|
-
expected_output_cols_type
|
525
|
+
session=dataset._session,
|
526
|
+
dependencies=self._deps,
|
527
|
+
drop_input_cols=self._drop_input_cols,
|
528
|
+
expected_output_cols_type=expected_dtype,
|
546
529
|
)
|
547
530
|
|
548
531
|
elif isinstance(dataset, pd.DataFrame):
|
549
|
-
transform_kwargs = dict(
|
550
|
-
snowpark_input_cols = self._snowpark_cols,
|
551
|
-
drop_input_cols = self._drop_input_cols
|
552
|
-
)
|
532
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
553
533
|
|
554
534
|
transform_handlers = ModelTransformerBuilder.build(
|
555
535
|
dataset=dataset,
|
@@ -568,7 +548,11 @@ class SVC(BaseTransformer):
|
|
568
548
|
return output_df
|
569
549
|
|
570
550
|
@available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
|
571
|
-
def fit_predict(
|
551
|
+
def fit_predict(
|
552
|
+
self,
|
553
|
+
dataset: Union[DataFrame, pd.DataFrame],
|
554
|
+
output_cols_prefix: str = "fit_predict_",
|
555
|
+
) -> Union[DataFrame, pd.DataFrame]:
|
572
556
|
""" Method not supported for this class.
|
573
557
|
|
574
558
|
|
@@ -593,22 +577,104 @@ class SVC(BaseTransformer):
|
|
593
577
|
)
|
594
578
|
output_result, fitted_estimator = model_trainer.train_fit_predict(
|
595
579
|
drop_input_cols=self._drop_input_cols,
|
596
|
-
expected_output_cols_list=
|
580
|
+
expected_output_cols_list=(
|
581
|
+
self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
|
582
|
+
),
|
597
583
|
)
|
598
584
|
self._sklearn_object = fitted_estimator
|
599
585
|
self._is_fitted = True
|
600
586
|
return output_result
|
601
587
|
|
588
|
+
|
589
|
+
@available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
|
590
|
+
def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
|
591
|
+
""" Method not supported for this class.
|
592
|
+
|
602
593
|
|
603
|
-
|
604
|
-
|
605
|
-
|
594
|
+
Raises:
|
595
|
+
TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
|
596
|
+
|
597
|
+
Args:
|
598
|
+
dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
|
599
|
+
Snowpark or Pandas DataFrame.
|
600
|
+
output_cols_prefix: Prefix for the response columns
|
606
601
|
Returns:
|
607
602
|
Transformed dataset.
|
608
603
|
"""
|
609
|
-
self.
|
610
|
-
|
611
|
-
|
604
|
+
self._infer_input_output_cols(dataset)
|
605
|
+
super()._check_dataset_type(dataset)
|
606
|
+
model_trainer = ModelTrainerBuilder.build_fit_transform(
|
607
|
+
estimator=self._sklearn_object,
|
608
|
+
dataset=dataset,
|
609
|
+
input_cols=self.input_cols,
|
610
|
+
label_cols=self.label_cols,
|
611
|
+
sample_weight_col=self.sample_weight_col,
|
612
|
+
autogenerated=self._autogenerated,
|
613
|
+
subproject=_SUBPROJECT,
|
614
|
+
)
|
615
|
+
output_result, fitted_estimator = model_trainer.train_fit_transform(
|
616
|
+
drop_input_cols=self._drop_input_cols,
|
617
|
+
expected_output_cols_list=self.output_cols,
|
618
|
+
)
|
619
|
+
self._sklearn_object = fitted_estimator
|
620
|
+
self._is_fitted = True
|
621
|
+
return output_result
|
622
|
+
|
623
|
+
|
624
|
+
def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
|
625
|
+
""" Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
|
626
|
+
Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
|
627
|
+
"""
|
628
|
+
output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
|
629
|
+
# The following condition is introduced for kneighbors methods, and not used in other methods
|
630
|
+
if output_cols:
|
631
|
+
output_cols = [
|
632
|
+
identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
|
633
|
+
for c in output_cols
|
634
|
+
]
|
635
|
+
elif getattr(self._sklearn_object, "classes_", None) is None:
|
636
|
+
output_cols = [output_cols_prefix]
|
637
|
+
elif self._sklearn_object is not None:
|
638
|
+
classes = self._sklearn_object.classes_
|
639
|
+
if isinstance(classes, numpy.ndarray):
|
640
|
+
output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
|
641
|
+
elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
|
642
|
+
# If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
|
643
|
+
output_cols = []
|
644
|
+
for i, cl in enumerate(classes):
|
645
|
+
# For binary classification, there is only one output column for each class
|
646
|
+
# ndarray as the two classes are complementary.
|
647
|
+
if len(cl) == 2:
|
648
|
+
output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
|
649
|
+
else:
|
650
|
+
output_cols.extend([
|
651
|
+
f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
|
652
|
+
])
|
653
|
+
else:
|
654
|
+
output_cols = []
|
655
|
+
|
656
|
+
# Make sure column names are valid snowflake identifiers.
|
657
|
+
assert output_cols is not None # Make MyPy happy
|
658
|
+
rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
|
659
|
+
|
660
|
+
return rv
|
661
|
+
|
662
|
+
def _align_expected_output_names(
|
663
|
+
self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
|
664
|
+
) -> List[str]:
|
665
|
+
# in case the inferred output column names dimension is different
|
666
|
+
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
|
667
|
+
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
|
668
|
+
output_df_columns = list(output_df_pd.columns)
|
669
|
+
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
|
670
|
+
if self.sample_weight_col:
|
671
|
+
output_df_columns_set -= set(self.sample_weight_col)
|
672
|
+
# if the dimension of inferred output column names is correct; use it
|
673
|
+
if len(expected_output_cols_list) == len(output_df_columns_set):
|
674
|
+
return expected_output_cols_list
|
675
|
+
# otherwise, use the sklearn estimator's output
|
676
|
+
else:
|
677
|
+
return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
|
612
678
|
|
613
679
|
@available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
|
614
680
|
@telemetry.send_api_usage_telemetry(
|
@@ -642,24 +708,26 @@ class SVC(BaseTransformer):
|
|
642
708
|
# are specific to the type of dataset used.
|
643
709
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
644
710
|
|
711
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
712
|
+
|
645
713
|
if isinstance(dataset, DataFrame):
|
646
|
-
self.
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
714
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
715
|
+
self._deps = self._get_dependencies()
|
716
|
+
assert isinstance(
|
717
|
+
dataset._session, Session
|
718
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
651
719
|
transform_kwargs = dict(
|
652
720
|
session=dataset._session,
|
653
721
|
dependencies=self._deps,
|
654
|
-
drop_input_cols
|
722
|
+
drop_input_cols=self._drop_input_cols,
|
655
723
|
expected_output_cols_type="float",
|
656
724
|
)
|
725
|
+
expected_output_cols = self._align_expected_output_names(
|
726
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
727
|
+
)
|
657
728
|
|
658
729
|
elif isinstance(dataset, pd.DataFrame):
|
659
|
-
transform_kwargs = dict(
|
660
|
-
snowpark_input_cols = self._snowpark_cols,
|
661
|
-
drop_input_cols = self._drop_input_cols
|
662
|
-
)
|
730
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
663
731
|
|
664
732
|
transform_handlers = ModelTransformerBuilder.build(
|
665
733
|
dataset=dataset,
|
@@ -671,7 +739,7 @@ class SVC(BaseTransformer):
|
|
671
739
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
672
740
|
inference_method=inference_method,
|
673
741
|
input_cols=self.input_cols,
|
674
|
-
expected_output_cols=
|
742
|
+
expected_output_cols=expected_output_cols,
|
675
743
|
**transform_kwargs
|
676
744
|
)
|
677
745
|
return output_df
|
@@ -703,29 +771,30 @@ class SVC(BaseTransformer):
|
|
703
771
|
Output dataset with log probability of the sample for each class in the model.
|
704
772
|
"""
|
705
773
|
super()._check_dataset_type(dataset)
|
706
|
-
inference_method="predict_log_proba"
|
774
|
+
inference_method = "predict_log_proba"
|
775
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
707
776
|
|
708
777
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
709
778
|
# are specific to the type of dataset used.
|
710
779
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
711
780
|
|
712
781
|
if isinstance(dataset, DataFrame):
|
713
|
-
self.
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
782
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
783
|
+
self._deps = self._get_dependencies()
|
784
|
+
assert isinstance(
|
785
|
+
dataset._session, Session
|
786
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
718
787
|
transform_kwargs = dict(
|
719
788
|
session=dataset._session,
|
720
789
|
dependencies=self._deps,
|
721
|
-
drop_input_cols
|
790
|
+
drop_input_cols=self._drop_input_cols,
|
722
791
|
expected_output_cols_type="float",
|
723
792
|
)
|
793
|
+
expected_output_cols = self._align_expected_output_names(
|
794
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
795
|
+
)
|
724
796
|
elif isinstance(dataset, pd.DataFrame):
|
725
|
-
transform_kwargs = dict(
|
726
|
-
snowpark_input_cols = self._snowpark_cols,
|
727
|
-
drop_input_cols = self._drop_input_cols
|
728
|
-
)
|
797
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
729
798
|
|
730
799
|
transform_handlers = ModelTransformerBuilder.build(
|
731
800
|
dataset=dataset,
|
@@ -738,7 +807,7 @@ class SVC(BaseTransformer):
|
|
738
807
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
739
808
|
inference_method=inference_method,
|
740
809
|
input_cols=self.input_cols,
|
741
|
-
expected_output_cols=
|
810
|
+
expected_output_cols=expected_output_cols,
|
742
811
|
**transform_kwargs
|
743
812
|
)
|
744
813
|
return output_df
|
@@ -766,30 +835,32 @@ class SVC(BaseTransformer):
|
|
766
835
|
Output dataset with results of the decision function for the samples in input dataset.
|
767
836
|
"""
|
768
837
|
super()._check_dataset_type(dataset)
|
769
|
-
inference_method="decision_function"
|
838
|
+
inference_method = "decision_function"
|
770
839
|
|
771
840
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
772
841
|
# are specific to the type of dataset used.
|
773
842
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
774
843
|
|
844
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
845
|
+
|
775
846
|
if isinstance(dataset, DataFrame):
|
776
|
-
self.
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
847
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
848
|
+
self._deps = self._get_dependencies()
|
849
|
+
assert isinstance(
|
850
|
+
dataset._session, Session
|
851
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
781
852
|
transform_kwargs = dict(
|
782
853
|
session=dataset._session,
|
783
854
|
dependencies=self._deps,
|
784
|
-
drop_input_cols
|
855
|
+
drop_input_cols=self._drop_input_cols,
|
785
856
|
expected_output_cols_type="float",
|
786
857
|
)
|
858
|
+
expected_output_cols = self._align_expected_output_names(
|
859
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
860
|
+
)
|
787
861
|
|
788
862
|
elif isinstance(dataset, pd.DataFrame):
|
789
|
-
transform_kwargs = dict(
|
790
|
-
snowpark_input_cols = self._snowpark_cols,
|
791
|
-
drop_input_cols = self._drop_input_cols
|
792
|
-
)
|
863
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
793
864
|
|
794
865
|
transform_handlers = ModelTransformerBuilder.build(
|
795
866
|
dataset=dataset,
|
@@ -802,7 +873,7 @@ class SVC(BaseTransformer):
|
|
802
873
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
803
874
|
inference_method=inference_method,
|
804
875
|
input_cols=self.input_cols,
|
805
|
-
expected_output_cols=
|
876
|
+
expected_output_cols=expected_output_cols,
|
806
877
|
**transform_kwargs
|
807
878
|
)
|
808
879
|
return output_df
|
@@ -831,17 +902,17 @@ class SVC(BaseTransformer):
|
|
831
902
|
Output dataset with probability of the sample for each class in the model.
|
832
903
|
"""
|
833
904
|
super()._check_dataset_type(dataset)
|
834
|
-
inference_method="score_samples"
|
905
|
+
inference_method = "score_samples"
|
835
906
|
|
836
907
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
837
908
|
# are specific to the type of dataset used.
|
838
909
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
839
910
|
|
911
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
912
|
+
|
840
913
|
if isinstance(dataset, DataFrame):
|
841
|
-
self.
|
842
|
-
|
843
|
-
inference_method=inference_method,
|
844
|
-
)
|
914
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
915
|
+
self._deps = self._get_dependencies()
|
845
916
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
846
917
|
transform_kwargs = dict(
|
847
918
|
session=dataset._session,
|
@@ -849,6 +920,9 @@ class SVC(BaseTransformer):
|
|
849
920
|
drop_input_cols = self._drop_input_cols,
|
850
921
|
expected_output_cols_type="float",
|
851
922
|
)
|
923
|
+
expected_output_cols = self._align_expected_output_names(
|
924
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
925
|
+
)
|
852
926
|
|
853
927
|
elif isinstance(dataset, pd.DataFrame):
|
854
928
|
transform_kwargs = dict(
|
@@ -867,7 +941,7 @@ class SVC(BaseTransformer):
|
|
867
941
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
868
942
|
inference_method=inference_method,
|
869
943
|
input_cols=self.input_cols,
|
870
|
-
expected_output_cols=
|
944
|
+
expected_output_cols=expected_output_cols,
|
871
945
|
**transform_kwargs
|
872
946
|
)
|
873
947
|
return output_df
|
@@ -902,17 +976,15 @@ class SVC(BaseTransformer):
|
|
902
976
|
transform_kwargs: ScoreKwargsTypedDict = dict()
|
903
977
|
|
904
978
|
if isinstance(dataset, DataFrame):
|
905
|
-
self.
|
906
|
-
|
907
|
-
inference_method="score",
|
908
|
-
)
|
979
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
|
980
|
+
self._deps = self._get_dependencies()
|
909
981
|
selected_cols = self._get_active_columns()
|
910
982
|
if len(selected_cols) > 0:
|
911
983
|
dataset = dataset.select(selected_cols)
|
912
984
|
assert isinstance(dataset._session, Session) # keep mypy happy
|
913
985
|
transform_kwargs = dict(
|
914
986
|
session=dataset._session,
|
915
|
-
dependencies=
|
987
|
+
dependencies=self._deps,
|
916
988
|
score_sproc_imports=['sklearn'],
|
917
989
|
)
|
918
990
|
elif isinstance(dataset, pd.DataFrame):
|
@@ -977,11 +1049,8 @@ class SVC(BaseTransformer):
|
|
977
1049
|
|
978
1050
|
if isinstance(dataset, DataFrame):
|
979
1051
|
|
980
|
-
self.
|
981
|
-
|
982
|
-
inference_method=inference_method,
|
983
|
-
|
984
|
-
)
|
1052
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1053
|
+
self._deps = self._get_dependencies()
|
985
1054
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
986
1055
|
transform_kwargs = dict(
|
987
1056
|
session = dataset._session,
|
@@ -1014,50 +1083,84 @@ class SVC(BaseTransformer):
|
|
1014
1083
|
)
|
1015
1084
|
return output_df
|
1016
1085
|
|
1086
|
+
|
1087
|
+
|
1088
|
+
def to_sklearn(self) -> Any:
|
1089
|
+
"""Get sklearn.svm.SVC object.
|
1090
|
+
"""
|
1091
|
+
if self._sklearn_object is None:
|
1092
|
+
self._sklearn_object = self._create_sklearn_object()
|
1093
|
+
return self._sklearn_object
|
1094
|
+
|
1095
|
+
def to_xgboost(self) -> Any:
|
1096
|
+
raise exceptions.SnowflakeMLException(
|
1097
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1098
|
+
original_exception=AttributeError(
|
1099
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1100
|
+
"to_xgboost()",
|
1101
|
+
"to_sklearn()"
|
1102
|
+
)
|
1103
|
+
),
|
1104
|
+
)
|
1105
|
+
|
1106
|
+
def to_lightgbm(self) -> Any:
|
1107
|
+
raise exceptions.SnowflakeMLException(
|
1108
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1109
|
+
original_exception=AttributeError(
|
1110
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1111
|
+
"to_lightgbm()",
|
1112
|
+
"to_sklearn()"
|
1113
|
+
)
|
1114
|
+
),
|
1115
|
+
)
|
1116
|
+
|
1117
|
+
def _get_dependencies(self) -> List[str]:
|
1118
|
+
return self._deps
|
1119
|
+
|
1017
1120
|
|
1018
|
-
def
|
1121
|
+
def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
|
1019
1122
|
self._model_signature_dict = dict()
|
1020
1123
|
|
1021
1124
|
PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
|
1022
1125
|
|
1023
|
-
inputs = list(_infer_signature(dataset[self.input_cols], "input"))
|
1126
|
+
inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
|
1024
1127
|
outputs: List[BaseFeatureSpec] = []
|
1025
1128
|
if hasattr(self, "predict"):
|
1026
1129
|
# keep mypy happy
|
1027
|
-
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1130
|
+
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1028
1131
|
# For classifier, the type of predict is the same as the type of label
|
1029
|
-
if self._sklearn_object._estimator_type ==
|
1030
|
-
|
1132
|
+
if self._sklearn_object._estimator_type == "classifier":
|
1133
|
+
# label columns is the desired type for output
|
1031
1134
|
outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
|
1032
1135
|
# rename the output columns
|
1033
1136
|
outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
|
1034
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1035
|
-
|
1036
|
-
|
1137
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1138
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1139
|
+
)
|
1037
1140
|
# For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
|
1038
1141
|
# For outlier models, returns -1 for outliers and 1 for inliers.
|
1039
|
-
# Clusterer returns int64 cluster labels.
|
1142
|
+
# Clusterer returns int64 cluster labels.
|
1040
1143
|
elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
|
1041
1144
|
outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
|
1042
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1145
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1146
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1147
|
+
)
|
1148
|
+
|
1046
1149
|
# For regressor, the type of predict is float64
|
1047
|
-
elif self._sklearn_object._estimator_type ==
|
1150
|
+
elif self._sklearn_object._estimator_type == "regressor":
|
1048
1151
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
|
1049
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1152
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1153
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1154
|
+
)
|
1155
|
+
|
1053
1156
|
for prob_func in PROB_FUNCTIONS:
|
1054
1157
|
if hasattr(self, prob_func):
|
1055
1158
|
output_cols_prefix: str = f"{prob_func}_"
|
1056
1159
|
output_column_names = self._get_output_column_names(output_cols_prefix)
|
1057
1160
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
|
1058
|
-
self._model_signature_dict[prob_func] = ModelSignature(
|
1059
|
-
|
1060
|
-
|
1161
|
+
self._model_signature_dict[prob_func] = ModelSignature(
|
1162
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1163
|
+
)
|
1061
1164
|
|
1062
1165
|
# Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
|
1063
1166
|
items = list(self._model_signature_dict.items())
|
@@ -1070,10 +1173,10 @@ class SVC(BaseTransformer):
|
|
1070
1173
|
"""Returns model signature of current class.
|
1071
1174
|
|
1072
1175
|
Raises:
|
1073
|
-
|
1176
|
+
SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
|
1074
1177
|
|
1075
1178
|
Returns:
|
1076
|
-
Dict
|
1179
|
+
Dict with each method and its input output signature
|
1077
1180
|
"""
|
1078
1181
|
if self._model_signature_dict is None:
|
1079
1182
|
raise exceptions.SnowflakeMLException(
|
@@ -1081,35 +1184,3 @@ class SVC(BaseTransformer):
|
|
1081
1184
|
original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
|
1082
1185
|
)
|
1083
1186
|
return self._model_signature_dict
|
1084
|
-
|
1085
|
-
def to_sklearn(self) -> Any:
|
1086
|
-
"""Get sklearn.svm.SVC object.
|
1087
|
-
"""
|
1088
|
-
if self._sklearn_object is None:
|
1089
|
-
self._sklearn_object = self._create_sklearn_object()
|
1090
|
-
return self._sklearn_object
|
1091
|
-
|
1092
|
-
def to_xgboost(self) -> Any:
|
1093
|
-
raise exceptions.SnowflakeMLException(
|
1094
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1095
|
-
original_exception=AttributeError(
|
1096
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1097
|
-
"to_xgboost()",
|
1098
|
-
"to_sklearn()"
|
1099
|
-
)
|
1100
|
-
),
|
1101
|
-
)
|
1102
|
-
|
1103
|
-
def to_lightgbm(self) -> Any:
|
1104
|
-
raise exceptions.SnowflakeMLException(
|
1105
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1106
|
-
original_exception=AttributeError(
|
1107
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1108
|
-
"to_lightgbm()",
|
1109
|
-
"to_sklearn()"
|
1110
|
-
)
|
1111
|
-
),
|
1112
|
-
)
|
1113
|
-
|
1114
|
-
def _get_dependencies(self) -> List[str]:
|
1115
|
-
return self._deps
|