admin管理员组文章数量:1405890
I am training an XGBClassifier model using Snowflake ML and attempting to register it using Snowflake’s model registry. The training and evaluation steps complete successfully, but when I try to log the model using log_model()
, I get the following error:
Training Accuracy: 0.9610
Evaluation Accuracy: 0.8730
Traceback (most recent call last):
File "C:\Mas\rla_projects\Claims-AI--lodgement\code\python\src\explain\train_model.py", line 56, in <module>
model_version = native_registry.log_model(
File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\_internal\telemetry.py", line 542, in wrap
return ctx.run(execute_func_with_statement_params)
...
File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\model\_packager\model_task\model_task_utils.py", line 149, in _get_model_task
raise ValueError(f"Model type {type(model)} is not supported")
ValueError: Model type <class 'NoneType'> is not supported
Code Snippet:
from snowflake.snowpark import Session
from snowflake.ml.registry import registry
from snowflake.ml.modeling.preprocessing import StandardScaler
from snowflake.ml.modeling.impute import SimpleImputer
from snowflake.ml.modeling.pipeline import Pipeline
from snowflake.ml.modeling.xgboost import XGBClassifier
# Snowflake connection parameters
conn_params = {
"user": "<...>",
"account": "<...>",
"warehouse": "<...>",
"database": "<...>",
"schema": "<...>",
"role": "<...>",
"authenticator": "externalbrowser",
}
# Create session
session = Session.builder.configs(conn_params).create()
# Load and prepare data
all_data = session.sql("SELECT *, IFF(CLASS = 'g', 1.0, 0.0) AS LABEL FROM Gamma_Telescope_Data").drop("CLASS")
train_data, test_data = all_data.random_split(weights=[0.9, 0.1], seed=0)
# Define feature and label columns
FEATURE_COLS = [c for c in train_data.columns if c != "LABEL"]
LABEL_COLS = ["LABEL"]
# Construct pipeline
pipeline = Pipeline(steps=[
("impute", SimpleImputer(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
("scaler", StandardScaler(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
("model", XGBClassifier(input_cols=FEATURE_COLS, label_cols=LABEL_COLS))
])
# Train the pipeline
pipeline.fit(train_data)
# Register model
native_registry = registry.Registry(
session=session,
database_name=session.get_current_database(),
schema_name=session.get_current_schema()
)
model_name = "Gamma_test"
version = "V8"
model_version = native_registry.log_model(
model=pipeline, # <-- This line triggers the error
model_name=model_name,
version_name=version,
sample_input_data=test_data,
comment="Gamma test",
conda_dependencies=["snowflake-ml-python==1.7.4", "snowflake-snowpark-python==1.28.0"],
options={"enable_explainability": True}
)
Observations & Debugging Attempts:
- Pipeline Training Works –
pipeline.fit(train_data)
runs without errors. - Pipeline Predictions Work – Predictions on training and test data succeed.
- Model Explanation Works Without Pipeline – If I train an
XGBClassifier
without a pipeline, I can successfully generate predictions and explanations. - Session is Active –
session.get_current_database()
andsession.get_current_schema()
return valid values. - Feature & Label Columns Look Correct –
FEATURE_COLS
andLABEL_COLS
contain expected values.
Additional Context:
- Environment:
- Win 10
- Python 3.9
- snowflake-connector-python 3.14.0
- snowflake-ml-python 1.7.4
- snowflake-snowpark-python 1.28.0
- This example is based on Snowflake’s official documentation:
Feature Preprocessing and Training on Non-Synthetic Data - The documentation suggests using a
Pipeline
, but it does not provide an example of registering aPipeline
-based model that has explainability. - The error message suggests that the model is somehow being treated as
NoneType
when passed tolog_model()
. - As mentioned the whole pipeline can be registered and retrieved when I remove this
options={"enable_explainability": True}
from.log_model
. - This
options={"enable_explainability": True}
works if I don't have a pipeline: Snowflake ML: `There is no method with name explain available in the model`
Question:
Is it possible to register a pipeline with options={"enable_explainability": True}
?
I am training an XGBClassifier model using Snowflake ML and attempting to register it using Snowflake’s model registry. The training and evaluation steps complete successfully, but when I try to log the model using log_model()
, I get the following error:
Training Accuracy: 0.9610
Evaluation Accuracy: 0.8730
Traceback (most recent call last):
File "C:\Mas\rla_projects\Claims-AI--lodgement\code\python\src\explain\train_model.py", line 56, in <module>
model_version = native_registry.log_model(
File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\_internal\telemetry.py", line 542, in wrap
return ctx.run(execute_func_with_statement_params)
...
File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\model\_packager\model_task\model_task_utils.py", line 149, in _get_model_task
raise ValueError(f"Model type {type(model)} is not supported")
ValueError: Model type <class 'NoneType'> is not supported
Code Snippet:
from snowflake.snowpark import Session
from snowflake.ml.registry import registry
from snowflake.ml.modeling.preprocessing import StandardScaler
from snowflake.ml.modeling.impute import SimpleImputer
from snowflake.ml.modeling.pipeline import Pipeline
from snowflake.ml.modeling.xgboost import XGBClassifier
# Snowflake connection parameters
conn_params = {
"user": "<...>",
"account": "<...>",
"warehouse": "<...>",
"database": "<...>",
"schema": "<...>",
"role": "<...>",
"authenticator": "externalbrowser",
}
# Create session
session = Session.builder.configs(conn_params).create()
# Load and prepare data
all_data = session.sql("SELECT *, IFF(CLASS = 'g', 1.0, 0.0) AS LABEL FROM Gamma_Telescope_Data").drop("CLASS")
train_data, test_data = all_data.random_split(weights=[0.9, 0.1], seed=0)
# Define feature and label columns
FEATURE_COLS = [c for c in train_data.columns if c != "LABEL"]
LABEL_COLS = ["LABEL"]
# Construct pipeline
pipeline = Pipeline(steps=[
("impute", SimpleImputer(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
("scaler", StandardScaler(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
("model", XGBClassifier(input_cols=FEATURE_COLS, label_cols=LABEL_COLS))
])
# Train the pipeline
pipeline.fit(train_data)
# Register model
native_registry = registry.Registry(
session=session,
database_name=session.get_current_database(),
schema_name=session.get_current_schema()
)
model_name = "Gamma_test"
version = "V8"
model_version = native_registry.log_model(
model=pipeline, # <-- This line triggers the error
model_name=model_name,
version_name=version,
sample_input_data=test_data,
comment="Gamma test",
conda_dependencies=["snowflake-ml-python==1.7.4", "snowflake-snowpark-python==1.28.0"],
options={"enable_explainability": True}
)
Observations & Debugging Attempts:
- Pipeline Training Works –
pipeline.fit(train_data)
runs without errors. - Pipeline Predictions Work – Predictions on training and test data succeed.
- Model Explanation Works Without Pipeline – If I train an
XGBClassifier
without a pipeline, I can successfully generate predictions and explanations. - Session is Active –
session.get_current_database()
andsession.get_current_schema()
return valid values. - Feature & Label Columns Look Correct –
FEATURE_COLS
andLABEL_COLS
contain expected values.
Additional Context:
- Environment:
- Win 10
- Python 3.9
- snowflake-connector-python 3.14.0
- snowflake-ml-python 1.7.4
- snowflake-snowpark-python 1.28.0
- This example is based on Snowflake’s official documentation:
Feature Preprocessing and Training on Non-Synthetic Data - The documentation suggests using a
Pipeline
, but it does not provide an example of registering aPipeline
-based model that has explainability. - The error message suggests that the model is somehow being treated as
NoneType
when passed tolog_model()
. - As mentioned the whole pipeline can be registered and retrieved when I remove this
options={"enable_explainability": True}
from.log_model
. - This
options={"enable_explainability": True}
works if I don't have a pipeline: Snowflake ML: `There is no method with name explain available in the model`
Question:
Is it possible to register a pipeline with options={"enable_explainability": True}
?
1 Answer
Reset to default 0it seems that in the new version (1.7.5) they have added support for
- Explainability: Support native and snowml sklearn pipeline
issue I raises:
https://github/snowflakedb/snowflake-ml-python/issues/145
本文标签:
版权声明:本文标题:python - Snowflake ML Registry for Model Explainability: `ValueError: Model type <class 'NoneType'> 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744946680a2633824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论