0
def get_scores(model, model_name):


    model.fit(X_train, y_train)


    train_preds = model.predict(X_train)
    test_preds = model.predict(X_test)

    train_probs = model.predict_proba(X_train)
    test_probs = model.predict_proba(X_test)


    print('{} has training accuracy of: {}'.format(model_name, accuracy_score(y_train, train_preds)))     
    print('{} has test accuracy of: {}\n'.format(model_name, accuracy_score(y_test, test_preds)))
    print('{} has training log loss of: {}'.format(model_name, log_loss(y_train, train_probs)))
    print('{} has test log loss of: {}\n'.format(model_name, log_loss(y_test, test_probs)))

I want call multiple model later, I call one of them here:

lr_initial = LogisticRegression(n_jobs=-1)

initial_lr_train_preds, initial_lr_test_preds, initial_lr_train_probs, initial_lr_test_probs = get_scores(lr_initial, ' Preliminary Logistic Regression model')

So, I want to put all values of accuracy_score(y_train, train_preds) of each model in a variable. How can this be done

Pari
  • 1
  • 1
  • 1
    Does this answer your question? [What's the best way to return multiple values from a function in Python?](https://stackoverflow.com/questions/38508/whats-the-best-way-to-return-multiple-values-from-a-function-in-python) – kaya3 Feb 23 '20 at 19:27

1 Answers1

0

There are several ways of coding to achieve what you need. For instance you may use a dictionary of the form {y_train: (train_preds, value)} where y_train is the key and the tuple (train_preds, value) the dictionary value

Erick
  • 301
  • 3
  • 12
  • Hi could you give me more information, i want to put all test and training accuracy of all models in table to compare the result easier, so for i want to put each train result of each model in a variable, Thanks – Pari Feb 23 '20 at 20:23