Data Science Applied to Heroin Consumption
By: Richard Han
Tags: Tableau, Machine Learning, Logistic Regression, Data Science, Heroin

Learning about the theory and math behind an algorithm is extremely important but the real challenge is being able to apply the same on a real world problem! In this article we will build a logistic regression model to the ‘Heroin consumption’ data. Let’s begin!

Setting up the dataset for binary classification

We will look at the problem of classifying an individual as a user of heroin or as a non-user of heroin. Some of the predictors used in determining this are personality factors such as Nscore (measuring neuroticism ), SS score (sensation-seeking), and Impulsive (impulsivity). The original dataset classifies individuals into 7 classes, depending on the time at which they used the drug. The original dataset also addresses many other drugs besides heroin; however, in this project, we look only at heroin. The dataset is taken from the UCI Machine Learning Repository and can be downloaded here:

https://medium.com/r/?url=http%3A%2F%2Farchive.ics.uci.edu%2Fml%2Fdatasets%2FDrug%2Bconsumption%2B%2528quantified%2529

For each drug, an individual falls under one of 7 classes — CL0, CL1, CL2, CL3, CL4, CL5, and CL6. CL0 means that the individual never used the drug, CL1 means the individual used the drug over a decade ago, CL2 means the individual used the drug within the last decade; and CL3, CL4, CL5, and CL6 mean the individual used the drug in the last year, in the last month, in the last week, and in the last day, respectively.

First, I took the .data file and converted it into a .csv file. I restricted the dataset to the drug heroin by deleting all the columns for the other drugs. I then added a new column “User” that has value 0 if the individual falls under CL0 or CL1 — the individual is not considered a User. Otherwise, the individual falls under CL2, CL3, CL4, CL5, or CL6; in this case, the value is 1 — the individual is considered a User. This gives a binary classification problem for classifying individuals as User or Not User.

I took a random sample of the heroin dataset using excel. Then, I broke up the dataset into two separate csv files: one containing 80% of the data, the other containing 20% of the data. The set containing 80% is our training set, and the set containing 20% is our test set.

Visualizing the data

For this section, I’m going to use the entire dataset for heroin consumption. Let’s look at heroin consumption by gender. Here is a graph for the number of users for each gender.

As you can see, there are about the same number of males as females in the population. For both genders, only a small fraction are heroin users, and there are about twice as many male heroin users as female heroin users. We can test whether gender is statistically significant using the chi-squared test:

Since the p-value is less than the significance level, gender is statistically significant.

Let’s look at the percentages of users by country.

As you can see, the USA and UK have the largest representation in the sample. Most of the heroin users in the sample are from the USA. Applying the chi-squared test, we can check that country is statistically significant:

Since the p-value is less than 0.05, country is statistically significant.

Let’s see how Impulsivity affects the percentage of users:

As the Impulsive score increases, the percentage of users increases.

We can apply the Chi-Squared test to check whether Impulsivity is statistically significant:

Since the p-value is less than the significance level, Impulsivity is statistically significant.

As the Impulsive score increases, the percentage of users increases . A similar effect can be seen with Nscore: