Azure / azure-openai-samples

Azure OpenAI Samples is a collection of code samples illustrating how to use Azure Open AI in creating AI solution for various use cases across industries. This repository is mained by a community of volunters. We welcomed your contributions.
MIT License
524 stars 373 forks source link

Script Error in azure-openai-samples/fundamentals/document_analysis/03-classify-documents.ipynb #9

Open Mvenkateswaramma opened 1 year ago

Mvenkateswaramma commented 1 year ago

Hello azure-openai-samples/fundamentals/document_analysis/ 03-classify-documents.ipynb Below is the script that I have executed and getting an below error message. Error: NotFittedError: need to call fit or load_model beforehand, Though I have called fit/Load functions still getting an exception, could you please take a look and do the needful. Thanks

Below is the script.

import xgboost as xgb from xgboost import XGBClassifier import pickle

TRAIN = False LOAD = True

filename for trained model

fname = ('../output/models/xgb.pkl')

if TRAIN:

create model instance

xgb = XGBClassifier(n_estimators=100, max_depth=5, learning_rate=1, objective='multi:softprob')
# fit model
xgb.fit(X_train, y_train)

# save the model to disk
with open(fname, "wb") as f:
    pickle.dump(xgb, f)

load the model from disk

if LOAD: with open(fname, "rb") as f: xgb= pickle.load(f)

predict

preds = xgb.predict(X_test) probas = xgb.predict_proba(X_test)

report

report = classification_report(y_test, preds) print(report)

louis-li commented 1 year ago

@aschauhan22 can you take a look at this issue?

Farhad-Heybati commented 1 year ago

In my case I have the following error: FileNotFoundError: [Errno 2] No such file or directory: '../output/models/xgb.pkl' In fact there is no file: '../output/models/xgb.pkl'

And when I try to train the model, I get another error: ValueError: Invalid classes inferred from unique values of y. Expected: [0 1 2 3 4], got ['business' 'entertainment' 'politics' 'sport' 'tech'] I used LabelEncoder() and train the model and dump it to the folder.