56
FB Page: ขี่ช้างจับข้อมูล www.elephant-analytics.com 1

FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

1

Page 2: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Turning DataintoInsight

https://www.youtube.com/watch?v=6jDjeNJrN14

Page 3: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Peerapong E.(aka. PE)Professional Petroleum Engineer

Specialized in Production Optimization

Inventor of Optimization Intellectual Property

Education

• Msc, Petroleum Engineering (Optimization),

Texas A&M University [Fulbright Scholarship]

• Certified Rapidminer Analyst

Work Experience

• PTT Group RD&T Gold Award Team Leader

• PTTEP, Data Sci Team Leader, PTTEP Digital Transformation

• Founder of FB page Elephant Data

Thailand (ข่ีช้างจบัข้อมลู)

• Founder of DEXTRACT solution3

Page 4: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Charity Workshop: Battle of Top Data-Sci Software

Page 5: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

• Workshop ในระดบั introduction เพ่ือช่วยให้บคุคลทัว่ไปที่สนใจสามารถตดัสินใจเลือก application ท่ีเหมาะสม

• เปรียบเทียบการท างานของ software หลายๆตวั ในการแก้ปัญหาแบบเดียวกนั เพ่ือดโูครงสร้างของ programming language และ demo application

• Free event น าเงินบริจาคให้การกศุลทัง้หมด

• Slide ทัง้หมด จะ upload ให้ใน FB เพจ ข่ีช้างจบัข้อมลู นะครับ

ท่ีมาของ charity workshop อนัน้ี

พีWeb scraping

พี่เอกRapidminer

Page 6: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

มาท าบุญดว้ยกนัเงินบริจาคทั้งหมด ไม่หกัค่าใชจ่้าย บริจาคใหก้บั

6

สนบัสนนุกลุ่มลกูเหรียง เพ่ือเป็นทนุการศกึษาของเด็กสามจงัหวดัชายแดนใต้ ท่ีครอบครัวเสียชีวิตจากเหตไุม่สงบ

บริจาคให้สตัว์พกิาร ท่ีมลูนิธิบ้านสงเคราะห์สตัว์พกิาร

บริจาคเพ่ือช่วยซือ้เคร่ืองช่วยหายใจในเด็กกบัโรงพยาบาลเด็ก

Page 7: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Why Programming?

Page 8: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Programming trend for new generation

8

Page 9: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Write application with Python

Basic Programming with Python

Code with drag & drop

(Scratch)

Logical Thinking

9

It will be 3rd language for Thai student

https://www.blognone.com/node/102435

Page 10: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Why is it so hard to start something

Page 11: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

The very first questions before getting startedเหตุการณ์สมมุติจากเร่ืองจริง หลายๆคร้ัง

พี อยากเรียนเขียน code

เอาดิ เริ่มเลย

เริ่มเรียนตัวไหนดี

มีสามตัวแนะน า

R มี function stat เยอะ syntax ไม่ยาก

Python ท าอะไรได้หลากหลาย ตัวเดียวครบ

RapidMiner ท า data sci ได้ไม่ต้องเขียน code

ลองหาดู มีเรียน online เยอะเลย

www.udemy.com

www.datacamp.com

www.coursera.org

Read10:00

Read10:05

Read10:05

Read10:06

Read10:06

Read10:06

Read10:07

Read10:07

Read10:07

9:58

10:02

นาย ก. (นามสมมตุ)ิ

เป็นไงบ้าง เรียนไปถึงไหนละ

เรื่องไรวะ

ที่บอกว่าจะเรียนเขียน program ไง

มาๆ งั้นจัด Workshop สอน Intro ให้หมดเลย

สึดดดด แล้วจะได้เริ่มม๊ัยยยย

Read09:13

Read09:16

Read09:17

Read09:12

นาย ก. (นามสมมตุ)ิ6 months later …

งานยุ่งว่ะ ยังไม่ได้เริ่มเลย T_T

Read09:15

Read09:05

Read09:14

แล้วมาท าVisualize Power BI สวยๆ ฟรีด้วยRead10:06

Page 12: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Learning curve

http://spatial-ecology.net/?p=725

Page 13: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Which Applications to

get started?

Page 14: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

KDnuggets Poll 2018

About KDnuggetshttps://www.kdnuggets.com/about/index.html

2018 KDnuggets Poll:

What software you used for

Analytics, Data Mining, Data

Science, Machine Learning

projects in the past 12 months?

Page 15: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

“Not competition, but collaboration”

Page 16: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

หา Condoราคาไม่แพงใกลอ้อฟฟิศ

วิเคราะห์ ราคาคอนโด ใน กรุงเทพ และ แนวโน้มราคาในอนาคต

Page 17: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Data Sci Workflow

Data collection Data Cleaning Data Mining Visualization

Data Geek

Require Intensive Coding

Business User

Expensive+

Various software

This Workshop

Get big picture of

workflow + Compare various

software

Page 18: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Searching Condo Ver 0.4

Page 19: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Searching condo for Thailand 4.0Condo price: Hipflat.com

Collect price from all condo with Python web scraping

Data collection Data Cleaning Data Mining Visualization

Page 20: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Scikit Learn in Python20

Simple Machine Learning Example

Same Data set and algorithm, Various Method

Data collection Data Cleaning Data Mining Visualization

Page 21: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Data Cleansing and Mining

Linear Regression Multivariate Linear Regression

Simplified Workflow using Multivariate Linear Regression*Only regression part, no cross-validation, feature engineering …*

Data collection Data Cleaning Data Mining Visualization

Page 22: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Every web has it’s own insightCondo price: Hipflat – Sales Price

Data Visualization with Power BI

Page 23: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Full loop data analytics workshop

Data collection Data Cleaning Data Mining Visualization

Data Visualization with Power BI

Page 24: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Our Instructors

Page 25: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Agenda

Schedule Topic Instructor

08:30 Registration

09:00 Introduction to the eventWeb Scraping for data preparationMachine Learning Example

Peerapong

09:40 Introduction to Rapidminer studioMachine Learning Example

Dr. Eakasit

10:20 Break

10:40 Power of Analytics with RMachine Learning Example

Dr. Kanokwan

11:20 Introduction to Power BIData Visualization and analytics

Rapheephan

11:50 Games (with free gift)

12:00 Finish

Page 26: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

26

Python as an opensource programming

Page 27: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

27

The Infinity Libraries

Page 28: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

• Python Anaconda Package Introduction

• Demo : Web Scraping with BeautifulSoup

• Demo : Multivariate Linear Regression

• Optional Demo : Web Scraping with Selenium

28

Section#1 Python

Page 29: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

29

Anaconda Package

Page 30: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

30

Anaconda is…

Umm, yes it is; but it’s not anaconda we mention here

Page 31: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

31

Without the interface (IDE)

Text file (.py)

Running script in command prompt

This is the conventional way to run Python

การรัน Python แบบดัง้เดิม ท่ีเห็น Geek รันกนั แตเ่ราจะท าอีกแบบท่ีง่ายกว่านัน้

Page 32: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

• Anaconda is a free and open source distribution of the Python and Rprogramming languages for data science and machine learning related applications

• That aims to simplify package management and deployment.

• The Anaconda distribution is used by over 6 million users, and itincludes more than 250 popular data science packages suitable for Windows, Linux, and MacOS.[5]

32

Anaconda is…

Yes!!!Everyone can

develop

Originally support

Python, R is added later

With anaconda, (most of) Python environment is ready to use

The pre-installed “infinity stones”

Page 33: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Download Anaconda

33

www.anaconda.com

Page 34: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Open via Anaconda Navigator

34

Page 35: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Open via Anaconda Navigator

35

We will use the Jupyternotebook for this workshop

For practical development, recommend Spyder

Page 36: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Notebook Shellstyle coding

Top-Down conventional style coding

IDE สองตวัท่ีจะใช้ใน class คือ Spyder และ Jupyter เพ่ือท าให้ชีวิตง่ายขึน้36

Page 37: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Spyder IDE

http://sjbyrnes.com/python/37

Spyder แบง่แยก Partition ของการท างาน คล้ายๆ Rstudio (ส าหรับคนท่ีเคยเขียน R มา)

