{"id":265424,"date":"2015-09-11T11:49:02","date_gmt":"2015-09-11T07:49:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=265424"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=265424","title":{"rendered":"\u0417a\u0447\u0435\u043c \u043c\u043d\u0435 AshleyMadison, \u0435\u0441\u043b\u0438 \u044f \u043d\u0435 \u043a\u0443\u0440\u044e?"},"content":{"rendered":"<p>       \u041a\u0430\u043a \u0432\u044b \u0432\u0441\u0435 \u0443\u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0431\u044b\u043b\u0438 \u0432\u044b\u043b\u043e\u0436\u0435\u043d\u044b \u0434\u0430\u043c\u043f\u044b \u0431\u0430\u0437 AshleyMadison.<br \/>  \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0443\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0435\u0439\u0442\u0438\u043d\u0433 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b.<br \/>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e \u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0438\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a \u0432\u043e\u0437\u0440\u0430\u0441\u0442, \u0440\u043e\u0441\u0442, \u0432\u0435\u0441, \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0438 \u0438 \u0442.\u0434. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/00c\/16f\/97d\/00c16f97d1aa40bebe09b1d6fe7f4d57.png\"\/><\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c?<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0431\u0443\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f iPython notebook. <br \/>  \u0422\u0435\u043c \u043a\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 Python \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"http:\/\/ipython.org\/notebook.html\">iPython notebook<\/a> \u2014 \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e!<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0435\u0437\u043b\u0438\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <b>1. \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL<\/b><\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043b\u044c\u0451\u043c \u0434\u0430\u043c\u043f\u044b \u0432 MySQL \u0438 \u0443\u0434\u0430\u043b\u0438\u043c \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 id &lt; 35 000 000 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<br \/>  \u042f \u0432\u0437\u044f\u043b \u0442\u0430\u0431\u043b\u0438\u0446\u044b member_details \u0438 aminno_member<br \/>  \u0417\u0430\u043b\u0438\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e, \u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0441 SSD (\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0435\u0441\u044f\u0442 \u043e\u043a\u043e\u043b\u043e 10 \u0413\u0438\u0433\u043e\u0432)<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431 \u043e\u043f\u043b\u0430\u0442\u0430\u0445 \u0438\u0437 csv \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 pays c \u043f\u043e\u043b\u044f\u043c\u0438 id \u0438 sum <\/p>\n<p>  <b>2. \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 pandas<\/b><\/p>\n<p>  \u0414\u0436\u043e\u0439\u043d\u0438\u043c 3 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e id \u044e\u0437\u0435\u0440\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c DataFrame \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<br \/>  \u0411\u0435\u0440\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f\u043c\u0438, \u044f \u0434\u0443\u043c\u0430\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0445\u043e\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435.  <\/p>\n<pre><code class=\"python\">engine = create_engine('mysql:\/\/login:pass@localhost:3306\/db') # Creating MySQL engine  sql = &quot;&quot;&quot; SELECT md.pnum, p.sum, am.gender, am.photos_public, md.profile_weight, md.profile_height, md.eye_color, md.hair_color, md.dob, md.profile_smoke, md.profile_ethnicity, md.profile_bodytype, md.profile_initially_seeking FROM `member_details` AS md  JOIN `aminno_member` AS am ON md.pnum = am.pnum LEFT JOIN pays AS p ON md.pnum = p.id  WHERE md.dob is not null AND (am.photos_public &gt; 0 OR p.sum is not NULL) &quot;&quot;&quot;  df = pd.read_sql_query(sql, engine).fillna(0).set_index('pnum') #Reading data from mysql DB to pandas dataframe <\/code><\/pre>\n<p>  \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0433\u043e\u0434 \u0438 \u043c\u0435\u0441\u044f\u0446 \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"python\">df['month_of_birth'] = df['dob'].apply(lambda x:x.month) df['year_of_birth'] = df['dob'].apply(lambda x:x.year) <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043b\u0438 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f(\u043f\u043b\u0430\u0442\u0438\u043b\/\u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u043b) \u043e\u0442 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f? \u0415\u0441\u0442\u044c \u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c?<br \/>  \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 2 \u0447\u0430\u0441\u0442\u0438: df0 \u2014 \u0442\u0435 \u043a\u0442\u043e \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043f\u043b\u0430\u0442\u0438\u043b, df1 \u2014 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u043b\u0438.  <\/p>\n<pre><code class=\"python\">THRESHOLD = 0.0001  df0 = df[(df['sum'] &gt; THRESHOLD)] df1 = df[(df['sum'] &lt; THRESHOLD)] <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u0438\u043c \u043f\u043e 2 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<br \/>  \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u2014 \u0442\u0435 \u043a\u0442\u043e \u043f\u043b\u0430\u0442\u0438\u043b, \u0441\u0438\u043d\u0438\u043c \u2014 \u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u0432\u0448\u0438\u0435.  <\/p>\n<pre><code class=\"python\">cols = ['profile_weight','profile_height','year_of_birth','month_of_birth',         'eye_color', 'hair_color','profile_smoke', 'profile_ethnicity',         'profile_bodytype', 'profile_initially_seeking','gender'] for col in cols:     plt.figure(figsize=(10,10))     df0[col].hist(bins=50, alpha=0.9, color = 'red', normed=1)     df1[col].hist(bins=50, alpha=0.7, normed=1)     plt.title(col)     plt.show() <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0430\u043c\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435:<\/p>\n<p>  \u0413\u043e\u0434 \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b89\/3a4\/20e\/b893a420ea4646acaf19d7919d053c3d.png\"\/><br \/>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c: \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e. \u0421\u0442\u0430\u0440\u0448\u0438\u0435 \u043f\u043b\u0430\u0442\u044f\u0442 \u043e\u0445\u043e\u0442\u043d\u0435\u0435. \u041f\u0438\u043a \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0443 \u043f\u043b\u0430\u0442\u044f\u0449\u0438\u0445 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 35 \u043b\u0435\u0442.<\/p>\n<p>  \u0412\u0435\u0441<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c6d\/009\/f76\/c6d009f767124647a5ba7292ec6237d1.png\"\/><br \/>  \u0422\u0443\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0439: \u043e\u0445\u043e\u0442\u043d\u0435\u0435 \u043f\u043b\u0430\u0442\u044f\u0442 \u0442\u0435 \u043a\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0435\u0441\u0438\u0442. \u0425\u043e\u0442\u044f \u0442\u043e\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e<\/p>\n<p>  \u0420\u043e\u0441\u0442<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e22\/570\/32d\/e2257032d42e4e9783d624299f784656.png\"\/><br \/>  \u0412\u044b\u0441\u043e\u043a\u0438\u0435 \u043f\u043b\u0430\u0442\u044f\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0445\u043e\u0442\u043d\u0435\u0435. \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u043e\u0441\u0442 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0447\u0438\u0441\u043b\u043e\u043c, \u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u043c.<\/p>\n<p>  \u041a\u0443\u0440\u0435\u043d\u0438\u0435<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/eb4\/c11\/40a\/eb4c1140aacc4b90a6ba663090ffadea.png\"\/><br \/>  \u041a \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0441\u0442\u0430\u0442\u044c\u0438) \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044f\u0432\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0432\u043e\u043f\u0440\u043e\u0441 \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 1,2,3,4?<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0434\u0430\u044e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b, \u0445\u043e\u0442\u044f \u0442\u043e\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434.<br \/>  <a href=\"https:\/\/gist.github.com\/seshaln\/bbad57ad0d3649ca6ebb\">\u0417\u0434\u0435\u0441\u044c<\/a> \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e notebook \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438.<\/p>\n<p>  <b>2. \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u043b\u0430\u0442\u044b<\/b><\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0438\u043c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u043f\u043b\u0430\u0442\u0438\u043b\/\u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u043b) \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c  <\/p>\n<pre><code class=\"python\">y = (df['sum'] &gt; THRESHOLD).astype(np.int32) <\/code><\/pre>\n<p>  \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0438\u0445 \u0431\u0438\u043d\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u044e  <\/p>\n<pre><code class=\"python\">categorical = ['month_of_birth',         'eye_color', 'hair_color','profile_smoke', 'profile_ethnicity',         'profile_bodytype', 'profile_initially_seeking'] ohe = preprocessing.OneHotEncoder(dtype=np.float32) Xcategories = ohe.fit_transform(df[categorical]).todense() <\/code><\/pre>\n<p>  \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0438\u0445 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0431\u0438\u043d\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438  <\/p>\n<pre><code class=\"python\">numeric = ['gender','profile_weight','profile_height','year_of_birth'] Xnumeric = df[numeric].as_matrix()  X = np.hstack((Xcategories,Xnumeric)) <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043d\u0430 2 \u0447\u0430\u0441\u0442\u0438 90% \u0438 10%. \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0438 \u0442\u044e\u043d\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c. \u041d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.  <\/p>\n<pre><code class=\"python\">X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.1, random_state=7) <\/code><\/pre>\n<p>  \u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 RandomForest \u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.  <\/p>\n<pre><code class=\"python\">from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier from sklearn import decomposition, pipeline, metrics, grid_search  rf = RandomForestClassifier(random_state=7, n_jobs=4) scl = StandardScaler() clf = pipeline.Pipeline([('scl', scl),                          ('rf', rf)])  param_grid = {'rf__n_estimators': (100,200),               'rf__max_depth': (10,20),               } model = grid_search.GridSearchCV(estimator = clf, param_grid=param_grid, scoring='roc_auc',                                      verbose=10, cv=3)  model.fit(X_train, y_train) print(&quot;Best score: %0.3f&quot; % model.best_score_) print(&quot;Best parameters set:&quot;) best_parameters = model.best_estimator_.get_params() for param_name in sorted(param_grid.keys()):     print(&quot;\\t%s: %r&quot; % (param_name, best_parameters[param_name])) <\/code><\/pre>\n<p>  <\/p>\n<pre><code>Best score: 0.802 Best parameters set: \trf__max_depth: 20 \trf__n_estimators: 200 <\/code><\/pre>\n<p>  \u041e\u0446\u0435\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432  <\/p>\n<pre><code class=\"python\">best = model.best_estimator_ print best.steps[1][1].feature_importances_ <\/code><\/pre>\n<p>  <\/p>\n<pre><code>[ 0.01083346  0.00745737  0.00754652  0.00764087  0.0075468   0.00769951   0.00780227  0.0076059   0.00747405  0.00733789  0.00720822  0.00720196   0.01067164  0.00229657  0.00271315  0.00403617  0.00453246  0.00420906   0.01227852  0.00166965  0.00060406  0.00293115  0.00347255  0.00581456   0.00176878  0.00060611  0.00129565  0.06303697  0.00526695  0.00408359   0.04618295  0.03014204  0.00401634  0.00312768  0.0041792   0.00073294   0.00260749  0.00137382  0.00385419  0.03020433  0.00788376  0.01423438   0.00953692  0.01218361  0.00685376  0.00812187  0.00433835  0.00294894   0.01210143  0.00806778  0.00458055  0.01323813  0.01434638  0.0120177   0.03383968  0.1623351   0.11347244  0.2088358 ] <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435(\u043f\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438): year_of_birth, profile_weight, profile_height<\/p>\n<p>  \u041e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c ROC \u043a\u0440\u0438\u0432\u0443\u044e  <\/p>\n<pre><code class=\"python\">from sklearn.metrics import roc_curve,roc_auc_score y_pred = best.predict_proba(X_test).T[1] print roc_auc_score(y_test,  y_pred)  fpr, tpr , thresholds = roc_curve(y_test, y_pred) plt.figure(figsize=(10,10)) plt.plot(fpr, tpr, label='ROC curve') plt.plot([0, 1], [0, 1], 'k--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver operating characteristic') plt.legend(loc=&quot;lower right&quot;) plt.show() <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a9b\/6f0\/1d7\/a9b6f01d712345c295c5073d2c57bd04.png\"\/><br \/>  \u0414\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ROC-%D0%BA%D1%80%D0%B8%D0%B2%D0%B0%D1%8F\">ROC_AUC score<\/a><br \/>  ROC_AUC = 0.79926<\/p>\n<p>  <b>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/b><br \/>  \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043a\u043b\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a \u043e\u043f\u043b\u0430\u0442\u0435 \u0443\u0441\u043b\u0443\u0433 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e. \u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u0430\u044f (roc_auc = 0.8), \u043d\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u044b(\u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445)<br \/>  \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442: <a href=\"https:\/\/gist.github.com\/seshaln\/bbad57ad0d3649ca6ebb\">gist.github.com\/seshaln\/bbad57ad0d3649ca6ebb<\/a><\/p>\n<p>  <b>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/b>  <\/p>\n<ul>\n<li>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u043a\u0443\u0441\u043e\u0432\/\u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439. \u0412 \u0431\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u044f &#8216;pref_opento&#8217;,&#8217;pref_lookingfor&#8217; \u0432\u0438\u0434\u0430 \u00ab12|17|58|97\u00bb \u2014 \u044d\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442. \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e, \u0430 \u0432\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/li>\n<li>\u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443, \u0430 \u043d\u0435 \u0444\u0430\u043a\u0442 \u043e\u043f\u043b\u0430\u0442\u044b.<\/li>\n<li>\u041f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c\u0438, \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b photos_public &gt; 0)<\/li>\n<li><b>\u0412\u0430\u0448\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f?<\/b><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/266639\/\"> http:\/\/habrahabr.ru\/post\/266639\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041a\u0430\u043a \u0432\u044b \u0432\u0441\u0435 \u0443\u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0431\u044b\u043b\u0438 \u0432\u044b\u043b\u043e\u0436\u0435\u043d\u044b \u0434\u0430\u043c\u043f\u044b \u0431\u0430\u0437 AshleyMadison.<br \/>  \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0443\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0435\u0439\u0442\u0438\u043d\u0433 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b.<br \/>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e \u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0438\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a \u0432\u043e\u0437\u0440\u0430\u0441\u0442, \u0440\u043e\u0441\u0442, \u0432\u0435\u0441, \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0438 \u0438 \u0442.\u0434. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/00c\/16f\/97d\/00c16f97d1aa40bebe09b1d6fe7f4d57.png\"\/><\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-265424","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265424"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265424\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}