python - 你好。我对 MLFlow 很陌生,想在自己的 ML 模型上实现 MLFlow 项目。但是我得到“”在入口点中找不到主要的“”
问题描述
完整的错误信息如下:
ERROR mlflow.cli: === Could not find main among entry points [] or interpret main as a runnable script. Supported script file extensions: ['.py', '.sh'] ===
我也尝试了这里建议的解决方案https://github.com/mlflow/mlflow/issues/1094
,但结果是一样的。
下面我提供了运行MLflow
项目所需的所有文件。
conda.yaml
档案_
name: lightgbm-example
channels:
- conda-forge
dependencies:
- python=3.6
- pip
- pip:
- mlflow>=1.6.0
- lightgbm
- pandas
- numpy
MLProject 文件
name: lightgbm-example
conda_env: ~/Desktop/MLflow/conda.yaml
entry-points:
main:
parameters:
learning_rate: {type: float, default: 0.1}
colsample_bytree: {type: float, default: 1.0}
subsample: {type: float, default: 1.0}
command: |
python3 ~/Desktop/MLflow/Test.py \
--learning-rate={learning_rate} \
--colsample-bytree={colsample_bytree} \
--subsample={subsample}
我的 Test.py 文件
import pandas as pd
import lightgbm as lgb
import numpy as np
import mlflow
import mlflow.lightgbm
import argparse
from sklearn.metrics import accuracy_score, confusion_matrix
def parse_args():
parser = argparse.ArgumentParser(description="LightGBM example")
parser.add_argument(
"--learning-rate",
type=float,
default=0.1,
help="learning rate to update step size at each boosting step (default: 0.3)",
)
parser.add_argument(
"--colsample-bytree",
type=float,
default=1.0,
help="subsample ratio of columns when constructing each tree (default: 1.0)",
)
parser.add_argument(
"--subsample",
type=float,
default=1.0,
help="subsample ratio of the training instances (default: 1.0)",
)
return parser.parse_args()
def find_specificity(c_matrix):
specificity = c_matrix[1][1]/(c_matrix[1][1]+c_matrix[0][1])
return specificity
def main():
args = parse_args()
df = pd.read_csv('~/Desktop/MLflow/Churn_demo.csv')
train_df = df.sample(frac=0.8, random_state=25)
test_df = df.drop(train_df.index)
train_df.drop(['subscriberid'], axis = 1, inplace = True)
test_df.drop(['subscriberid'], axis = 1, inplace = True)
TrainX = train_df.iloc[:,:-1]
TrainY = train_df.iloc[:,-1]
TestX = test_df.iloc[:,:-1]
TestY = test_df.iloc[:,-1]
mlflow.lightgbm.autolog()
dtrain = lgb.Dataset(TrainX, label=TrainY)
dtest = lgb.Dataset(TestX, label=TestY)
with mlflow.start_run():
parameters = {
'objective': 'binary',
'device':'cpu',
'num_threads': 6,
'num_leaves': 127,
'metric' : 'binary',
'lambda_l2':5,
'max_bin': 63,
'bin_construct_sample_cnt' :2*1000*1000,
'learning_rate': args.learning_rate,
'colsample_bytree': args.colsample_bytree,
'subsample': args.subsample,
'verbose': 1
}
model = lgb.train(parameters,
dtrain,
valid_sets=dtest,
num_boost_round=10000,
early_stopping_rounds=10)
y_proba=model.predict(TestX)
pred=np.where(y_proba>0.25,1,0)
conf_matrix = confusion_matrix(TestY,pred)
specificity = find_specificity(conf_matrix)
acc = accuracy_score(TestY,pred)
mlflow.log_metric({"specificity" : specificity, "accuracy" : acc})
if __name__ == "__main__":
main()
解决方案
幸运的是,我已经解决了我的问题。我列出了相同错误的一些解决方案,如果您将来遇到同样的问题,它们可以帮助您。
- 文件名。文件名应与 MLFlow 文档中建议的相同
https://mlflow.org/
。例如 notconda.yamp
, butconda.yaml
, 因为在https://github.com/mlflow/mlflow/issues/3856
- 该
conda.yaml
文件不支持 Tab,请考虑使用空格代替 - 在 MLProject 文件名中,“P”在 MLFlow 1.4 之前应为大写。但是后来的版本没关系,正如那里解释的那样
https://github.com/mlflow/mlflow/issues/1094
- (在我的情况下) MLProject 文件是空间敏感的。让
https://github.com/mlflow/mlflow/tree/master/examples
GitHub 示例指导您。
推荐阅读
- c# - 如何计算 EDF 文件的持续时间(时间)?
- php - 将php对象转换为日期格式
- javascript - 如何使用 javascript 显示自定义字段编号
- angular - 如何将 Angular 5 应用程序添加到 Visual Studio 中的解决方案?
- java - Java:堆栈(从一个堆栈中删除一个元素并通过用户输入哪个堆栈到哪个堆栈添加到另一个堆栈
- javascript - 将每个记录的一个关系的值乘以另一个关系的总和
- r - 在使用 stringi 包之前将字符串的文本语料库转换为字符向量
- python - Python正则表达式帮助:)?
- php - 使用php上传文件时遇到错误
- webpack - 有没有办法获取 WebPack 链接的绝对路径?