Meaning of predicted values

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:

  • Class labels (like 0 or 1) if the model is a classifier.
  • Numeric values if the model is a regressor.

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:

  • 0: The percentage change between today’s close and tomorrow’s close is not positive.
  • 1: The percentage change between today’s close and tomorrow’s close is positive.

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