#31 · Machine Learning · Medium
⊣ Solve on deep-ml.comDivide a dataset into two subsets based on a feature threshold. Given a dataset (2D NumPy array), a feature index, and a threshold value, split the data into rows where the feature value is greater than or equal to the threshold and rows where it is less.
import numpy as np
def divide_on_feature(X, feature_index, threshold):
left = X[X[:, feature_index] >= threshold]
right = X[X[:, feature_index] < threshold]
return left, rightfeature_index from every row.>= threshold for the left split and < threshold for the right split.