Untitled

From Mustard Wigeon, 4 Months ago, written in Plain Text, viewed 65 times.
URL http://codebin.org/view/f589d4f6 Embed
Download Paste or View Raw
  1. #1.1  Балансировка целевого признака
  2. #Спобос уменьшения размера весов
  3.  
  4. dict_classes={0:1, 1:class_ratio}
  5. classificator = LogisticRegression(class_weight=dict_classes)
  6. f1_ballanced = cross_val_score(classificator,
  7.                                     features_train,
  8.                                     target_train,
  9.                                     cv=cv_counts,
  10.                                     scoring='f1').mean()
  11. print('F1 на CV с балансированными классами', f1_ballanced)
  12.  
  13.  
  14. classificator = LogisticRegression(class_weight='balanced')
  15. f1_ballanced = cross_val_score(classificator,
  16.                                     features_train,
  17.                                     target_train,
  18.                                     cv=cv_counts,
  19.                                     scoring='f1').mean()
  20. print('F1 на CV с балансированными классами', f1_ballanced)
  21.  
  22.  
  23. #Спобос ресемплинг с уменшением класса 0
  24.  
  25. df_train = df.iloc[target_train.index]
  26.  
  27. target_train_class_zero = df_train[df_train['toxic'] == 0]['toxic']
  28. target_train_class_one = df_train[df_train['toxic'] == 1]['toxic']
  29. target_train_class_zero_downsample = target_train_class_zero.sample(target_train_class_one.shape[0],
  30.                                                                     random_state=12082020)
  31. target_train_downsample = pd.concat([target_train_class_zero_downsample, target_train_class_one])
  32.  
  33. features_train_downsample = df.iloc[target_train_downsample.index]
  34. features_train_downsample, target_train_downsample = shuffle(features_train_downsample,
  35.                                                              target_train_downsample,
  36.                                                              random_state=12082020)
  37. features_train_downsample = count_tf_idf.transform(features_train_downsample['lemm_text']
  38.                                                    .values)
  39.  
  40. classificator = LogisticRegression()
  41. train_f1_downsampled = cross_val_score(classificator,
  42.                       features_train_downsample,
  43.                       target_train_downsample,
  44.                       cv=cv_counts,
  45.                       scoring='f1').mean()
  46. print('F1 на CV с уменьшением классов', train_f1_downsampled)

Reply to "Untitled"

Here you can reply to the paste above