Questions tagged [logistic-regression]

Logistic regression is a statistical classification model used for making categorical predictions.

Logistic regression is a statistical analysis method used for predicting and understanding categorical dependent variables (e.g., true/false, or multinomial outcomes) based on one or more independent variables (e.g., predictors, features, or attributes). The probabilities describing the possible outcomes of a single trial are modeled as a function of the predictors using a logistic function (as it follows):

enter image description here

A logistic regression model can be represented by:

enter image description here

The logistic regression model has the nice property that the exponentiated regression coefficients can be interpreted as odds ratios associated with a one unit increase in the predictor.

Multinomial logistic regression (i.e., with three or more possible outcomes) are also sometimes called Maximum Entropy (MaxEnt) classifiers in the machine learning literature.


Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique. Consider whether your question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

3746 questions
7
votes
2 answers

sklearn.linear_model.LogisticRegression returns different coefficients every time although random_state is set

I'm fitting a logistic regression model and am setting the random state to a fixed value. Every time I do a "fit" I get different coefficients, example: classifier_instance.fit(train_examples_features,…
jonathans
  • 320
  • 3
  • 9
7
votes
2 answers

Is there a way to implement sample weights?

I'm using statsmodels for logistic regression analysis in Python. For example: import statsmodels.api as sm import numpy as np x = arange(0,1,0.01) y = np.random.rand(100) y[y<=x] = 1 y[y!=1] = 0 x = sm.add_constant(x) lr = sm.Logit(y,x) result =…
user2448817
  • 119
  • 1
  • 2
  • 6
7
votes
1 answer

Multinomial regression using multinom function in R

I was thinking about posting my question in Cross-Validated, but decided to come here. I am using the multinom() function from the nnet package to estimate the odds of becoming employed, unemployed, or out of labor force conditioned on age and…
Koba
  • 1,514
  • 4
  • 27
  • 48
6
votes
0 answers

Is there python function for comparing two or more Logistic Regression models using anova?

I am trying to implement the Python version of this 'R' code to compare 2 or more Logistic Regression models by finding deviance statistics anova(LogisticModel.1, LogisticModel.2) which gives an output like this There is an statsmodels…
snehil
  • 586
  • 6
  • 12
6
votes
2 answers

regression models in r output table to word

I have been using sjplot to create a combined table. This creates a HTML table. I would like to make a table that can be exported to word. I have reviewed this post which discusses copy and pasting into word, but this alters the formatting of the…
sar
  • 182
  • 6
  • 26
6
votes
1 answer

Get marginal effects for sklearn logistic regression

I want to get the marginal effects of a logistic regression from a sklearn model I know you can get these for a statsmodel logistic regression using '.get_margeff()'. Is there nothing for sklearn? I want to avoid doing the calculation my self as I…
6
votes
1 answer

Ordinal logistic regression: Intercept_ returns [1] instead of [n]

I'm running an ordinal (i.e. multinomial) ridge regression using mord (scikitlearn) library. y is a single column containing integer values from 1 to 19. X is made of 7 numerical variables binned in 4 buckets, and dummied into a final of 28 binary…
Adav
  • 428
  • 4
  • 18
6
votes
1 answer

How can I use the "ivprobit" function in "ivprobit" package in R?

I am trying to understand the syntax of the "ivprobit" function in "ivprobit" package in R. The instruction says: Usage ivprobit(formula, data) Arguments formula y~x|y1|x2 whre y is the dichotomous l.h.s.,x is the r.h.s. …
Eric
  • 528
  • 1
  • 8
  • 26
6
votes
0 answers

Adding splines to a multinomial logit model using mgcv

I am trying to train a multinomial logit model and while I am at it I might as well make it a GAM and add splines to the mix. I have tried using mgcv, but I have only managed to generate errors so far. Below are some examples using the iris…
Zoltan
  • 760
  • 4
  • 15
6
votes
1 answer

Goodness-of-fit for fixed effect logit model using 'bife' package

I am using the 'bife' package to run the fixed effect logit model in R. However, I cannot compute any goodness-of-fit to measure the model's overall fit given the result I have below. I would appreciate if I can know how to measure the…
Eric
  • 528
  • 1
  • 8
  • 26
6
votes
2 answers

Sigmoid function returns 1 for large positive inputs

I wrote the following function in Python to calculate sigmoid function of a scalar, vector or matrix. def sigmoid(z): sig = 1.0/(1.0 + np.exp(-z)) return sig For relatively large positive values of z, e^-z returns a very small value close…
Supratim Haldar
  • 2,376
  • 3
  • 16
  • 26
6
votes
2 answers

Seaborn Regplot and Scikit-Learn Logistic Models Calculated Differently?

I'm using both the Scikit-Learn and Seaborn logistic regression functions -- the former for extracting model info (i.e. log-odds, parameters, etc.) and the later for plotting the resulting sigmoidal curve fit to the probability estimations. Maybe my…
John Sukup
  • 303
  • 3
  • 11
6
votes
2 answers

How to avoid NaN in numpy implementation of logistic regression?

EDIT: I already made significant progress. My current question is written after my last edit below and can be answered without the context. I currently follow Andrew Ng's Machine Learning Course on Coursera and tried to implement logistic…
6
votes
4 answers

Calculate residual deviance from scikit-learn logistic regression model

Is there any way to calculate residual deviance of a scikit-learn logistic regression model? This is a standard output from R model summaries, but I couldn't find it any of sklearn's documentation.
Max Ghenis
  • 14,783
  • 16
  • 84
  • 132
6
votes
1 answer

How are class_weights being applied in sklearn logistic regression?

I am interested in how sklearn apply the class weight we supply. The documentation doesn't state explicitly where and how the class weights are applied. Nor does reading the source code helps (seems like sklearn.svm.liblinear is used for the…
lizardfireman
  • 329
  • 3
  • 17