Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.utils import shuffle
- def upsample(features, target, repeat):
- '''Данная функция создана для того, чтобы
- увеличить выборку'''
- features_zeros = features[target == 0]
- features_ones = features[target == 1]
- target_zeros = target[target == 0]
- target_ones = target[target == 1]
- features_upsampled = pd.concat([features_zeros] + [features_ones] * repeat)
- target_upsampled = pd.concat([target_zeros] + [target_ones] * repeat)
- features_upsampled, target_upsampled = shuffle(
- features_upsampled, target_upsampled, random_state=12345)
- return features_upsampled, target_upsampled
- features_upsampled, target_upsampled = upsample(features_train, target_train, 10)
- model = RandomForestClassifier(random_state=12345, criterion='gini', max_depth=11,
- min_samples_leaf=2, n_estimators=76, class_weight='balanced')
- model.fit(features_upsampled, target_upsampled)
- predicted_valid = model.predict(features_valid)
- print("F1:", f1_score(target_valid, predicted_valid))
- #OUTPUT F1: 0.5956471935853379
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement