def naiv_pred(): flag = int(request.args.get('flag')) li = [] te = pd.read_csv("test.csv") if (flag): li.append(request.args.get('customerID')) li.append(request.args.get('Gender')) li.append(request.args.get('SeniorCitizen')) li.append(request.args.get('Partner')) li.append(request.args.get('Dependents')) li.append(request.args.get('tenure')) li.append(request.args.get('PhoneService')) li.append(request.args.get('MultipleLines')) li.append(request.args.get('InternetService')) li.append(request.args.get('OnlineSecurity')) li.append(request.args.get('OnlineBackup')) li.append(request.args.get('DeviceProtection')) li.append(request.args.get('TechSupport')) li.append(request.args.get('StreamingTV')) li.append(request.args.get('StreamingMovies')) li.append(request.args.get('Contract')) li.append(request.args.get('PaperlessBilling')) li.append(request.args.get('BaymentMrthod')) li.append(request.args.get('MonthlyCharges')) li.append(request.args.get('TotalCharges')) dic = {} c = 0 for i in X.columns: dic[i] = [li[c]] c += 1 te = pd.DataFrame(data=dic) te_c = prep.cleaning(te.copy())["data"] te["Churn"] = df["d"]["Churn"].inverse_transform(clf_naiv.get_pred(te_c)) data = {"pred": te.head(500).to_json()} return jsonify(data)
def prp(): df = prep.cleaning(pd.read_csv("dataset.csv"))["data"] data = {"data": df.head(500).to_json()} return jsonify(data)
import py_files.prep as prep import py_files.LR as LR import py_files.LOGR as LOGR import py_files.RF as RF import py_files.KNN as KNN import py_files.SVM as SVM import py_files.Dtree as Dtree import py_files.naiv as naiv import pandas as pd import json from flask import Flask, jsonify, request, render_template from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA df = prep.cleaning(pd.read_csv("dataset.csv")) #load the dataset lda = LDA(n_components=8) #select 8 feature X = df["data"].drop("Churn", axis=1) Y = df["data"]["Churn"] lda.fit(X, Y) #fit the data to select the best feature clf_log = LOGR.LR(df["data"].copy(), "Churn", lda) #intiate object from logisticRegression Class clf_KNN = KNN.KNN(df["data"].copy(), "Churn", lda) #intiate object from K-NN Class clf_RF = RF.RF(df["data"].copy(), "Churn", lda) #intiate object from RandomForest Class clf_SVM = SVM.SV(df["data"].copy(), "Churn", lda) #intiate object from SVM Class clf_Dt = Dtree.DT(df["data"].copy(), "Churn", lda) #intiate object from Decision Tree Class clf_naiv = naiv.RF(df["data"].copy(), "Churn",