|
@@ -0,0 +1,31 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""
|
|
|
+Created on 2023-12-07
|
|
|
+---------
|
|
|
+@summary: 预测,成绩最好的是决策树模式
|
|
|
+---------
|
|
|
+@author: 李俊亮
|
|
|
+"""
|
|
|
+import pickle
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+from jieba.posseg import cut
|
|
|
+
|
|
|
+
|
|
|
+_base_path = Path(__file__).parent
|
|
|
+_stop_flags = ["x", "w", "v", "u", "c", "uj", "ul", "m", "f", "r"]
|
|
|
+_vectorizer = pickle.load(open(f'{_base_path}/libs/vectorizer.pkl', 'rb'))
|
|
|
+_model = pickle.load(open(f'{_base_path}/libs/model.pkl', 'rb'))
|
|
|
+
|
|
|
+
|
|
|
+def predict(corups: list):
|
|
|
+ """
|
|
|
+ 预测
|
|
|
+
|
|
|
+ :param corups:
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ corpus = [' '.join([w for w, f in cut(l) if f not in _stop_flags]) for l in corups]
|
|
|
+ X = _vectorizer.transform(corpus)
|
|
|
+ predict_result = _model.predict(X)
|
|
|
+ return list(predict_result)
|