Any idea as to why some are correctly being filled with the predictive values and the rest are left at 0.0?
# Define features and target
columns_to_drop = ['tempmax', 'tempmin']
features = sub_beijing.drop(columns=[col for col in columns_to_drop if col in sub_beijing.columns])
target_max = sub_beijing['tempmax']
target_min = sub_beijing['tempmin']# Split the data into training and testing sets
X_train, X_test, y_train_max, y_test_max = train_test_split(features, target_max, test_size=0.2, random_state=42)
_, _, y_train_min, y_test_min = train_test_split(features, target_min, test_size=0.2, random_state=42)
# Train the model for tempmax
ridge_max = Ridge()
ridge_max.fit(X_train, y_train_max)
# Train the model for tempmin
ridge_min = Ridge()
ridge_min.fit(X_train, y_train_min)
# Predict tempmax and tempmin for the test set
y_pred_max = ridge_max.predict(X_test)
y_pred_min = ridge_min.predict(X_test)
# Ensure columns exist and set correct dtype to avoid FutureWarning
if 'predicted_tempmax' not in sub_beijing.columns:
sub_beijing['predicted_tempmax'] = 0.0
if 'predicted_tempmin' not in sub_beijing.columns:
sub_beijing['predicted_tempmin'] = 0.0
# Add predictions to the original dataframe using .loc
sub_beijing.loc[X_test.index, 'predicted_tempmax'] = y_pred_max
sub_beijing.loc[X_test.index, 'predicted_tempmin'] = y_pred_min
# Optional: Calculate and print the mean squared error for evaluation
mse_max = mean_squared_error(y_test_max, y_pred_max)
mse_min = mean_squared_error(y_test_min, y_pred_min)
print(f'Mean Squared Error for tempmax: {mse_max}')
print(f'Mean Squared Error for tempmin: {mse_min}')
# Display the dataframe with predictions
print(sub_beijing[['tempmax', 'predicted_tempmax', 'tempmin', 'predicted_tempmin']].head(60))
weird, the code seems fine. Are you sure your models are not just outputting 0 for many inputs?