我有多个使用joblib导入的sklearn模型。他们可以完美地独立工作。我现在正在尝试围绕它创建一个Dash应用,以便非编码器可以传递输入并获取4个预测值。
这是我的代码:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import numpy as np
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets = external_stylesheets)
def label_input(ls, tag = 'sample'):
ls.append(html.Label(tag))
ls.append(dcc.Input(value = 0, type = 'number', id = tag))
inputs_list = []
features_list = *list of 25 features*
for i in features_list:
label_input(inputs_list, i)
inputs_list.append(
html.Table([
html.Tr([html.Td([*Output variable name*]), html.Td(id = *output variable name in lower case)]),
*repeated 3 more times
])
)
app.layout = html.Div(inputs_list)
import joblib
model_1 = joblib.load(*filename*)
*repeated 3 more times*
def output_generator(ls, tag, val):
ls.append(Output(tag, val))
def input_generator(ls, tag, val):
ls.append(Input(tag, val))
input_list = []
for i in features_list:
input_generator(input_list, i, 'value')
targets = *list of 4 outputs*
output_list = []
for i in targets:
output_generator(output_list, i.lower(), 'children')
@app.callback(output_list, input_list)
def predictor(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y):
df = pd.DataFrame(dict(zip(features_list, [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y])),
index = [0])
return model1.predict(df), *repeated 3 times*
if __name__ == '__main__':
app.run_server(debug = False)
一切正常,直到我尝试在任何文本框中键入任何内容。我每次都会收到以下错误: 靠后的并行循环不能嵌套在线程下,设置n_jobs = 1
我知道很多,但是我被困住了。任何帮助将不胜感激。