Page 38: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Jupyter Notebook

https://techtalktone.wordpress.com/2017/03/28/running-jupyter-notebooks-on-a-remote-server-via-ssh/

38

Jupyter จะใช้เป็นหลกัใน workshop นี ้จะเน้นการสอดแทรก Text และ รัน code ทีละ step

Page 39: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Notebook Shellstyle coding

Top-Down conventional style coding

39เปรียบเทียบหน้าตา Spyder รันรวดเดียวจบ Jupyter รันทีละ cell

Page 40: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

การมีข้อมลู

จุดเร่ิมตน้ของการวเิคราะห์ขอ้มูลคือ

40

Page 41: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

41

The Fundamental Step of Data

Turning Unstructured Data to be Structured

Page 42: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Python for Scraping

https://medium.com/the-andela-way/introduction-to-web-scraping-87edf94ac692

What is web scraping?

Web scraping is a technique for gathering data or information on web pages. A scraper is a script that parses an html site. Scrapers are bound to fail in cases of site re-design.

As much as there’re many libraries that support web scraping, we will delve into web scraping using python libraries.

Why python?

Python is one of the most popular languages for web crawling. In this tutorial, I will use beautiful soup since it is easy and highly efficient.

42

Scraping คือการเอา data จาก Website ดงึมาอยูใ่นรูปแบบที่เราสามารถใช้งานตอ่ได้ เช่น Excel, CSV, Text

Page 43: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

Key Idea in this workshop

Web Data Excel

ExtractionSummarize Further

work

43

เราจะเน้น Technique ในการดงึข้อมลูจากเวปในรูปแบบตา่งๆ แล้วน ามาเก็บไว้ใน Excel โดยใช้ Jupyter Notebook เป็นตวัช่วย

Page 44: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

BeautifulSoup

Web Scraping in Python

Selenium Scrapy

• Quick Easy to implement web scraping

• Entry library for web scraping

• Automated web testing automation

• Can perform human-like task

• Can handle web wthjavascript

• Framework for large scale web scraping

Page 45: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Html code inside the web

• Right Click at any place on the web page• Select inspect element

• HTML code show up

45

ข้างใน Web ถกูเขียนด้วย HTML structure

Page 46: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

• Extract multiple elements from Hipflat using

beautifulsoup library

Workshop46

Page 47: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Let’s do the exercise

SC-14_Hipflat_Abstracts

47

Page 48: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Export data to Excel with openpyxl library

48

Page 49: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Openpyxl library

https://openpyxl.readthedocs.io/en/stable/

Openpyxl is a Python library for reading and writing Excel 2010• Xlsx (will use in this workshop)• xlsm• xltx• xltm

49

Library เพ่ือให้ Python ติดต่อกบั Excel

Page 50: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Idea Flowchart

func_Scrape- Input = URL- Operation = Web scraping- Output = Data from web

func_PrintExcel- Input = data to be printed- Operation→ print to excel and save

New URL:For loop

50

Page 51: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Let’s do the exercise

Scraping and save to ExcelSC-15_Hipflat_Full_Loop

51

Page 52: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Machine Learning Project: Condo PricePrediction

Proj-03_CondoPricePrediction

52

Page 53: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Common form of Data Mining

Use Correlation to predict “Number”

Use Correlation to Classify Type

53

Page 54: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Multivariated Linear Regression

Linear Regression Multivariated Regression

54

y = f(x) y = f(x1,x2,x3,x4,…)

Page 55: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

Multivariated Linear Regression55

Input:- Year Built

- Number of Floor

- Distance to BTS/MRT Station

- Distance to Siam Paragon

Output:- Sale Price

Model Matching

Prediction

- Use the model to predicted sales price of 30th floor condo

- At predefined location (100 locations)- Year built from 2018 – 2025

Page 56: FB Page: ขี่ช้างจับข้อมูล  · FB Page: ขี่ช้างจับข้อมูล ... Web scraping is a technique for gathering data or information

FB Page: ข่ีช้างจบัข้อมลู www.elephant-analytics.com

PJ-3A_ScikitLearn

Workshop on Python MultivariatedRegrssion