skip to Main Content

I am trying to run the following code

iter_max = 100
CC = 1
save_model = False
with mlflow.start_run(run_name=run_name, experiment_id=experiment.experiment_id, nested=True) as run:
    text_clf = Pipeline([
        ('vect', CountVectorizer()),
        ('tfidf', TfidfTransformer()),
        ('clf',LogisticRegression(max_iter=iter_max, C=CC))])
    text_clf.fit(X_train, y_train)
    run_id = mlflow.active_run().info.run_id`

But I get no model and no dataset…

enter image description here

I would like to get a model so I can register it and use it on databricks

I would like to get a model, register it and use it

2

Answers


  1. Chosen as BEST ANSWER

    thanks for the reply! it worked, but I'm facing a new challenge....I used a balanced training set, nevertheless, the model created by mlflow is overfitting towards 1 outcome. To see if I was doing something wrong, I trained the model on databricks and run it on memory, turns out it isn't overfitting so...idk what is going on..


  2. You need to register the model like below. Use below code.

    save_model = True
    with mlflow.start_run(run_name=run_name, experiment_id=experiment_id, nested=True) as run:
        text_clf = Pipeline([
            ('vect', CountVectorizer()),
            ('tfidf', TfidfTransformer()),
            ('clf', LogisticRegression(max_iter=iter_max, C=CC))
        ])
        text_clf.fit(X_train, y_train)
    
    
        if save_model:
            mlflow.sklearn.log_model(text_clf, "model")
    
        mlflow.log_param("iter_max", iter_max)
        mlflow.log_param("CC", CC)
    
        run_id = mlflow.active_run().info.run_id
    
    if save_model:
        mlflow.register_model(f"runs:/{run_id}/model", "My Registered Model")
    

    enter image description here

    Output:

    enter image description here

    You can use below code for prediction.

    import mlflow
    logged_model = 'runs:/{run_id}/model'
    
    # Load model as a PyFuncModel.
    loaded_model = mlflow.pyfunc.load_model(logged_model)
    
    # Predict on a Pandas DataFrame.
    import pandas as pd
    loaded_model.predict(pd.DataFrame(data))
    

    You can also see the model in models section.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search