マッチング機能を用いて分析する

ここでは、RAPID機械学習 マッチング AAPFアドオンのマッチング機能を用いた分析の例として、 求職者と求人企業の2つのデータがマッチするか予測します。

データを準備する

  1. ユーザがアクセス可能なディレクトリにrapid-matching-python-getting_started.zipを格納します。

  2. 格納したファイルを解凍します。

    $ unzip rapid-matching-python-getting_started.zip -d ~/work
    
  3. [work/examples/matching] ディレクトリに移動します。

    $ cd ~/work/examples/matching/
    
  4. 分析データファイル内の root_path[work/examples/matching/data] ディレクトリの絶対パスを指定します。

    $ sed -i '2c "root_path": "'$(pwd)/data/\", data/data_conf_ssi.json
    

分析を実行する

1. データ加工

学習データと予測データの加工を行います。

In [1]:
from rapid_matching_python import convert

convert('cls', 'data/data_conf_ssi.json')
[END]

2. 予測モデル作成

学習データを用いて分類問題の予測モデルを作成します。

In [2]:
from rapid_matching_python import train_matching

train_matching('cls', 'data/data_conf_ssi_new.json', 'data/hparam_ssi.json')
 
 
[train] avg_loss: 0.16061
 
 
[train] avg_loss: 0.16013
 
 
[train] avg_loss: 0.15758
 
 
[train] avg_loss: 0.13061
 
 
[train] avg_loss: 0.12423
 
 
[train] avg_loss: 0.12243
 
 
[train] avg_loss: 0.12164
 
 
[train] avg_loss: 0.12131
 
 
[train] avg_loss: 0.12189
 
 
[train] avg_loss: 0.12119
 
 
[train] avg_loss: 0.11056
 
 
[train] avg_loss: 0.09149
 
 
[train] avg_loss: 0.08958
 
 
[train] avg_loss: 0.08583
 
 
[train] avg_loss: 0.08445
 
 
[train] avg_loss: 0.08384
 
 
[train] avg_loss: 0.08314
 
 
[train] avg_loss: 0.08268
 
 
[train] avg_loss: 0.08330
 
 
[train] avg_loss: 0.08244
[END]

3. 結果評価

予測データと予測モデルを用いて予測を実行します。

In [3]:
from rapid_matching_python import predict_matching

predict_matching('cls', 'data/data_conf_ssi_new.json', 'data/hparam_ssi.json')
[[1999    1]
 [ 303  197]]
Precision: [0.86837533 0.99494949]
Recall: [0.9995 0.394 ]
Accuracy: 0.8784

予測結果を表示します。

In [4]:
import pandas as pd

result_df = pd.read_csv('data/predict/result_cls.csv', index_col=['q_id', 't_id'])
result_df.head(5)
Out[4]:
truth predict score
q_id t_id
1100001 1 P N 0.343
1100005 1 P N 0.335
1100009 1 P N 0.343
1100013 1 P N 0.340
1100017 1 P N 0.339

正解ラベルごとのマッチングスコアをグラフに表示して確認します。

In [5]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

df_p = result_df[result_df['truth']=='P']['score']
df_n = result_df[result_df['truth']=='N']['score']
hist_p, bins_p = np.histogram(df_p, bins=1001, range=(0, 1.001))
hist_n, bins_n = np.histogram(df_n, bins=1001, range=(0, 1.001))
plt.plot(bins_p[:-1], hist_p, 'blue')
plt.plot(bins_n[:-1], hist_n, 'red')
plt.plot([0.5, 0.5], [0.0, max(hist_p.max(), hist_n.max())], 'black', linestyle='dashed')
plt.ylim(0, max(np.r_[hist_p, hist_n]))
plt.xlabel("Score")
plt.ylabel("Number of samples")
plt.show()