如何解决Catboost python 功能重要性缺少 1 个必需的位置参数:“值”
我正在尝试计算 python 文件中的特征重要性。我通过 Spark Submit 运行这个 python 文件。由于我们的数据节点上没有安装 catboost 库,所以我在 python 中手动加载它们。
然后我加载模型文件并尝试计算特征重要性。在那里我收到以下错误
abc = model.get_feature_importance(type=catBoost.EFstrType().FeatureImportance(),prettified=True,thread_count=-1,verbose=False)
TypeError: __call__() missing 1 required positional argument: 'value'
请看下面我正在运行的代码。
def getCatBoostLibraries():
files = os.listdir(os.getcwd())
with zipfile.ZipFile(os.path.abspath("catboost zip file path"),'r') as zip_ref:
zip_ref.extractall(os.getcwd())
catboostFldrPath = os.path.abspath(os.path.join(os.getcwd(),"catboost"))
sys.path.append(catboostFldrPath)
configFile = os.path.abspath(os.path.join(catboostFldrPath,"__init__.py"))
spec = importlib.util.spec_from_file_location("catboost",configFile)
catBoost = importlib.util.module_from_spec(spec)
spec.loader.exec_module(catBoost)
return catBoost
def getFeatureImportance(modelPath):
catBoost = getCatBoostLibraries()
model = catBoost.CatBoostRegressor()
model.load_model(modelPath)
abc = model.get_feature_importance(type=catBoost.EFstrType().FeatureImportance(),verbose=False)
importance_score_df = pd.DataFrame(abc,columns=['features','featr_imp'])
return importance_score_df
解决方法
在我删除以下行中的大括号后它起作用了
abc = model.get_feature_importance(type=catBoost.EFstrType.FeatureImportance,prettified=True,thread_count=-1,verbose=False)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。