Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def downsample(features, target, fraction):
- features_zeros = features[target == 0]
- features_ones = features[target == 1]
- target_zeros = target[target == 0]
- target_ones = target[target == 1]
- features_downsampled = pd.concat(
- [features_zeros.sample(frac=fraction, random_state=12345)] + [features_ones])
- target_downsampled = pd.concat(
- [target_zeros.sample(frac=fraction, random_state=12345)] + [target_ones])
- features_downsampled, target_downsampled = shuffle(
- features_downsampled, target_downsampled, random_state=12345)
- return features_downsampled, target_downsampled
- features_downsampled, target_downsampled = downsample(features_train, target_train, 0.1)
- model = RandomForestClassifier(random_state=12345, criterion='gini', max_depth=11,
- min_samples_leaf=2, n_estimators=76, class_weight='balanced')
- model.fit(features_downsampled, target_downsampled)
- predicted_valid = model.predict(features_valid)
- print("F1:", f1_score(target_valid, predicted_valid))
- #OUTPUT F1: 0.5099236641221373
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement