# Alternatives to logistic regression when data is unbalanced [duplicate]

Using Python's pandas, sklearn, and stats models API, I have trained a logistic regression on a training dataset that tells me whether or not a particular purchase (based on gender, and other features) was fraudulent. I held out a test set, and under a logistic regression all datapoints are predicted to be within %20 percent of unfraudulent (where fraudulent =0, unfradulent =1). In other words, arbitrarily setting a decision boundary to be 50%, all test points are predicted to be unfraudelent. This is because many many more data points are unfraudulent in the training set than fraudulent.

I am new to statistics, and would like to improve my model. What's the next step?

• Unbalanced classes is tbe term to use, not sparse. Can you edit the title? And search this site for unbalanced classes Commented May 16, 2017 at 20:24
• You are incorrectly evaluating your regression model. Instead if insisting on a hard classification threshold, you should evaluate your logistic regression on the basis of the probabilities it produces. Use the log-loss, not accuracy. Commented May 16, 2017 at 20:46
• It sounds like your problem isn't unbalanced classes, but that your features don't predict fraud well! If your features don't help you forecast fraud, then your best prediction for every transaction is not fraudulent. If that's what's going on, the next step would be to build/get a richer feature set. Commented May 16, 2017 at 21:17
• If you're running logistic regression, you could try construct 2nd degree polynomial terms over all your features, probably with some regularization if you have a lot of features. Or use a random forest classifier. Those would explore whether a more flexible functional form on your current data might do better. You want to estimate $\theta$ so that $f(x; \theta)$ forecasts fraud for input $x$. The two basic approaches are to get a better function $f$ or get better data $x$. Commented May 16, 2017 at 21:34
• @MatthewGunn I will try what you said, BUT you were right about the features. I found other features I could add in and no longer faced this problem, learning something in the process. Thanks again! Commented May 16, 2017 at 21:51