How to adjust scaled scikit-learn Logicistic Regression coeffs to score a non-scaled dataset?
Question: I am currently using Scikit-Learn's LogisticRegression to build a model. I
have used

    
    
    from sklearn import preprocessing
    scaler=preprocessing.StandardScaler().fit(build)
    build_scaled = scaler.transform(build)
    

to scale all of my input variables prior to training the model. Everything
works fine and produces a decent model, but my understanding is the
coefficients produced by LogisticRegression.coeff_ are based on the scaled
variables. Is there a transformation to those coefficients that can be used to
adjust them to produce coefficients that can be applied to the non-scaled
data?

I am thinking forward to am implementation of the model in a productionized
system, and attempting to determine if all of the variables need to be pre-
processed in some way in production for scoring of the model.

Note: the model will likely have to be re-coded within the production
environment and the environment is not using python.


Answer: You can use [pipeline](http://scikit-
learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) with two
steps: scaling and regression. It takes raw data as input and produces
regression desired.

Or if you explicitly want to get coefficients, you can manually combine
LogisticRegression coefficients with scaler parameters which are scaler.mean_
and scaler.std_.

To do so, note that standardscaler normalized data this way: v_norm = (v -
M(v))/ sigma(v). Here M(v) is mean of raw variable v and sigma(v) is it's
standard deviation and stored in scaler.mean_ and scaler.std_ arrays
respectively.

Then LogisticRegression takes this normalized variables and multiplies them by
LogisticRegression.coef_ and adds intercept_.

