On Chinese Valentine's day, I wrote a matchmaking model in Python

Tianyuan prodigal son 2020-11-13 09:06:15
chinese valentine day wrote matchmaking


Say it first : This article is purely a work of entertainment on the Double Seventh Festival . If someone follows the mate selection theory proposed in this model and leads to lovelorn or single , Except for compassion , I can't make up for more .

In traditional Chinese festivals , Tanabata may be the most mysterious origin 、 The most profound one . Of course , This is not the point of this article , Our core problem is : On the special commemorative day of Chinese Valentine's Day , You really want to talk to TA A confession ?TA Is it really the only right choice for you ? This matchmaking model , Maybe it's enlightening for you .

My matchmaking agency is doing well , Countless single people who want to find their ideal partner come to visit . According to the appearance 、 character 、 Ability 、 Wealth and other factors , I set a quality index for each client (Quality Index), Shorthand for qidx. Statistical findings ,qidx Show the mean 8.0、 Standard deviation 0.5 Normal distribution .

Here is 1 Million customers qidx Statistical distribution , You can see that most single people have qidx be located 7.0~9.0 Between , Evaluate negative and excellent , All belong to the minority .

import numpy as np
import matplotlib.pyplot as plt
singles = np.random.normal(loc=8.0, scale=0.5, size=10000)
plt.hist(singles, bins=8, histtype='step')
plt.show()

 Insert picture description here
In general , My clients pay 1 Time , Will get 10 Second choice opportunity . My strategy for recommending goals to clients is based on “ suitable ”, Always choose with the customer qidx Adaptive opposite sex , Specifically speaking, it is based on the customer's qidx Is the mean , With 0.1 The variance of , Random generation according to normal distribution .

Usually , There are two ways for customers to choose from the goals I recommend to them . The first is based on the traditional concept of mate selection , The specific rules are as follows .

  1. Yes 10% 's customers will fall in love with their current recommendation target at first sight , Don't care about both sides qidx match
  2. If the current recommended target is qidx Higher than the customer , But not more than 0.2, The probability that the customer chooses the current recommended target , It will increase as the number of remaining options decreases , About from 0.35 Rise to be 0.8
  3. If the current recommended target is qidx Higher than the customer 0.2 above , The probability that the customer chooses the current recommended target , It will increase as the number of remaining options decreases , About from 0.55 Rise to be 1.0
  4. If the current recommended target is qidx Lower than customers , But not more than 0.2, The probability that the customer chooses the current recommended target , It will increase as the number of remaining options decreases , About from 0.25 Rose to 0.7
  5. If the current recommended target is qidx Lower than customers 0.2 above , The probability that the customer chooses the current target , It will increase as the number of remaining options decreases , About from 0 Rose to 0.18

The second way of matching is based on “ Grain theory ”, It sounds very tall . The explanation of wheat ear theory is omitted here , Interested students can search by themselves . specifically , It's the customer that comes first 4 In the second recommendation , No choice , Just write down the tallest of them qidx; From 5 Time to start , As long as you encounter more than or equal to before 4 Second highest qidx Recommended target for , Make a choice .

below , I use two ways to match 1 Ten thousand customers choose their spouses , What will happen ?

# -*- encoding: utf-8 -*-
import numpy as np
class Single:
def __init__(self, qidx, times):
self.times = times # The number of matches provided by the matchmaker 
self.counter = 0 # The current number of matches 
self.qidx = qidx # Customer's qidx
self.spouse = None # Matching a successful spouse qidx
self.histroy = list() # Based on the theory of ear of wheat times/e Second, the recommended object of qidx
def math_classical(self, spouse):
self.counter += 1
if np.random.random() < 0.1:
self.spouse = spouse
if spouse - self.qidx >= 0.2:
if np.random.random() < 1-0.05*(10-self.counter):
self.spouse = spouse
elif spouse - self.qidx > 0:
if np.random.random() < 0.8-0.05*(10-self.counter):
self.spouse = spouse
elif self.qidx - spouse >= 0.2:
if np.random.random() < 0.18-0.02*(10-self.counter):
self.spouse = spouse
elif self.qidx - spouse >= 0:
if np.random.random() < 0.7-0.05*(10-self.counter):
self.spouse = spouse
def match_technical(self, spouse):
self.counter += 1
if self.counter < self.times/np.e:
self.histroy.append(spouse)
elif spouse >= max(self.histroy):
self.spouse = spouse
def main(math_mode, total=10000, times=10):
# The total number of builds is total The customer , Its qidx There is normal random function generation 
singles = [Single(np.random.normal(loc=8.0, scale=0.5), times) for i in range(total)]
for p in singles:
for i in range(10):
if p.counter < 10 and not p.spouse:
spouse = np.random.normal(loc=p.qidx, scale=0.1)
getattr(p, math_mode)(spouse)
matched = np.array([(p.qidx, p.spouse) for p in singles if p.spouse])
diff = matched[:,0] - matched[:,1]
print('----------------------------------')
print(' A successful match %d people , The success rate %0.2f%%'%(matched.shape[0], matched.shape[0]*100/total))
print(' Customer qidx mean value %0.2f, Spouse mean %0.2f'%(np.sum(matched[:,0])/matched.shape[0], np.sum(matched[:,1])/matched.shape[0]))
print(' Matching variance %0.2f, Matching standard deviation %0.2f'%(diff.var(), diff.std()))
print()
if __name__ == '__main__':
print(' Based on the statistical results of traditional mate selection ')
main('math_classical')
print(' Statistical results of mate selection based on wheat ear theory ')
main('match_technical')

Compare the matching success rate of the two schemes 、 Match the average of successful customers qidx、 The average spouse of a successful customer qidx、 Clients and spouses qidx And so on , You'll find that , This result is really interesting .

 Based on the statistical results of traditional mate selection
----------------------------------
A successful match 10000 people , The success rate 100.00%
Customer qidx mean value 8.00, Spouse mean 8.02
Matching variance 0.01, Matching standard deviation 0.10
Statistical results of mate selection based on wheat ear theory
----------------------------------
A successful match 7138 people , The success rate 71.38%
Customer qidx mean value 8.00, Spouse mean 8.11
Matching variance 0.00, Matching standard deviation 0.07

Conclusion :

  1. Choosing a mate based on the traditional way , Higher success rate (100% VS 71.38%);
  2. Based on the theory of ear of wheat , Spouse quality index is higher (8.11 VS 8.02);
  3. Based on the theory of ear of wheat , The two sides qidx The standard deviation of the difference is smaller (0.07 VS 0.10), This means that both sides match better .
版权声明
本文为[Tianyuan prodigal son]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database