teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2017/05/10 08:41

投稿

trafalbad
trafalbad

スコア303

title CHANGED
File without changes
body CHANGED
@@ -16,14 +16,67 @@
16
16
 
17
17
  コード
18
18
  ```
19
+ from bottle import route, run
20
+ # -*- coding: utf-8 -*-
21
+ import pandas as pd
22
+ import numpy as np
23
+ import matplotlib.pyplot as plt
24
+ import json
25
+ import csv
26
+ from collections import OrderedDict
27
+ from sklearn.externals import joblib
28
+ #mecab
29
+ from natto import MeCab
30
+ nm = MeCab()
31
+ print(nm)
32
+ m = MeCab("-Owakati")
33
+ MODEL_FILE='bays_model-2.csv'
34
+ clf = joblib.load(MODEL_FILE)
35
+
36
+ #前処理
37
+ f = open('baysweb_word.csv', 'r')
38
+ line = json.load(f)
39
+ dek_dic={}
40
+ dek_dic={v:i for i, v in enumerate(line.drop("Unnamed: 0", axis=1).columns)}
41
+ def func(x):
42
+ if x == None:
43
+ return 1
44
+ else:
45
+ return 0 # NaN
46
+
19
47
  @route('/housmart', method="POST")
20
48
  def clean_name():
21
- curl http://localhost:8080/housmart -X POST -H "Content-Type: application/json" -d '{"clean_buldingname": "実際の建物の名前"}'
49
+ curl http://localhost:8080/housmart -X POST -H "Content-Type: application/json" -d '{"clean_buldingname": "ライオンズガーデン明大パラダイム"}'
50
+ dek_dic={}
51
+ dek_dic={v:i for i, v in enumerate(line.drop("Unnamed: 0", axis=1).columns.T)}
52
+ def func(x):
53
+ if x == None:
54
+ return 1
55
+ else:
56
+ return 0 # NaN
57
+ are=[]
58
+ for n in nm.parse(clean_buildingname, as_nodes=True):
59
+ if n.surface !="":
60
+ are.append(n.surface)
61
+ ree=[]
62
+ for i, v in dek_dic.items():
63
+ for n in are:
64
+ if i==n:
65
+ ree.append(v)
66
+ else:
67
+ pass
68
+ were=[]
69
+ for i,v in dek_dic.items():
70
+ if v in ree:
22
- #ここで単語を前処理してxxにする
71
+ were.append(None)
72
+ else:
73
+ were.append(i)
74
+ xx=pd.DataFrame(were).applymap(func).T
23
- clf.predict(xx)#予測,clfはシリアライズした分類器
75
+ clf.predict(xx)#予測
24
- if clf.predict(xx)==1:
76
+ if clf.predict(xx)==1:
25
- return str(clean_buildingname)
77
+ return str(clean_buildingname)
26
78
 
27
79
  run(host='localhost', port=8080, debug=True)
28
80
 
81
+
29
82
  ```