-
Book Overview & Buying
-
Table Of Contents
Machine Learning and Generative AI for Marketing
By :
For marketers who are relatively new to the world of AI/ML, setting up a robust Python environment is the first technical step to unlocking the potential of data science in marketing strategies. Python, renowned for its simplicity and powerful libraries, serves as the backbone for most AI/ML projects in today’s technology companies. This section will guide you through setting up a Python environment tailored for AI/ML in marketing projects, ensuring that you have the necessary tools and libraries at your disposal. Python’s appeal lies in its vast ecosystem of libraries designed for data analysis, ML, natural language processing (NLP), and more. For AI/ML projects, using an Anaconda distribution is highly recommended due to its simplicity in managing packages and environments. Let’s look at how you can get started.
Visit the Anaconda website at https://www.anaconda.com/download and download the installer for Python 3. Once the Anaconda distribution has been downloaded, you can follow the installation instructions and create a new environment. This can be done by opening a terminal window and typing:
conda create --name ai_marketing python=3.8
conda activate ai_marketing
After running these commands, you should have a new Python environment named ai_marketing with Python 3.8 installed and activated. This environment will help you manage dependencies for your AI/ML projects effectively, isolating them from other projects on your system.
With your environment set up, the next step is to install the key Python libraries that will power your AI/ML marketing projects. The following are some of the essential Python libraries for AI/ML projects, grouped by their general functionality. You can install these libraries using Anaconda via the following terminal commands:
conda install numpy pandas
conda install matplotlib seaborn
conda install scikit-learn
conda install tensorflow keras
conda install nltk spacy
pip install transformers
JupyterLab offers an interactive coding environment ideal for data exploration, visualization, and presenting step-by-step AI/ML analyses. This can be installed via the following terminal command:
conda install jupyterlab
To launch JupyterLab, where you can create and manage your notebooks, type the following in the terminal:
jupyter lab
You should now see a screen similar to what is shown below in a newly launched browser window:

Figure 1.7: Image of the JupyterLab UI after launch
To ensure that everything is set up correctly, run a simple Python script in a Jupyter notebook to verify the installation of key libraries. Click on the icon below the Notebook heading of Figure 1.7 and type the following lines of code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn
import tensorflow as tf
import transformers
print("Environment setup successful!")
Pressing Shift + Enter will execute the code in the cell:

Figure 1.8: Environment setup successful message
You can also use Ctrl + Enter to run the cell without moving to the next one.
You can change the cell type using the dropdown menu in the toolbar. Select Code for Python code or Markdown for narrative text, equations, or HTML.
# for headings (e.g., # Heading 1, ## Heading 2)– or * for bullet lists1., 2., etc., for numbered lists`code` for inline code[Link text](url) for hyperlinks[Alt text](Image URL) for imagesYou can share your notebook by downloading it in various formats (including .ipynb, HTML, PDF, etc.) from the File -> Download as menu.
Change the font size
Change margin width
Change background colour