def model_train(model_id, features, target): result = {} model_path = os.path.join(config.model_dir, model_id + '.joblib') model = ml_models.load_model(model_path) #x_train, x_test, y_train, y_test = train_test_split(features, target) x_train, y_train = features, target x_test, y_test = features, target model.fit(x_train, y_train) y_pred = model.predict(x_test) result["mean_squared_error"] = metrics.mean_squared_error(y_test, y_pred) result["mean_absolute_error"] = metrics.mean_absolute_error(y_test, y_pred) try: train_loss = model.named_steps['model'].lpath['train'] val_loss = model.named_steps['model'].lpath['val'] except Exception: train_loss = [] val_loss = [] result["train_loss"] = train_loss result["val_loss"] = val_loss ml_models.save_model(model, model_path) return result
def model_train(model_id, features, target): result = {} model_path = os.path.join(config.model_dir, model_id + '.joblib') model = ml_models.load_model(model_path) #x_train, x_test, y_train, y_test = train_test_split(features, target) x_train, y_train = features, target x_test, y_test = features, target model.fit(x_train, y_train) y_pred = model.predict(x_test) result["mean_squared_error"] = metrics.mean_squared_error(y_test, y_pred) result["mean_absolute_error"] = metrics.mean_absolute_error(y_test, y_pred) ml_models.save_model(model, model_path) return result
def model_train(model_id, features, target, **kwags): result = {} model_path = os.path.join(config.model_dir, model_id+'.joblib') model = ml_models.load_model(model_path) x_train = features y_train = target model.fit(x_train, y_train, **kwags) y_pred = model.predict(x_train) cm = metrics.confusion_matrix(y_train, y_pred) true_pred = 0 total = 0 for i in range (len(cm)): true_pred += cm[i][i] total += sum(cm[i]) result["accuracy"] = round(true_pred / total, 4) ml_models.save_model(model, model_path) return result
def model_predict(model_id, features): model_path = os.path.join(config.model_dir, model_id + '.joblib') model = ml_models.load_model(model_path) target = model.predict(features) return target.tolist()
def model_load(model_id): model_path = os.path.join(config.model_dir, model_id + '.joblib') return ml_models.load_model(model_path)