Hi,
What does this line mean? “The first five predicted values [0 0 1 0 0]”
Course Name: Python for Machine Learning in Finance, Section No: 9, Unit No: 1, Unit type: Notebook
Hi,
What does this line mean? “The first five predicted values [0 0 1 0 0]”
Course Name: Python for Machine Learning in Finance, Section No: 9, Unit No: 1, Unit type: Notebook
Hi RR,
When you use the .predict()
method on a trained model in scikit-learn, it returns a NumPy array of predictions.
Example:
y_pred = rf_model.predict(X_test)
This y_pred
array contains:
You can print or slice it just like any NumPy array:
print("First five predictions:", y_pred[:5])
To compare the predicted values with the actual test labels:
for true, pred in zip(y_test[:5], y_pred[:5]):
print(f"Actual: {true}, Predicted: {pred}")
You can also convert predictions into a DataFrame for better formatting or analysis:
import pandas as pd
results = pd.DataFrame({
'Actual': y_test,
'Predicted': y_pred
})
print(results.head())
So what does first five predicted values of [0 0 1 0 0] mean? How to use it in trading?
Hi RR,
In Section 6, Unit 8
, we create the signal
variable assign it to y
.
# Create a column 'future_returns' with the calculation of percentage change
data['future_returns'] = data['close'].pct_change().shift(-1)
# Create the signal column
data['signal'] = np.where(data['future_returns'] > 0, 1, 0)
So, What does the [0 0 1 0 0] mean?
When we apply the trained model on X_test
, the classification works as follows:
The next step will be to evaluate the model’s performance.
How to Use This in Trading?
Consider the signal (0 or 1) as an indicator—you can take a long or short position based on it.
Additionally, you can combine multiple indicators to enhance the accuracy of the model’s signals.
Let me know if you have any questions!
Best,
Ajay
Knowing that 0 is non positive and 1 is positive, so what does the sequence of [0 0 1 0 0] mean? May i have someone else to answer this?
Hi Red,
The first five values are just shown for illustration purposes. The ML model forecasts whether you should take a long position (1) or close/no position (0) after each candle.
Interpretation:
I have added date time and close price to explain the interpretation of first five values.
For example, on 2019-05-28 12:30:00, the ML model predicts 1. You should go long at the close price of 109.33. On 2019-05-28 12:45:00, the ML model forecasts 0, so you should close any open position. You close your long trade at price 109.37, making a PnL of 0.04 per share from this trade.
Predicted Value | close | |
---|---|---|
2019-05-28 12:00:00+00:00 | 0 | 109.29 |
2019-05-28 12:15:00+00:00 | 0 | 109.37 |
2019-05-28 12:30:00+00:00 | 1 | 109.33 |
2019-05-28 12:45:00+00:00 | 0 | 109.37 |
2019-05-28 13:00:00+00:00 | 0 | 109.38 |
I hope this helps.
We have identified some inconsistency in the explanation of the notebook and we will also enhance the explanations in the notebook. Thank you for raising the query.
Thanks for the reply