def mlregressionop(action): try: if action == "create": method = request.args['type'] model = createModel("Regression", method) return jsonify(result="Success", model=model.getId()) elif action == "train": modelId = request.args['id'] dataName = request.args['data'] label = request.args['target'] features = request.args['train'].split(",") model = getModel(modelId) datadf = datautil.load(dataName) labelData = datautil.getColValues(datadf, label) featureData = datautil.getColsValues(datadf, features) data = dict() data["train"] = featureData data["target"] = labelData model.train(data) predit_data = model.predict(data['train']) true_data = data['target'] rmse = np.sqrt(np.mean((predit_data - true_data)**2)) return jsonify(result="Success", model=modelId, rmse=rmse) elif action == "predict": modelId = request.args['id'] data = json.loads(request.args['data']) model = getModel(modelId) return jsonify(result="Success", predict=str(model.predict(data))) elif action == "predictViz": modelId = request.args['id'] scale = request.args['scale'] model = getModel(modelId) return jsonify(result="Success", predict=str(model.predictViz(int(scale)))) else: return jsonify(result="Failed", msg="Do not support this action {}".format(action)) except: traceback.print_exc() return jsonify(result="Failed", msg="Some Exception")
def mlaaop(action): try: if action == "create": method = request.args['type'] model = createModel("association_analysis", method) return jsonify(result="Success", model=model.getId()) elif action == "train": modelId = request.args['id'] dataName = request.args['data'] label = request.args['label'] features = request.args['features'].split(",") model = getModel(modelId) datadf = datautil.load(dataName) labelData = datautil.getColValues(datadf, label) featureData = datautil.getColsValues(datadf, features) data = dict() data["train"] = featureData data["target"] = labelData model.train(data) return jsonify(result="Success", model=modelId) elif action == "predict": ''' modelId = request.args['id'] data = json.loads(request.args['data']) model = getModel(modelId) return jsonify(result="Success", predict=str(model.predict(data))) ''' print "pass" pass elif action == "predictViz": modelId = request.args['id'] scale = request.args['scale'] model = getModel(modelId) return jsonify(result="Success", predict=str(model.predictViz(int(scale)))) else: return jsonify(result="Failed", msg="Do not support this action {}".format(action)) except: traceback.print_exc() return jsonify(result="Failed", msg="Some Exception")
def mlclsop(action): try: if action == "create": method = request.args['type'] model = createModel("Classification", method) return jsonify(result="Success", model=model.getId()) elif action == "train": modelId = request.args['id'] dataName = request.args['data'] label = request.args['label'] features = request.args['features'].split(",") model = getModel(modelId) datadf = datautil.load(dataName) labelData = datautil.getColValues(datadf, label) featureData = datautil.getColsValues(datadf, features) data = dict() data["features"] = featureData data["label"] = labelData model.train(data) return jsonify(result="Success", model=modelId) elif action == "predict": modelId = request.args['id'] data = json.loads(request.args['data']) model = getModel(modelId) return jsonify(result="Success", predict=str(model.predict(data))) elif action == "predictViz": modelId = request.args['id'] scale = request.args['scale'] model = getModel(modelId) return jsonify(result="Success", predict=str(model.predictViz(int(scale)))) else: return jsonify(result="Failed", msg="Do not support this action {}".format(action)) except: traceback.print_exc() return jsonify(result="Failed", msg="Some Exception")
def mlclsop(action): try: if action == "create": method = request.args['type'] model = createModel("Classification", method) return jsonify(result="Success", model=model.getId()) elif action == "train": ahora = datetime.now().strftime( '%d%m%Y-%H%M%S') # Obtiene fecha y hora actual print("Fecha y Hora:", ahora) # Muestra fecha y hora f = open(ahora + '.txt', 'w') modelId = request.args['id'] dataName = request.args['data'] label = request.args['label'] features = request.args['features'].split(",") model = getModel(modelId) # Guardo la cabecera del archivo, con datos genericos de lo que se eligio en la pantalla f.write('%s : %s \n' % ('Modelo de entrenamiento', str(model))) f.write('%s :%s \n' % ('Dataset seleccionado', str(dataName))) f.write('%s :%s \n' % ('Dato a predecir Y', str(label))) f.write('%s :%s \n' % ('Caracteristicas X', str(features))) datadf = datautil.load(dataName) labelData = datautil.getColValues(datadf, label) featureData = datautil.getColsValues(datadf, features) data = dict() data["features"] = featureData data["label"] = labelData data["data"] = datadf ##model.train(data) ## este es un llamado nuevo que retornaria los resultados de las diferentes metricas que se aplicaron al conjunto de datos}} modelPredic = model.train(data) f.write('\n') for elemento in modelPredic: f.write('%s \n' % elemento) f.close() return jsonify(result="Success", model=modelId, metric=str(modelPredic)) ##return jsonify(result="Success", model=modelId) ## asi estaba el llamado anterior elif action == "predict": modelId = request.args['id'] data = json.loads(request.args['data']) model = getModel(modelId) return jsonify(result="Success", predict=str(model.predict(data))) elif action == "predictViz": modelId = request.args['id'] scale = request.args['scale'] model = getModel(modelId) return jsonify(result="Success", predict=str(model.predictViz(int(scale)))) else: return jsonify(result="Failed", msg="No se soporta esta accion {}".format(action)) except: traceback.print_exc() return jsonify(result="Failed", msg="Some Exception")
def mlregressionop(action): try: if action == "create": method = request.args['type'] model = createModel("Regression", method) return jsonify(result="Success", model=model.getId()) elif action == "train": ahora = datetime.now().strftime( '%d%m%Y-%H%M%S') # Obtiene fecha y hora actual print("Fecha y Hora:", ahora) # Muestra fecha y hora f = open(ahora + '.txt', 'w') modelId = request.args['id'] dataName = request.args['data'] label = request.args['target'] features = request.args['train'].split(",") model = getModel(modelId) # Guardo la cabecera del archivo, con datos genericos de lo que se eligio en la pantalla f.write('%s : %s \n' % ('Modelo de entrenamiento', str(model))) f.write('%s :%s \n' % ('Dataset seleccionado', str(dataName))) f.write('%s :%s \n' % ('Dato a predecir Y', str(label))) f.write('%s :%s \n' % ('Caracteristicas X', str(features))) datadf = datautil.load(dataName) labelData = datautil.getColValues(datadf, label) featureData = datautil.getColsValues(datadf, features) data = dict() data["train"] = featureData data["target"] = labelData data["data"] = datadf ##model.train(data) ## en metric mandar los datos de las predicciones de los algoritmos, hacer el que model.train devuelva los datos concatenados o en un objeto modelPredic = model.train(data) f.write('\n') for elemento in modelPredic: f.write('%s \n' % elemento) f.close() return jsonify(result="Success", model=modelId, metric=str(modelPredic)) elif action == "predict": modelId = request.args['id'] data = json.loads(request.args['data']) model = getModel(modelId) return jsonify(result="Success", predict=str(model.predict(data))) elif action == "predictViz": modelId = request.args['id'] scale = request.args['scale'] model = getModel(modelId) return jsonify(result="Success", predict=str(model.predictViz(int(scale)))) else: return jsonify(result="Failed", msg="No se soporta esta accion{}".format(action)) except: traceback.print_exc() return jsonify(result="Failed", msg="Some Exception")