tjb305
tjb305

Reputation: 2630

How do I view a model produced using scikit-learn?

I am learning to use scikit-learn as an alternative to R/SAS EM to produce machine learning models. I can produce a logistic regression classifier and apply it to a test set but I cannot seem to determine how to view the regression formula? I understand that I cannot save out as a PMML and only use joblib or pickle dumps, but these are not very intuitive.

Thanks,

Toby

Upvotes: 1

Views: 2778

Answers (1)

Alleo
Alleo

Reputation: 8548

After training classifier

from sklearn.linear_model import LogisticRegression
# generating some dataset
from hep_ml.commonutils import generate_sample
X, y = generate_sample(n_samples=1000, n_features=10)
trained_regressor = LogisticRegression().fit(X, y)

you are able to see coefficients

trained_regressor.coef_

Whish will output something like

array([[ 0.85468364,  1.09829236,  1.19397439,  0.89664885,  0.81402396,
         1.00528498,  1.11475434,  0.88583092,  0.708134  ,  0.76573151]])

and 'trained_regressor.intercept_' is bias.

The decision function looks like (from LinearRegressor.decison_function):

scores = safe_sparse_dot(X, self.coef_.T, dense_output=True) + self.intercept_

So you have all coefficients in linear combination provided as 'coef_' and 'intercept_' fields of classifier.

Upvotes: 6

Related Questions