Menu

Feature Engineering

Feature Engineering

Instead of directly using all stock prices, we create two informative features.

Feature 1

Difference between opening and closing prices.

stock_data['Open_Close'] = (
    stock_data['Open']
    - stock_data['Close']
)

Feature 2

Difference between highest and lowest prices.

stock_data['High_Low'] = (
    stock_data['High']
    - stock_data['Low']
)

Explanation

These engineered features summarize daily price movement and volatility, helping the KNN model learn market behavior more effectively.