





















































Hi ,
Welcome to this week’s edition of ProgrammingPro!
In today’sExpert Insight, we bring you an excerpt from the recently published book, AI Strategies for Web Development, which demonstrates how to create an AI-driven product recommendation system for e-commerce using TensorFlow and Keras.
News Highlights: Rust 1.82 adds cargo info
and lifetime improvements; Java proposal targets 25% JDK size reduction; OpenAI releases Swarm for multi-agent AI; and Microsoft previews .NET AI integration libraries.
My top 5 picks from today’s learning resources:
But there’s more, so dive right in.
Stay Awesome!
Divya Anne Selvaraj
Editor-in-Chief
PS:The October survey is still live. Do take the opportunity to leave us your feedback, request a learning resource, and earn your one Packt credit for this month.
cargo info
subcommand provides detailed information about packages in the Cargo registry. Additional updates include improvements in lifetime parameter handling.jlink
tool to create custom runtime images without using JMOD files to improve efficiency in cloud environments.ls *.c
can significantly boost your productivity by quickly listing only the C source files in a directory, making file management easier.String
everywhere, gradually refining to using &str
for function parameters and when returning substrings, and avoiding &str
in structs.useEffect
and Ruby’s class methods, referring to both as "escape hatches" from their respective paradigms that should be used sparingly.Here’s an excerpt from “Chapter 6: Design Intelligence – Creating User-Centric Experiences with AI" in the book, AI Strategies for Web Development, by Anderson Soares Furtado Oliveira, published in September 2024.
In this example, we will create an AI-driven dynamic content personalization system for an e-commerce website. The system will use TensorFlow and Keras to analyze user behavior and personalize product recommendations based on
their shopping history. We will use the Retailrocket recommender system dataset to store user data and product information.
The workflow of the example isas follows:
However, it also hassome disadvantages:
Retailrocket recommender system dataset is a dataset of user behavior from an e-commerce website, including clicks, purchases, and views. The dataset contains 1,407,580 users and 2,756,101 behavior events, including 2,664,312 views, 69,332 cart additions, and 22,457 purchases. You can access the datasetat:https://www.kaggle.com/datasets/retailrocket/ecommerce-dataset
Next, we will learn how to manipulate and analyze this datausing Python.
In this section, we will outline a series of coding steps essential for manipulating and understanding the dataset effectively. Each step will build upon the last, guiding you through the use of various Python libraries to harness the power of this data for building an intelligentrecommender system.
import tensorflow as tf
from tensorflow import keras
import pandas as pd
events_df = pd.read_csv(
"/kaggle/input/ecommerce-dataset/events.csv"
)
user_data = events_df.groupby('visitorid').agg(
{'itemid': lambda x: list(x)}
)
model = keras.Sequential([
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(len(user_data), activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(user_data, user_data, epochs=10)
def recommend_products(user_id):
user_data = user_data[user_id]
predictions = model.predict(user_data)
recommended_products = []
for i in range(len(predictions)):
if predictions[i] > 0.5:
recommended_products.append(products[i])
return recommended_products
The result of this example is an AI-driven dynamic content personalization system for an e-commerce website that provides personalized product recommendations based onuser behavior.
In this example, we discussed techniques for implementing AI-driven dynamic content personalization in e-commerce applications. We also introduced tools like TensorFlow and Keras for incorporating AI into e-commerce environments. By following the above project, you can create a personalized product recommendation system for your e-commerce website and provide a unique shopping experience foreach user.
Note
This is a simplified example and may not work directly without some modifications depending on your development environment. Adjust itas needed.
AI Strategies for Web Development was published in September 2024. Packt library subscribers can continue reading the entire book for free or you can buy the bookhere!
That’s all for today.
We have an entire range of newsletters with focused content for tech pros. Subscribe to the ones you find the most usefulhere.
If your company is interested in reaching an audience of developers, software engineers, and tech decision makers, you may want toadvertise with us.