Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get model params while training #14531

Closed
anshdavid opened this issue Jul 31, 2019 · 5 comments
Closed

get model params while training #14531

anshdavid opened this issue Jul 31, 2019 · 5 comments

Comments

@anshdavid
Copy link

Description

I am using SGDRegressor for training a model. Is there any way i can store the Bias and the Norm values for each iteration in the training loop ?

Using verbose i can see the output , I just want to store the parameters in a list. I was trying to run the regressor in a for loop as it returns an instance of itself, but that did'nt work

clf = SGDRegressor(max_iter=1, alpha=alpha)                                                                                              
for counter in range (0,epochs):
    clf.fit(X, Y)
    print("slope {0}, intercept {1}".format(clf.coef_, clf.intercept_))

Can someone help me out ?
thanks....

@anshdavid anshdavid reopened this Jul 31, 2019
@glemaitre
Copy link
Member

This could be linked to a callback mechanism which was already a feature request which we don't have implemented for the moment. A potential discussion can be found in #10973

@anshdavid
Copy link
Author

anshdavid commented Jul 31, 2019

Thank you for the reply @glemaitre . I figured out a way of doing it . The result is off by a few decimal places though ...

clf = SGDRegressor(max_iter=1, alpha=0.01)
coef=0
intercpt=0
for counter in range (0,100):

    clf.fit(X, Y, coef_init=coef, intercept_init=intercpt )
    coef = clf.coef_
    intercpt = clf.intercept_
    intercpts.append(intercpt)
    slopes.append(coef)

@amueller
Copy link
Member

you should be using partial_fit

@glemaitre
Copy link
Member

you should be using partial_fit

I was not fast enough to mention that. Basically, max_iter=1 in this case and you don't need to pass the coef_init and intercept_init.

@anshdavid
Copy link
Author

@amueller , @glemaitre thank you . got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants