【发布时间】:2020-12-11 06:38:10
【问题描述】:
我正在尝试对每个可能的类别进行概率预测。 该模型是使用 Azure autoML 制作的,我不知道类的索引是什么。我知道我可以从具有不同数据的多次运行中获得这些信息,这些数据可以预测不同的类别,但我希望它每次都返回。
def init():
global model
# This name is model.id of model that we want to deploy deserialize the model file back
# into a sklearn model
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'model.pkl')
path = os.path.normpath(model_path)
path_split = path.split(os.sep)
log_server.update_custom_dimensions({'model_name': path_split[1], 'model_version': path_split[2]})
try:
logger.info("Loading model from path.")
model = joblib.load(model_path)
logger.info("Loading successful.")
except Exception as e:
logging_utilities.log_traceback(e, logger)
raise
@input_schema('data', PandasParameterType(input_sample))
@output_schema(NumpyParameterType(output_sample))
def run(data):
try:
resultclass = model.predict(data)
resultprob = model.predict_proba(data)
return json.dumps({"classes": model.classes_.tolist(), "probability": resultprob.tolist()})
except Exception as e:
result = str(e)
return json.dumps({"error": result})
使用
result = model.predict(data)
返回诸如“PARTS”之类的类之一
使用
result = model.predict_proba(data)
返回不同类别概率的数组,例如 [[0.2001282610210249, 0.0636559071698174, 0.03661803212989511, 0.4096565578555216, 0.28667445877888889, 0.025476]]]788889, 0.025476]]7888889, 0.025476]
遵循我使用的其他建议
model.classes_.tolist()
我认为这会给我类列表,但我得到 [0, 1, 2, 3, 4, 5]
有没有办法从模型中获取所有类?
【问题讨论】:
-
这是什么型号?我尝试使用
RandomForestClassifier并返回类标签而不是索引。 -
Azure 列表
MaxAbsScaler, LogisticRegression
标签: python machine-learning scikit-learn azure-machine-learning-studio