question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why do I have to retrain the model every time?

See original GitHub issue

Describe the solution you’d like I want to be able to use ResidualsPlot and PredictionError classes without having to retrain the model every time. I want to be able to train the model on my own and pass in the y_actual, y_predicted, and X_test and make the plots. I have tried to use the draw() method but I get errors.

Is your feature request related to a problem? Please describe. Very frustrating to have to repeatedly train the model. I am having trouble even believing that this how it was designed, I hope I’m just missing something

Examples I want to be able to do this:

X_train, X_test, y_train, y_test = train_test_split(X, y)
lr = LinearRegression()
lr.fit(X_train, y_train)
y_pred = lr.predict(X_test)
resid = y_test - y_pred
resplot = ResidualsPlot()  
resplot.draw(y_test, y_pred)
errplot = PredictionError()
errplot.draw(y_test, y_pred)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bbengfortcommented, Jul 13, 2021

@pedropalb I think there is a blog post on this topic, but until I find the link - I wanted to mention that I’ve opened a PR that adds this functionality to the yellowbrick contrib module: #1189

0reactions
bbengfortcommented, Jul 12, 2021

Hi @pedropalb - thanks for using Yellowbrick! We currently don’t have plans to create such an interface. The issue is that Yellowbrick often takes advantage of the properties of models, particularly the learned attributes such as coef_ in order to produce its visualizations. There are a few visualizers that can produce results without the estimator, but we’ve erred on the side of integrating into the ML workflow. (Note that we’re still looking to produce Keras estimators for Yellowbrick - #1106).

However, it is hopefully pretty simple to produce an “estimator” that can do what you’d like. I thought we actually had this already in the contrib module, but for some reason I can’t find it - I’ll investigate and get back to you. But the basic sketch is as follows:

from sklearn.base import BaseEstimator
from sklearn.metrics import f1_score

class PassthroughEstimator(BaseEstimator):

    def __init__(self, y_pred, estimator_type="classifier"):
        self._y_pred = y_pred
        self._estimator_type = estimator_type        

    def fit(self, X, y=None):
        return self
    
    def predict(self, X):
        return self._y_pred
    
    def score(self, X, y=None):
        return f1_score(y, self._y_pred)

You may get some issues if Yellowbrick looks for an learned attribute you can’t find; but you can add them to the passthrough from your Keras model to make it work. Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

To retrain, or not to retrain? Let's get analytical about ML ...
data, the answer to this question is surprisingly often based on a gut feeling. Some retrain the models overnight—because it is convenient.
Read more >
Should a machine learning model be retrained each time new ...
Not always. Some models might need frequent retraining, but others can last long (i.e. a whole year) without updates. This depends on several...
Read more >
When Should You Retrain Machine Learning Models? - phData
This post discusses some of the most common cues for retraining an ML model. We'll discuss why you need to retrain machine learning...
Read more >
Retraining Model During Deployment: Continuous Training ...
This is because your model is sensitive to changes in the real world, and user behaviour keeps changing with time. Although all machine...
Read more >
When Should a Machine Learning Model Be Retrained?
This was mostly because the model retraining tasks were laborious and cumbersome, but machine learning has come a long way in a short...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found