-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question31.py
19 lines (15 loc) · 793 Bytes
/
Question31.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np
def divide_on_feature(X, feature_i, threshold):
# Define the split function based on the threshold type
split_func = None
if isinstance(threshold, int) or isinstance(threshold, float):
# For numeric threshold, check if feature value is greater than or equal to the threshold
split_func = lambda sample: sample[feature_i] >= threshold
else:
# For non-numeric threshold, check if feature value is equal to the threshold
split_func = lambda sample: sample[feature_i] == threshold
# Create two subsets based on the split function
X_1 = np.array([sample for sample in X if split_func(sample)])
X_2 = np.array([sample for sample in X if not split_func(sample)])
# Return the two subsets
return [X_1, X_2]