(This is just a joke)
This year's theme for PyCon is "Everyone is different, everyone is good".
So, let's choose a lecture that incorporates all the elements. Use the set cover problem in Combinatorial Optimization (http://qiita.com/Tsutomu-KKE@github/items/bfbf4c185ed7004b5721).
Randomly create the nationality of the speaker, the level of the lecture, the field of the lecture, etc. The score is, for example, the number of likes.
python
import numpy as np, pandas as pd
np.random.seed(1)
n = 20
a = pd.DataFrame({
'Country': np.random.choice('アメリカ イギリス インド フランス ロシア 中Country'.split(), n),
'level': np.random.choice('Beginner Intermediate Advanced'.split(), n),
'Field': np.random.choice('Data Analysis Optimization Machine Learning Document Web'.split(), n),
'score': np.random.randint(1, 10, n),
})
print(a)
level | Field | Country | score |
---|---|---|---|
0 | Beginner | Web | China |
1 | Advanced | optimisation | France |
2 | Beginner | Data analysis | Russia |
... | ... | ... | ... |
19 | Beginner | Data analysis | France |
Use ortoolpy.set_covering. Since it is minimized, the reciprocal of the score is weighted.
python
from ortoolpy import set_covering
n = sum(b.nunique() for b in [a.level, a.Field, a.Country]) #Total unique number
res = set_covering(n, [(1/r.score, r[:3].tolist()) for _, r in a.iterrows()])
print(a.ix[res])
level | Field | Country | score |
---|---|---|---|
5 | Advanced | Machine learning | France |
8 | Intermediate | document | America |
10 | Beginner | optimisation | Russia |
13 | Intermediate | Data analysis | England |
14 | Intermediate | optimisation | India |
16 | Advanced | Web | China |
You can see that all items have appeared.
that's all