為機器學習準備資料

使用 Python 分析 IoT 資料

Matthias Voppichler

IT Developer

機器學習複習

  • 監督式學習
    • 分類
    • 迴歸
  • 非監督式學習
    • 叢集分析
  • 深度學習
    • 神經網路
使用 Python 分析 IoT 資料

機器學習複習

  • 監督式學習
    • 分類
    • 迴歸
  • 非監督式學習
    • 叢集分析
  • 深度學習
    • 神經網路
使用 Python 分析 IoT 資料

標籤

print(environment_labeled.head())
                     humidity  temperature  pressure   label
timestamp                                                   
2018-10-01 00:00:00      81.0         11.8    1013.4       1
2018-10-01 00:15:00      79.7         11.9    1013.1       1
2018-10-01 00:30:00      81.0         12.1    1013.0       1
2018-10-01 00:45:00      79.7         11.7    1012.7       1
2018-10-01 01:00:00      84.3         11.2    1012.6       1
使用 Python 分析 IoT 資料

Train / Test 切分

時間序列切分

  • 訓練時模型不可看到測試資料
  • 不能用隨機切分
  • 模型不應「偷看未來」
使用 Python 分析 IoT 資料

Train / Test 切分

split_day = "2018-10-13"

train = environment[:split_day] test = environment[split_day:]
print(train.iloc[0].name) print(train.iloc[-1].name) print(test.iloc[0].name) print(test.iloc[-1].name)
2018-10-01 00:00:00
2018-10-13 23:45:00
2018-10-14 00:00:00
2018-10-15 23:45:00

訓練/測試切分示意

使用 Python 分析 IoT 資料

特徵與標籤

X_train = train.drop("target", axis=1)
y_train = train["target"]
X_test = test.drop("target", axis=1)
y_test = test["target"]

print(X_train.shape) print(y_train.shape)
(1248, 3)
(1248,)
使用 Python 分析 IoT 資料

羅吉斯回歸(Logistic Regression)

from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression()
logreg.fit(X_train, y_train)
print(logreg.predict(X_test))
[0 0 1 1 1 1 1 0 0]
使用 Python 分析 IoT 資料

一起來練習吧!

使用 Python 分析 IoT 資料

Preparing Video For Download...