Regression with discrete dependent variable using statsmodels

With this recipe, you can perform Regression with Discrete Dependent Variable in Python using the StatsModels library

Recipe Objective - How to perform Regression with Discrete Dependent Variable using the StatsModels library in python?

Regression models for limited and qualitative dependent variables. This module now allows model estimation using binary (Logit, Probit), nominal (MNLogit), or count (Poisson, negative binomial) data.

For more related projects -

https://www.dezyre.com/projects/data-science-projects/deep-learning-projects
https://www.dezyre.com/projects/data-science-projects/neural-network-projects

Example:

# Importing libraries
import statsmodels.api as sm
import statsmodels.formula.api as smf

# Importing spector dataset from statsmodels in the form of pandas dataframe
data = sm.datasets.spector.load_pandas()

# Storing data
X = data.data

# Fit and summarize Logit model with 'GRADE' as dependent variable and 'GPA, TUCE, PSI' as independent variables,
model = sm.Logit(X['GRADE'], X[['GPA','TUCE','PSI']])
model = model.fit()

# Model summary
model.summary()

Output - 
Optimization terminated successfully.
         Current function value: 0.586580
         Iterations 5
Logit Regression Results
Dep. Variable:	GRADE	No. Observations:	32
Model:	Logit	Df Residuals:	29
Method:	MLE	Df Model:	2
Date:	Sun, 14 Nov 2021	Pseudo R-squ.:	0.08844
Time:	20:05:56	Log-Likelihood:	-18.771
converged:	True	LL-Null:	-20.592
Covariance Type:	nonrobust	LLR p-value:	0.1618
coef	std err	z	P>|z|	[0.025	0.975]
GPA	0.2993	0.682	0.439	0.661	-1.036	1.635
TUCE	-0.1015	0.100	-1.019	0.308	-0.297	0.094
PSI	1.6364	0.813	2.014	0.044	0.044	3.229

In this way, we can perform Regression with Discrete Dependent Variable using the StatsModels library in python.

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

MLOps Project for a Mask R-CNN on GCP using uWSGI Flask
MLOps on GCP - Solved end-to-end MLOps Project to deploy a Mask RCNN Model for Image Segmentation as a Web Application using uWSGI Flask, Docker, and TensorFlow.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Loan Eligibility Prediction Project using Machine learning on GCP
Loan Eligibility Prediction Project - Use SQL and Python to build a predictive model on GCP to determine whether an application requesting loan is eligible or not.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..