admin管理员组文章数量:1122832
I am trying to predict in a python worksheet with my custom xgboost model which I deployed to Snowflake Model Registry. I am reading my table with modin pandas read_snowflake, than I am trying to use SimpleImputer but keep getting:
raise NotImplementedError(message) NotImplementedError: Snowpark pandas does not support the DataFrame interchange protocol method
__dataframe__
. To use Snowpark pandas DataFrames with third-party libraries that try to call the__dataframe__
method, please convert this Snowpark pandas DataFrame to pandas withto_pandas()
I understand it wants me to convert to native pandas but since it has limits on snowflake I do not want that since speed is cost important for this case. I do not understand why snowpark own method does not work?
Here is my code:
import snowflake.snowpark as snowpark
from snowflake.snowpark.functions import col
from snowflake.ml.registry import Registry
import modin.pandas as pd
import snowflake.snowpark.modin.plugin
from snowflake.ml.modeling.impute import SimpleImputer
def main(session: snowpark.Session):
model_registry = Registry(session=session, database_name="MY_DB", schema_name="PUBLIC")
model = model_registry.get_model('MY_MODEL').version('v1')
df=pd.read_snowflake('MY_TABLE')
numerical_features = [ MY_NUMERIC_COLUMNS]
categorical_features = [MY_CAT_COLUMNS]
for col in numerical_features:
df[col] = pd.to_numeric(df[col], errors='coerce').astype(float)
X_custom_test = df.drop(columns=[""])
X_custom_test = X_custom_test.applymap(lambda x: np.nan if pd.isna(x) else x)
imputer_num = SimpleImputer(strategy="mean", input_cols=numerical_features)
imputer_num.fit(X_custom_test)
X_custom_test = imputer_num.transform(X_custom_test)
imputer_cat = SimpleImputer(strategy="most_frequent", input_cols=categorical_features)
imputer_cat.fit(X_custom_test)
X_custom_test = imputer_cat.transform(X_custom_test)
#test_y_pred = model.run(X_custom_test, function_name="predict")
本文标签: pandasSnowflake ML SimpleImputer does not work as expectedStack Overflow
版权声明:本文标题:pandas - Snowflake ML SimpleImputer does not work as expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311745a1934847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论