def predict_results(): user_id = g.user['id'] is_default_model = request.form.get("is_default_model") if int(is_default_model): r = UserData.get_model(0) else: r = UserData.get_model(user_id) features = r['features'].split(',') selected_file = request.form["available_files"] df_path = USER_PATH / str(user_id) / selected_file df = PreProcess.getDF(df_path) is_norm = request.form.get("is_norm") is_map = request.form.get("is_map") if is_map == "true": annotation_file = request.form["anno_tbl"] annotation_table_path = UPLOAD_FOLDER.as_posix() + annotation_file df = PreProcess.mergeDF(df_path, Path(annotation_table_path)) df = df.dropna(axis=0, subset=['Gene Symbol']) df = PreProcess.probe2Symbol(df) df = PreProcess.step3(df, 'sklearn', 'drop') df = df.set_index(['Gene Symbol']) df = df.T elif is_norm == "true": df = get_norm_df(df) model_name = r['model_path_name'] e = ValidateUser.has_col(df.columns, features) if e is not None: return render_template("error.html", errors=e) result = get_predicted_result_df(user_id, model_name, df[features], is_default_model) result = result.astype(str) result[result == '0'] = 'Negative' result[result == '1'] = 'Positive' frame = {'ID': df.index, 'Predicted Result': result} out_result = pd.DataFrame(frame) save_path = USER_PATH / str(user_id) / "tmp" / "results.pkl" out_result.to_pickle(save_path) data = out_result['Predicted Result'].value_counts() return render_template( "modeling/predict-results.html", tables=[out_result.to_html(classes='display" id = "table_id')], data=data)
def predict(): user_id = g.user['id'] path = USER_PATH / str(g.user["id"]) list_names = [f for f in os.listdir(path) if os.path.isfile((path / f))] annotation_list = [] annotation_db = UserData.get_annotation_file(g.user["id"]) for f in annotation_db: annotation_list.append([f['file_name'], f['path']]) r = UserData.get_model(user_id) if r['accuracy'] is None: return redirect(url_for('modeling.index') + "?s=2") features = r['features'].split(',') trained_file = r['trained_file'] clasifier = r['clasifier'] accuracy = r['accuracy'] accuracy = str(round(float(accuracy), 2)) details = [features, trained_file, clasifier, accuracy] return render_template("modeling/predict.html", available_list=list_names, details=details, annotation_list=annotation_list)