[Python] "error": "Prediction failed: idf vector is not fitted" with Postman and CURL command

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    from sklearn.pipeline import make_pipeline
    from sklearn.feature_extraction.text import TfidfVectorizer
    from sklearn.linear_model import LogisticRegression
    import joblib

    #Make a pipeline with TFIDF vectorizier and logistic regresssion model

    pipeline = make_pipeline(
    (TfidfVectorizer()),
    LogisticRegression())

    #Train the model with pipeline set above

    pipeline.fit(train_df['cleaned_sentence'], train_df['category'])


    # Save fully fitted pipeline (includes vectorizer + model)
    joblib.dump(pipeline, "logistic_model.pkl")
    print("Saved: logistic_model.pkl")


    after saving the model, created docker image and deployed requirements, main.py and dockerfile to GCP

    # build docker and push to gcp
    gcloud builds submit --tag gcr.io/finalprojectwk5/sentiment-classifier

    # gcp deploy from google cloud shell sdk
    gcloud run deploy sentiment-classifier --image=gcr.io/finalprojectwk5/sentiment-
    classifier --platform=managed --region=us-central1 --allow-unauthenticated --
    memory=1024Mi

    # Curl command with Postman
    curl -X POST -H "Content-Type: application/json" -d "{\"text\": \"prefix great service
    confusion read crustal clear crass filthy nonsensical see coming\"}" https://sentiment-
    classifier-763594834115.us-central1.run.app/predict


    I am getting erorr "Prediction failed: idf vector is not fitted" after running the postman command

    Continue reading...

Compartilhe esta Página