EP 4 : การใช้งาน Azure Machine Learning and Microsoft Dynamics 365 for Finance and Operations

--

ในบล็อคนี้ เราจะมาลองทำ basic Data Mining ด้วย Azure Machine Learning กัน โดยฐานข้อมูลที่ใช้จะอยู่บน Azure SQL Database และข้อมูลถูก integration มาจากโปรแกรม Dynamics 365 for Finance and Operations

ตัวอย่างในบล็อคนี้ จะเป็นการนำข้อมูลการขายปลีก (Retail) มาหากฏความสัมพันธ์ (Association Rules) เพื่อนำมาวิเคราะห์ ว่าลูกค้าซื้ออะไรคู่กับสินค้าอะไรบ่อยๆ ทำให้สามารถออกโปรโมชั่นแคมเปญคู่กัน ทำให้มีราคาถูกลง เพื่อที่จะเพิ่มมูลค่ายอดขายสินค้าได้

เตรียม Azure SQL Database

ขั้นตอนแรก เราต้องเตรียมฐานข้อมูลให้เรียบร้อย โดยสามารถทำตาม link นี้ได้เลยครับ https://docs.microsoft.com/en-us/azure/azure-sql/database/design-first-database-tutorial

note* การใช้บริการ azure cloud platform นั้นมีค่าใช้จ่าย และเราต้องทำการผูกบัตรเครดิตไว้กับ azure subscription ด้วยนะ (เบื้องต้นมีให้ทดลองใช้ฟรี $200 usd สำหรับ account ใหม่)

Bring your own database (BYOD)

Dynamics 365 for Finance and Operations ทำการตั้งค่า export data ผ่าน Data management workspace, ไปที่เมนู Configure Entity export to database

ตั้งค่า connection string ของ azure sql database

Data Source=<logical server name>,1433; Initial Catalog=<your DB name>; Integrated Security=False; User ID=<SQL user ID>; Password=<password>

กด Publish Entity store, เลือก Publish entity ที่เราต้องการนำข้อมูลส่งออกไป ทั้งนี้ระบบจะไป create staging table ใน database ให้เราอัตโนมัติ

ทำการนำข้อมูลส่งออก ด้วยเมนู Export เพียงแต่เลือก target เป็น entity store ที่เราตั้งค่าไว้

เมื่อ job run เสร็จเรียบร้อย เรากลับมาเช็คข้อมูลที่ azure sql database จะได้ดังรูป

ขั้นตอนต่อมา เราต้อง prepare data ตามรูปแบบ input ของ model ที่ใช้ ……(เปลี่ยน item by transaction เป็น Itemsets)
ฝั่งซ้ายคือ transaction เดิม
ฝั่งขวาคือ transaction ที่ model ต้องการ

sql select statement เราจะใช้คำสั่งประมาณนี้

SELECT Main.TRANSACTIONNUMBER, LEFT(Main.CATEGORYNAME,Len(Main.CATEGORYNAME)-1) As “Items”
FROM (SELECT DISTINCT RetailTrans2.TRANSACTIONNUMBER,
(
SELECT ‘i’ + RetailTrans1.CATEGORYNAME + ‘,’ AS [text()]
FROM [dbo].[RetailTransactionSalesLineV2Staging] RetailTrans1
WHERE RetailTrans1.TRANSACTIONNUMBER = RetailTrans2.TRANSACTIONNUMBER
and RetailTrans1.CATEGORYNAME != ‘’
GROUP BY RetailTrans1.TRANSACTIONNUMBER, RetailTrans1.CATEGORYNAME
FOR XML PATH (‘’)
) [CATEGORYNAME]
FROM [dbo].[RetailTransactionSalesLineV2Staging] RetailTrans2
WHERE RetailTrans2.CATEGORYNAME != ‘’
) [Main]
ORDER BY TRANSACTIONNUMBER

Microsoft Azure Machine Learning Studio

Azure ML Studio เป็นเครื่องมือไว้ทำ Machine Learning มีเครื่องมือ GUI-Based ให้ใช้งาน นั่นหมายความว่าเราก็แค่ drag and drop เอา Module ที่ต้องการมาประกอบกันเพื่อทำ Machine Learning และมันก็เป็น Web Based เราสามารถใช้งานบน Web Browser ได้เลย … cr. Supanat Jintawatsakoon

ขั้นตอนแรกสร้าง Experiments

เลือก Import Data จาก Azure SQL Database, setup connection และ database query

เมื่อเราทำการ Run Experiments เราสามารถดูข้อมูลหรือผลลัพธ์การทำงานหลังจาก node นั้นๆทำงานเสร็จได้, เช็คข้อมูลว่านำเข้าตาม format ที่เราต้องการหรือไม่

เลือก Algorithms Model ที่เราจะนำมาใช้แก้ปัญหา ในทีนี้เราจะใช้ Discover Association Rules (เลือกที่ระบบมีมาให้เบื้องต้นทางซ้ายมือ หรือกด import มาจาก gallery ก็ได้)

ตั้งค่า model options ด้านขวาตามรูป แล้ว run experiments อีกครั้ง

ผลลัพธ์ที่ออกมาทำให้เราทราบว่า สินค้าที่ขายคู่กันใน 1 บิล ตั้งแต่ 2–3 ชิ้น เป็นสินค้าอะไรที่ขายดีที่สุดครับ

สุดท้ายนี้ ขอขอบคุณ

ขั้นตอนการหากฏความสัมพันธ์ (Association Rules) (http://dataminingtrend.com/2014/association-rules)

Bring your own database (BYOD) from Dynamics 365 for Finance and Operations (https://us.hitachi-solutions.com/knowledge-center/bring-your-own-database-for-dynamics-365-finance-operations-part-2)

ลองเล่น Azure Machine Learning Studio (https://medium.com/@SupanatJ/c7e7d0621ef7)

จบ…

--

--

Teerapong Mukdapipatkul (Bee) 😄

Microsoft Dynamics 365 Developer at QUICK ERP and Co-Founder at Analytic Business Solutions linkedin.com/in/teerapong-muk