Untitled

From Bistre Bongo, 3 Months ago, written in Plain Text, viewed 71 times.
URL http://codebin.org/view/a63aebc2 Embed
Download Paste or View Raw
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. # открываем файлы
  5. # возьмём индекс '0', чтобы перевести данные в pd.Series
  6. target = pd.read_csv('/datasets/eng_target.csv')['0']
  7. probabilities = pd.read_csv('/datasets/eng_probabilities.csv')['0']
  8.  
  9. def revenue(target, probabilities, count):
  10.     probs_sorted = probabilities.sort_values(ascending=False)
  11.     selected = target[probs_sorted.index][:count]
  12.     return 1000 * selected.sum()
  13.  
  14. state = np.random.RandomState(12345)
  15.    
  16. values = []
  17. for i in range(1000):
  18.     target_subsample = target.sample(frac=1, replace=True, random_state=state)
  19.     probs_subsample = probabilities[target_subsample.index]
  20.     bootstrap_sample = revenue(target_subsample, probs_subsample, 3)
  21.     values.append(bootstrap_sample)
  22.    
  23. values = pd.Series(values)
  24. lower = values.quantile(0.01)
  25.  
  26. mean = values.mean()
  27. print("Средняя выручка:", mean)
  28. print("1%-квантиль:", lower)

Reply to "Untitled"

Here you can reply to the paste above