質問編集履歴

1

追記

2017/05/10 08:41

投稿

trafalbad
trafalbad

スコア303

test CHANGED
File without changes
test CHANGED
@@ -34,19 +34,123 @@
34
34
 
35
35
  ```
36
36
 
37
+ from bottle import route, run
38
+
39
+ # -*- coding: utf-8 -*-
40
+
41
+ import pandas as pd
42
+
43
+ import numpy as np
44
+
45
+ import matplotlib.pyplot as plt
46
+
47
+ import json
48
+
49
+ import csv
50
+
51
+ from collections import OrderedDict
52
+
53
+ from sklearn.externals import joblib
54
+
55
+ #mecab
56
+
57
+ from natto import MeCab
58
+
59
+ nm = MeCab()
60
+
61
+ print(nm)
62
+
63
+ m = MeCab("-Owakati")
64
+
65
+ MODEL_FILE='bays_model-2.csv'
66
+
67
+ clf = joblib.load(MODEL_FILE)
68
+
69
+
70
+
71
+ #前処理
72
+
73
+ f = open('baysweb_word.csv', 'r')
74
+
75
+ line = json.load(f)
76
+
77
+ dek_dic={}
78
+
79
+ dek_dic={v:i for i, v in enumerate(line.drop("Unnamed: 0", axis=1).columns)}
80
+
81
+ def func(x):
82
+
83
+ if x == None:
84
+
85
+ return 1
86
+
87
+ else:
88
+
89
+ return 0 # NaN
90
+
91
+
92
+
37
93
  @route('/housmart', method="POST")
38
94
 
39
95
  def clean_name():
40
96
 
41
- curl http://localhost:8080/housmart -X POST -H "Content-Type: application/json" -d '{"clean_buldingname": "実際の建物の名前"}'
97
+ curl http://localhost:8080/housmart -X POST -H "Content-Type: application/json" -d '{"clean_buldingname": "ライオンズガーデン明大パラダイム"}'
42
98
 
43
- #ここで単語を前処理してxxにする
99
+ dek_dic={}
44
100
 
45
- clf.predict(xx)#予測,clfはシリアライズした分類器
101
+ dek_dic={v:i for i, v in enumerate(line.drop("Unnamed: 0", axis=1).columns.T)}
46
102
 
47
- if clf.predict(xx)==1:
103
+ def func(x):
48
104
 
105
+ if x == None:
106
+
107
+ return 1
108
+
109
+ else:
110
+
111
+ return 0 # NaN
112
+
113
+ are=[]
114
+
115
+ for n in nm.parse(clean_buildingname, as_nodes=True):
116
+
117
+ if n.surface !="":
118
+
119
+ are.append(n.surface)
120
+
121
+ ree=[]
122
+
123
+ for i, v in dek_dic.items():
124
+
125
+ for n in are:
126
+
127
+ if i==n:
128
+
129
+ ree.append(v)
130
+
131
+ else:
132
+
133
+ pass
134
+
135
+ were=[]
136
+
137
+ for i,v in dek_dic.items():
138
+
139
+ if v in ree:
140
+
141
+ were.append(None)
142
+
143
+ else:
144
+
145
+ were.append(i)
146
+
147
+ xx=pd.DataFrame(were).applymap(func).T
148
+
149
+ clf.predict(xx)#予測
150
+
151
+ if clf.predict(xx)==1:
152
+
49
- return str(clean_buildingname)
153
+ return str(clean_buildingname)
50
154
 
51
155
 
52
156
 
@@ -54,4 +158,6 @@
54
158
 
55
159
 
56
160
 
161
+
162
+
57
163
  ```