首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嗨。我对MLFlow非常陌生,我想在我自己的ML模型上实现MLFlow项目。然而,我得到的是“无法在入口点中找到主要的”

嗨。我对MLFlow非常陌生,我想在我自己的ML模型上实现MLFlow项目。然而,我得到的是“无法在入口点中找到主要的”
EN

Stack Overflow用户
提问于 2021-10-07 10:24:39
回答 1查看 463关注 0票数 2

完整的错误消息如下:

代码语言:javascript
复制
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文件

代码语言:javascript
复制
name: lightgbm-example
channels:
  - conda-forge
dependencies:
  - python=3.6
  - pip
  - pip:
      - mlflow>=1.6.0
      - lightgbm
      - pandas
      - numpy

MLProject文件

代码语言:javascript
复制
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文件

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-11 10:01:04

幸运的是,我的问题已经解决了。我列举了一些同样的错误的解决方案,如果你面临同样的问题,它可以在将来帮助你。

  1. 文件名。文件名应该与MLFlow docs https://mlflow.org/中建议的相同。例如,不支持conda.yamp,但是conda.yaml,由于conda.yaml conda.yaml文件中存在不支持Tab的问题,请考虑使用MLProject文件名'P‘中的空格代替
  2. 作为MLFlow 1.4之前的大写。但是后面的版本并不重要,正如这里所解释的,https://github.com/mlflow/mlflow/issues/1094
  3. (In,my ) MLProject文件是空间敏感的。让https://github.com/mlflow/mlflow/tree/master/examples GitHub示例指导您。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69479488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档