As an example, I use a small data frame and calculate logistic regression using either statsmodels or scikit-learn:
import pandas as pd
x1 = [148,85,182,49]
x2 = [50,31,32,21]
x3 = [72,66,64,66]
y = [1,0,1,1]
df = pd.DataFrame({"x1":x1,"x2":x2,"x3":x3,"y":y})
import statsmodels.api as sm
lr = sm.Logit(endog = y, exog = X)
res = lr.fit()
res.summary()
The output is very well organized into a data frame form:
Is there a way to show outputs from scikit-learn in a similar form?
Actually, the only possibility I found is to use print
, which gives a "no-decent" presentation:
from sklearn import linear_model
from sklearn.linear_model import LogisticRegression
data = df.to_numpy()
X = data[: , 0:3].astype('float')
y = data[: , 3].astype('int')
lr = LogisticRegression(solver = "lbfgs")
model = lr.fit(X, y)
print(f"intercept: {model.intercept_} coeficients: {model.coef_}")
intercept: [-45.25601233] coeficients: [[ 0.06092424 -0.3317025 0.75962957]]