<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[A Cannalytical Mind - Medium]]></title>
        <description><![CDATA[A moderately OK attempt at cannabis-related data science - Medium]]></description>
        <link>https://medium.com/a-cannalytical-mind?source=rss----6c43ca60466a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>A Cannalytical Mind - Medium</title>
            <link>https://medium.com/a-cannalytical-mind?source=rss----6c43ca60466a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:22:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/a-cannalytical-mind" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding the Target Toker: Targeted Marketing for Dispensaries — Part I]]></title>
            <link>https://medium.com/a-cannalytical-mind/finding-the-target-toker-targeted-marketing-for-dispensaries-part-i-80942b94155a?source=rss----6c43ca60466a---4</link>
            <guid isPermaLink="false">https://medium.com/p/80942b94155a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[marijuana-dispensaries]]></category>
            <category><![CDATA[cannabis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[AJ Davis]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 16:39:16 GMT</pubDate>
            <atom:updated>2018-10-31T16:39:15.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OmaSvzAR-A7MdNcl" /><figcaption>Photo by <a href="https://unsplash.com/@chasefade?utm_source=medium&amp;utm_medium=referral">Chase Fade</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Finding the Target Toker: Targeted Marketing for Dispensaries — Part I</h3><p>Targeted marketing is a method of intelligently designing marketing campaigns to target a specific customer segment while employing a customized message with the intent of maximizing profit per marketing dollar spent. Almost all commercial enterprises can benefit from some form of targeted marketing, even cannabis retailers. In this post, I describe what customer class dispensaries should be targeting, i.e., the target toker, and review my attempt to build a model to classify them using demographic data.</p><h3>Identifying the Target Toker</h3><p>The Marijuana Policy group conducted a <a href="http://www.cannabisconsumer.org/uploads/9/7/9/6/97962014/market_size_and_demand_study_july_9_2014%5B1%5D.pdf">study</a> that investigated the legal cannabis market and demand in Colorado for the Colorado Department of Revenue. The study concluded that the lion share of marijuana demand comes from regular users, i.e., near-daily users. In Colorado, the top 21.8 percent of users account for 66.9 percent of the demand. In contrast, the entire population of rare users (less than once per month), a group that accounts for almost one-third of all users, represents less than 1 percent (0.3 percent) of total demand. The table below is from the report and details the relationship between the frequency of use and demand for cannabis in Colorado.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*wA9CZefl2dk3dz9FLSEq9g.png" /><figcaption>Source: Marijuana Policy Group calculations. One million grams equals one metric ton.</figcaption></figure><p>Table 1: Relationship between Frequency of Use and Demand for Cannabis in Colorado — Marijuana Policy Group</p><p>The table above seems to indicate that there exists a great opportunity to increase demand for cannabis among less frequent users, i.e., cannabis consumers who use it less than 20 days per month. These individuals have room to increase their consumption and could be a prime target for a marketing campaign. Cannabis consumers who use marijuana more than 20 days are already regularly purchasing cannabis and dispensaries do not need to waste marketing funds on them.</p><p>Additionally, the American Medical Association released a <a href="https://jamanetwork.com/journals/jamainternalmedicine/fullarticle/1898878">study</a> examining the relationship between medical cannabis laws and the opioid overdose mortality rate. The study concluded that medical cannabis laws are associated with significantly lower state-level opioid overdose mortality rates. The table below details the coefficients from the fixed-effects regression equations where the dependent variable was the annual opioid analgesic overdose mortality rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*jEQRJn1RjX6SgzBAn82KzA.png" /><figcaption>Source: Bachhuber MA, Saloner B, Cunningham CO, Barry CL. Medical Cannabis Laws and Opioid Analgesic Overdose Mortality in the United States, 1999–2010. <em>JAMA Intern Med.</em> 2014;174(10):1668–1673.</figcaption></figure><p>Table 2: Relationship between Cannabis and Painkiller Overdose — American Medical Association</p><p>While this study may not demonstrate a definitive causal relationship between medical marijuana laws and painkiller overdoses, the statistically significant negative coefficient associated with the “Medical cannabis law” independent variable offers some evidence that individuals may be willing to substitute cannabis (an arguably cheaper and healthier alternative) for painkillers to manage pain.</p><p>Given the above two studies, there is a case for dispensaries and delivery services to target their marketing efforts toward individuals who are open to using cannabis (but currently use it less than 20 days/month) and may have a tendency to misuse painkillers. This is our target toker.</p><h3>Classifying the Target Toker</h3><p>In order for dispensaries to market specifically to the class identified above, they need a method of detecting them within their customer base. A good approach for this is to utilize supervised machine learning and classification modeling. If dispensaries can accurately predict whether an individual is a target toker based on available demographic information, they can then target their marketing effort towards these individuals.</p><h4>Data</h4><p><a href="https://nsduhweb.rti.org/respweb/homepage.cfm">The National Survey on Drug Use and Health</a> provides a rich data set of drug use and demographic questions that allow for the labeling of the target class and provides a large set of relevant features for prediction.</p><h4>Data Processing</h4><p>Most of the data processing consisted of standard recoding steps one might complete when analyzing survey data. “Yes/No” questions were recoded to 1s and 0s, string processing of question answers that were originally coded as numbers for the survey administrator, and replacing “Skips”/“Refusals”/“Don’t Knows” with “N/As”.</p><p>The target for this problem was labeled by creating a binary variable for survey participants who reported that they had “misused painkillers” at some point in their life and reported having consumed cannabis less than 240 days in the past year (this corresponds to less than 20 days per months on average as described in Table 1). Given the specificity of this target class, there was a significant imbalance between the target class and everyone else (~1:16). In order to account for the imbalance, synthetic over-sampling techniques (SMOTE) were employed.</p><h4>Feature Selection/Engineering/EDA</h4><p>There were over 2,000 questions in the survey. I reviewed the survey codebook to identify those questions that intuitively seemed like they could be determinants of the target class and might be related to data that is available in the public domain (feature data needs to be available to dispensaries in order to utilize the algorithm for classification). This narrowed the space to approximately 30 potential features. These features included survey questions related to:</p><ul><li>Gender</li><li>Ethnicity</li><li>Age</li><li>Health</li><li>Income</li><li>Marital Status</li><li>Geographic Location</li><li>Education</li></ul><p>The final 30 features were then engineered appropriately so they could be utilized in the various classification algorithms and then evaluated via an ensemble of empirical feature selection methods (i.e., Chi-Squared, RFE, K-Best, and Feature Importance). I ended up including the 20 features that appeared most frequently as important features per the feature selection methods listed above.</p><p>All of the included features were demographic variables, and as such, categorical in nature. All categorical variables were one-hot encoded into indicator/dummy variables.</p><p>By simply looking at the percentages of the top categorical variables for the targeted class, we are able to get a general idea of the target toker demographic profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*AsDUNnIBBJ0HGqkUxAISgg.jpeg" /><figcaption>% of Target Tokers with Characteristics</figcaption></figure><p>According to the chart above, the target toker appears to be Caucasian males, who make less than $10k annually, live in a small metro area, are in very good health, between 18 and 25 years old, and have never been married (although a lot of them have been).</p><h4>Modeling</h4><p>In order to develop a method to detect target tokers, the data described above was utilized in a host of common classification models. Standard machine learning protocols were followed such as separation into training and test sets, scaling, cross-validation, and hyperparameter tuning. For this particular business problem, because the marketing costs are unknown to me, it is unclear whether precision or recall is more important. Thus, I chose the F1 score as the evaluation metric. We are certainly interested in detecting as many of the target tokers as possible to maximize the value of the marketing effort. However, while the marginal cost of marketing will likely be cheap at scale, we should still attempt to minimize false positives, i.e., classifying someone as a target toker when they aren’t.</p><h4>Results</h4><p>The ROC curves associated with the test data set for all of the classifiers are plotted below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbJaVz9CtmV9s7luHB1TrA.jpeg" /></figure><p>While all classifiers performed well, the XGBoost classifier had the highest weighted average test set F1 score of 0.87. Below is the confusion matrix for the final model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*T0VF0bz7u7lCieDvl5fH_g.jpeg" /></figure><p>Table 3: Test Set Confusion Matrix XGBoost Classifier</p><p>The confusion matrix above illustrates that precision associated with classifying the Target Toker class is slightly higher than recall (0.91 vs. 0.82) and the opposite is true for the Non-Target Toker class (0.84 vs. 0.92).</p><h3>Next Steps</h3><p>Given the F1 score of the final model, and assuming I have accurately identified a relevant target toker, it appears the classification model could have some value to cannabis retailers. For Part II and Part III of this project, I hope to explore the following:</p><ul><li><em>Take a deeper dive into the features — </em>Additional engineering to combine some related categorical variables could improve prediction accuracy shrink the feature space so that the model is more practical/implementable in the real world.</li><li><em>Spend more time on model development — </em>The standard exemplary classifiers performed pretty well, however, little time was spent on hyperparameter tuning. Additionally, given the plethora of categorical features, I would like to try the Yandex’s state-of-the-art <a href="https://tech.yandex.com/catboost/">CatBoost algorithm</a>.</li><li><em>Develop a web application — </em>A simple application that would allow dispensaries to upload a file of demographic data for customers and output the probabilities each customer is a target toker seems appropriate.</li></ul><p><em>All of the code related to this post can be found in my </em><a href="https://github.com/AJ-Davis/A-Cannalytical-Mind"><em>Github repository</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80942b94155a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cannalytical-mind/finding-the-target-toker-targeted-marketing-for-dispensaries-part-i-80942b94155a">Finding the Target Toker: Targeted Marketing for Dispensaries — Part I</a> was originally published in <a href="https://medium.com/a-cannalytical-mind">A Cannalytical Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dankstimate: Cannabis Price Estimation — Part I]]></title>
            <link>https://medium.com/a-cannalytical-mind/the-dankstimate-cannabis-price-estimation-part-i-ffbb19d1edb1?source=rss----6c43ca60466a---4</link>
            <guid isPermaLink="false">https://medium.com/p/ffbb19d1edb1</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[marijuana]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[cannabis-dispensary]]></category>
            <category><![CDATA[cannabis]]></category>
            <dc:creator><![CDATA[AJ Davis]]></dc:creator>
            <pubDate>Fri, 19 Oct 2018 19:45:09 GMT</pubDate>
            <atom:updated>2018-11-01T04:11:56.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Ykazzh_2Im5L3xxpKupEA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/2PiRLc_gqIs?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Josiah Weiss</a> on <a href="https://unsplash.com/search/photos/dispensary?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>The Dankstimate: Cannabis Price Estimation — Part I</h3><p>Since I learned about super-normal profits and black markets in microeconomics 101, I’ve been fascinated by cannabis pricing. How could something grown so easily be worth so much money?</p><p>In graduate school, I came across a clever <a href="http://www.priceofweed.com/">website</a> that anonymously crowd-sources how much money people pay for different quantities of cannabis. It also details the transaction location and perceived cannabis quality. I was so fascinated I wrote my <a href="https://link.springer.com/article/10.1007/s00181-015-0992-1">master’s thesis</a> using their data to estimate the price elasticity of cannabis.</p><p>Five years later, cannabis is legal for medicinal use in 31 states and recreational use in 9 states. There are thousands of dispensaries from which one can obtain pricing data to analyze. I thought it might be a good time to revisit cannabis pricing to build a model that outputs a price benchmark for dispensaries (a “dankstimate” in the vein of Zillow’s “zestimate”).</p><h3>How do dispensaries currently set prices?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sbAqwFfcpBpIG3mFhEz6Q.jpeg" /></figure><p>Based on anecdotes from dispensary employees, flower product (i.e., the actual cannabis flower, not a concentrate or edible) pricing isn’t especially scientific. Dispensary managers evaluate the flower based on nose (i.e., smell), density, and strain name. While these are important features consumers look to when making their purchasing decisions, we may be able to create an additional pricing benchmark by aggregating pricing data from the majority of dispensaries in the states in which cannabis is legal for both medicinal and recreational use.</p><h3>Building the “Dankstimate”</h3><p>While companies like <a href="https://newfrontierdata.com/">New Frontier Data</a> and <a href="https://bdsanalytics.com/">BDS Analytics</a> have rich retail tracking data sets from POS systems to build bench marking models, I wanted to build an accurate model using publicly available information. Price prediction is a classic machine learning regression problem, which is the approach I employed.</p><h4>Data</h4><p>I was able to obtain data from menus at over 20,000 dispensaries in the states that have legalized cannabis for recreational use using the <a href="https://weedmaps.com/">weedmaps.com</a> API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4BZ9ss_eOrCxqb0pHDUog.png" /></figure><p>The data set included information like the cost for varying quantities of the products, THC and CBD content, strain name, the sub-type of flower (Indica, Sativa, or Hybrid), and other information related to the dispensary.</p><h4>Data Processing/Exploratory Data Analysis</h4><p>The data from the weedmaps API came in typical JSON format. Some of the more significant munging exercises included:</p><ul><li>Initially, I only wanted to look at flower products, so I had to filter out non-flower products from the data set.</li><li>The price data varied by product and dispensary, so I had to transform it into a price per gram for each product. I also created quantity indicator variables for each product to account for quantity discounts as the quantities available for each product varied (a weighted average is probably another option).</li><li>The text associated with the strain names for each product was quite messy and required the use regular expressions.</li><li>THC and CBD content was not listed for a lot of products and the structure of the strings in which it was listed varied significantly between menus. In order to ensure I was able to include cannabinoid content for a majority of the products, I fuzzy matched each product to the average lab testing results from this <a href="https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/E8TQSD">data set</a>. I only kept observations that matched 100%.</li><li>As with any data set, there were some values that I would consider outliers. Values that were greater than three standard deviations from the mean were removed.</li></ul><p>The bar charts below illustrate average pricing by the major regions in the states that have legalized cannabis for recreational use (only includes regions that had more than 1,000 observations)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*9_8OysSLM7XBTWr6JUiG_w.jpeg" /><figcaption>15 Most Expensive Regions</figcaption></figure><p>Interestingly, when looking at the data from the Priceofweed.com back in 2012, Washington D.C. was also the most expensive place to purchase cannabis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*pkcuT4p86z6iZ7vv8NYKmw.jpeg" /><figcaption>15 Least Expensive Regions</figcaption></figure><p>According to the data, the cheapest place to buy cannabis is the tiny Washington town of Cathlamet. Given the density of agriculture in the area, perhaps there are a number of larger cannabis farms driving price down.</p><p>The table below details the average cost per gram for 15 historically popular strains as detailed in this <a href="https://cannabis.net/blog/opinion/15-most-popular-cannabis-strains-of-all-time">article</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1601e4a4f2a0b37eb8341e3c7843177b/href">https://medium.com/media/1601e4a4f2a0b37eb8341e3c7843177b/href</a></iframe><p>The pie chart below details the composition of sub types in the data set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*5VxlA87Z7-sYC8lzuT1cdQ.jpeg" /></figure><h4><em>Feature Selection/Engineering</em></h4><p>Based on insights from industry reports, dispensary employees, and growers I believe the following are the most relevant features:</p><ul><li><em>Nose </em>or <em>the fragrance of the flower</em> is certainly one of the most important determinants of price. While the genetics or strain of a cannabis flower certainly contribute to its nose, the specific conditions under which each product is grown is likely the biggest factor. Strain and geographic related fixed-effects helped to capture some of the variation associated with the nose; however, I had to live with some omitted variable bias related to this determinant.</li><li><em>Density </em>of the buds is also a common characteristic that helps set price. Like the nose, the density of a product is a tangible characteristic that consumers can evaluate prior to making a purchasing decision. Greater density is typically associated with higher quality. Unfortunately, this is data that is not readily available and I was unable to include it in any model.</li><li><em>Geographic location </em>is important for a number of reasons. Distance from major manufacturing centers like northern California, regional economic conditions (e.g., the cost of living, electricity prices, etc.), and amount of time cannabis has been legal all contribute to pricing. My model incorporated geographic fixed effects (I evaluated both regional and zip-code based indicators) to help capture variation associated with geographic location.</li><li><em>The type of cannabis </em>is another important pricing determinant. Similar to nose and density, the strain name and type (i.e., Indica or Sativa) are additional factors that consumers can evaluate prior to purchase. Given the dominance of a <em>cultivar</em> (i.e., classification of cannabis based on cultural vernacular whether it is accurate or not) approach to understanding cannabis, the majority of consumers believe the effects and flavors of cannabis flower are dictated by the strain and/or type (e.g., Indica helps you sleep; “in da couch”). I was able to include both strain and type fixed-effects in my model. Additionally, certain strains have garnered significant recognition over the years and often fetch a premium (e.g., “White Widow” or “OG Kush”). Again, utilizing fuzzy string matching, I created a popular strain score (‘fuzz ratio’ of 0-100) based on how close it matched its closest strain name in this <a href="https://cannabis.net/blog/opinion/15-most-popular-cannabis-strains-of-all-time">article</a>.</li><li><em>The potency</em> of cannabis is typically measured by its content of the cannabinoids <em>THC </em>and<em> CBD. </em>The higher the concentration of these cannabinoids, the stronger the effects of the flower will be when consumed (this is more of a <em>chemovar </em>approach to classifying cannabis, i.e. based on its chemical composition — more on cultivar vs. chemovar in future posts). In most states, the legislation to legalize cannabis often required that all all products be laboratory tested for their concentration of THC and CBD (among other things) and the results displayed for consumers.</li></ul><p>As detailed above, most features in the model were categorical and were one-hot encoded to create indicators. I also explored creating some polynomial permutations of the potency and popular strain features.</p><h4>Modeling</h4><p>All modeling was completed using Python’s scikit-learn library. I explored all popular supervised machine learning regression models such as linear, lasso, ridge, xgboost, random forest, etc. I employed the powerful GridSearchCV function to complete some basic hyper-parameter tuning and cross-validation to combat over-fitting. The models were evaluated via the R² and RMSE scoring metrics.</p><h4>Results</h4><p>The random forest regressor performed the best by a significant margin. One might expect on ensemble algorithm like random forest to overfit, however, the R² when the model was run with the training set was 0.82 (RMSE of 2.48) and the R² from the test set was 0.84 (RMSE of 2.40).</p><p>The table below illustrates the predicted prices vs. the actual prices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*uCqehnq9molLRQD2v0NOEA.jpeg" /></figure><p>It appears the model is overpredicting prices below $8/gram and underpredicting prices greater than $8/gram.</p><h3>Next Steps</h3><p>It is clear that the model can certainly use some more work; the average $/gram was $9.24 so a model that is consistently off by more than $2 isn’t particularly useful . For Part II and Part III of this project, I hope explore the following:</p><ul><li><em>Add more features and data</em> — Perhaps there is a better way to capture the variation in pricing associated with the nose and density of the flower products? These features are unfortunately very case-specific, since they are highly contingent on the grower. Weedmaps does provide pictures for each flower product so perhaps some kind of computer visualization tools could be utilized. Also, websites like <a href="http://cannabisreports.org/">Cannabisreports.org</a> and <a href="https://www.leafly.com/">Leafly.com</a> appear to be rich data sources for this model.</li><li><em>Additional feature engineering</em> — I would like to do a deeper dive into potential feature transformations and interactions in an attempt to improve the accuracy of the model.</li><li><em>Explore the use of neural nets — </em>Even though I was able to utilize over 400,000 observations in this analysis, significantly more data is available in Weedmaps and it is growing everyday. I believe I may be able to boost prediction efficacy even more by obtaining a larger data set and employing some of the latest deep learning models via Amazon Web Services (AWS).</li><li><em>Create models for concentrates and edibles — </em>Pricing data is also available for non-flower products as well. Concentrates are becoming increasingly more popular per BDS Analytics most recent <a href="https://shop.bdsanalytics.com/collections/reports/products/concentrates-the-hottest-product-category-in-cannabis">report</a>.</li><li><em>Create a web application </em>— Once the model is finalized, I hope to build a simple web application that dispensaries could use to easily benchmark their product pricing.</li><li><em>Black market comparisons — </em>While recent attempts to obtain new data from the priceofweed.com haven’t been fruitful, it would be great to conduct a similar analysis on cannabis pricing in the black market.</li></ul><p><em>All of the code related to this post can be found in my </em><a href="https://github.com/AJ-Davis/A-Cannalytical-Mind"><em>Github repository</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffbb19d1edb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cannalytical-mind/the-dankstimate-cannabis-price-estimation-part-i-ffbb19d1edb1">The Dankstimate: Cannabis Price Estimation — Part I</a> was originally published in <a href="https://medium.com/a-cannalytical-mind">A Cannalytical Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>