線性關係視覺化

Python 線性建模入門

Jason Vestuto

Data Scientist

快速繪圖

import matplotlib.pyplot as plt
plt.plot(x, y, 'r-o')
plt.show()

Python 線性建模入門

物件介面

# Import the pyplot module
import matplotlib.pyplot as plt
# Create figure and axis objects
fig, axis = plt.subplots()
# Prepare initial style options
options = dict(marker='o', color='blue')
Python 線性建模入門

物件介面

# Call the plot method on the axis object
line = axis.plot(x, y, **options)
# Modify the axis object with set methods
_ = axis.set_ylabel('Times')
_ = axis.set_xlabel('Distances')
# Display figure
plt.show()
Python 線性建模入門

線性資料視覺化

  • 兩個點:
    • (x1,y1) = (0,0)
    • (x2,y2) = (2,3)
  • x 與 y 的變化量:
    • dy = (y2 - y1) = 3 - 0
    • dx = (x2 - x1) = 2 - 0
  • 斜率=升高比位移
    • slope = dy/dx = 3/2
  • 截距:
    • x=0y1 = 0

說明「rise over run」以示斜率的圖

Python 線性建模入門

一起來練習吧!

Python 線性建模入門

Preparing Video For Download...