Flask

我要对输入的序列进行

--- 维度扩展 
    x_test_1 = np.expand_dims(x_test[12], axis=0)


--- PCA降维
    pca = PCA(n_components=5,copy=True) 
    newX = pca.fit_transform(x)

报错提示:在post给的内容没有在excle中找到

是程序逻辑的问题,需要在看下flask

src文件夹内的文件结构如下:

├── App.vue
├── assets
│ └── logo.png
├── components
│ └── HelloWorld.vue
├── main.js
├── router.js
└── views
├── About.vue
└── Home.vue
详解:

main.js app入口点,它与根组件一起加载和初始化Vue。
app.vue 根组件,它是开始渲染所有其他组件时的起点。
‘components’ 存储UI组件
router.js 定义URL并将URL映射到对应的组件
‘views’ 存储绑定到路由器的UI组件
‘asset’ 存储静态资源,如图像和字体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import Flask, jsonify
from flask_cors import CORS
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.decomposition import PCA
import numpy as np

# configuration
DEBUG = True

# instantiate the app
app = Flask(__name__)
app.config.from_object(__name__)

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})


# sanity check route
@app.route('/ping', methods=['GET'])
def ping_pong():
return jsonify('pong!,hhh')

def Bayes():
df = pd.read_excel('./Data.xls')
df_T=df.T
x=df_T.iloc[:,0:1764]
y1 = df_T.iloc[0:26,1764:1765] #1 类的类别
y2 = df_T.iloc[26:59,1764:1765] #2 类的类别
pca = PCA(n_components=5,copy=True)
newX = pca.fit_transform(x)
# 拆分
newX1 = newX[0:26,:]
newX2 = newX[26:59,:]
x_train1,x_test1,y_train1,y_test1 = train_test_split(newX1,y1,test_size=0.2,random_state=5)
x_train2,x_test2,y_train2,y_test2 = train_test_split(newX2,y2,test_size=0.2,random_state=5)
x_train = np.vstack((x_train1 , x_train2))
x_test = np.vstack((x_test1 , x_test2))
y_train = np.vstack((y_train1 , y_train2))
y_test = np.vstack((y_test1 , y_test2))
print(x_test[1])
gnb = GaussianNB()
gnb = gnb.fit(x_train,y_train)
return gnb

def pretreatment(list1):
array = np.array(list1)
return np.expand_dims(array, axis=0)

@app.route('/predict', methods=['GET'])
def main():
gnb = Bayes()
predict = gnb.predict(pretreatment([2187.82169246, 153.58047602, -124.83874381, -339.65293843, -5.28906774]))
value = int(predict[0])
return jsonify(value)

if __name__ == '__main__':
app.run()