Run an OLS regression with Pandas Data Frame

前端 未结 5 1986
温柔的废话
温柔的废话 2020-11-30 16:48

I have a pandas data frame and I would like to able to predict the values of column A from the values in columns B and C. Here is a toy example:



        
5条回答
  •  感动是毒
    2020-11-30 17:41

    I don't know if this is new in sklearn or pandas, but I'm able to pass the data frame directly to sklearn without converting the data frame to a numpy array or any other data types.

    from sklearn import linear_model
    
    reg = linear_model.LinearRegression()
    reg.fit(df[['B', 'C']], df['A'])
    
    >>> reg.coef_
    array([  4.01182386e-01,   3.51587361e-04])
    

提交回复
热议问题