Mistake 12: Not saving the results

Not saving the results after running an experiment.


Sometimes running an experiment can take considerable time and the next step is to analyze its results. Often, I find myself adding new analyses and generating new plots from my previous results. However, from time to time I realize that I am not saving my results in an experiment that has already been running for several hours. Thus, I need to stop it, write code to save the results and start again. It is a good idea to write code to save your results from the beginning. By results, I mean any information that you may need to analyze in the future including:

  • The models’ predictions and ground truth.
  • Experiment configuration: hyper-parameters, iterations, description, etc.
  • The trained models.
  • Date, start, and end time of the experiment.
  • Any other important information.

The following code shows how to save a trained model with the WINE dataset so you can reuse it later on.

tree = DecisionTreeClassifier(random_state = 123)
tree.fit(X_train, y_train)

import pickle
# Save the model to hard drive.
pickle.dump(tree, open('tree.pickle', 'wb'))

# Load the model and make predictions.
loaded_tree = pickle.load(open('tree.pickle', 'rb'))
predictions = loaded_tree.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, predictions):.3f}")
#>> Accuracy: 0.865

In this case I used the ‘pickle’ library to persist the trained model. However, there are other alternatives depending on your use case like ‘ONNX’, ‘joblib’ and so on (scikit-learn-model-persistence 2025).


It is recommendeded to save your experiments’ results for further analysis.

References

scikit-learn-model-persistence. 2025. Model Persistence. https://scikit-learn.org/stable/model_persistence.html.