建立特徵
在本章中,你會使用名為 sales_df 的資料集。它包含不同媒體類型的廣告投放支出,以及各自活動所帶來的銷售金額(美元)。資料集已為你預先載入。以下是前兩列:
tv radio social_media sales
1 13000.0 9237.76 2409.57 46677.90
2 41000.0 15886.45 2913.41 150177.83
你將使用廣告支出作為特徵來預測銷售值,起初先使用 "radio" 欄位。不過,在進行任何預測之前,你需要先建立特徵與目標陣列,並將它們重塑為適用於 scikit-learn 的正確格式。
本練習屬於課程
使用 scikit-learn 進行監督式學習
練習說明
- 建立
X,取自sales_dfDataFrame 的"radio"欄位值所組成的陣列。 - 建立
y,取自sales_dfDataFrame 的"sales"欄位值所組成的陣列。 - 將
X重塑為二維的 NumPy 陣列。 - 列印
X與y的形狀。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Create X from the radio column's values
X = ____
# Create y from the sales column's values
y = ____
# Reshape X
X = ____
# Check the shape of the features and targets
print(____)