Python Forum
fit each group and extract coefficients
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fit each group and extract coefficients
#1
I have a data frame df as follows:

	Board	Time	CO	H2
0	B000653BE	05.11.2018 13:28	89720	20320
1	B000653BE	05.11.2018 13:32	112760	35070
2	B000653BE	05.11.2018 13:36	130783	47063
(...)
Board	Time	CO	H2
B000653BF	08.11.2018 14:04	261254	217003
B000653BF	08.11.2018 14:08	261395	216402
B000653C2	05.11.2018 13:28	95564	49094
B000653C2	05.11.2018 13:32	90978	73274
B000653C2	05.11.2018 13:36	87743	93204
(...)
And I want to fit each group of Board via

def func_exp(x, a, b, c):
        #c = 0
        return a * np.exp(b * x) + c
        
def exponential_regression (x_data, y_data):
    popt, pcov = curve_fit(func_exp, 
                           x_data, 
                           y_data,          
                           p0 = (1000.1, 0.01, 1000000),        
                           maxfev=5000
                           )
    print(popt)   
    return func_exp(x_data, *popt)
but I can't figure out how to proceed. I thought about

df.groupby('Board').apply(exponential_regression(df.index, df["H2"]))
but I only get different errors (when I try to adjust the syntax somehow..)
I'm totally used to R, there I know how to proceed but I don't know how to do the same in python. However, I need to fit each group in regards to H2 and CO and extract the corresponding regression coefficients.

Can somebody please help me?
Reply


Messages In This Thread
fit each group and extract coefficients - by Progressive - Jul-19-2019, 01:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  AR roots for VAR coefficients Scott 2 1,051 Nov-30-2022, 09:23 PM
Last Post: Scott
  Neural Network importance weights / coefficients jkaustin 1 2,057 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Outputing LogisticRegression Coefficients (sklearn) RawlinsCross 6 4,760 Feb-27-2020, 02:47 PM
Last Post: RawlinsCross
  using two arrays to fit a third one - find coefficients vaugirard 1 2,601 Jul-05-2018, 10:49 PM
Last Post: Larz60+
  Printing coefficients Scott 1 5,759 Jun-30-2018, 12:14 PM
Last Post: gontajones
  How to group variables & check correlation of group variables wrt single variable SriRajesh 2 2,960 May-23-2018, 03:01 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020