How can I integrate a machine learning algorithm in py file into django website?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm working with random forest algorithm to predict college dropouts with python, the algorithm is finished and now I have to use that file and be able to run it from a website, I'm using django but I don't know how I can make it work, I import the file in views but it only display a line, it doesn't even have an structure like it has when I run the file in jupyter, so if anyone knows something I'll be very thankful.



Sorry if is a little difficult to understand, english is not my first language.



This is the algorithm



 import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
import pandas as pd
from sklearn.feature_selection import SelectKBest

dataset = pd.read_csv('C:/Users/danni/OneDrive/Documents/Universidad/2018/Tesis/encuestas/Nueva carpeta/Nueva carpeta/SinRanking/2005_2017_SOLO_PRIMERO_Y_SEGUNDO.csv', delimiter=";")


datos2 = dataset['F_Nac']
i = 0
a =
while i < len(datos2):
value2 = datos2[i]
first = value2[6:10]

year = first
a_ingreso = dataset['A_Ingreso']
a.append(a_ingreso[i] - int(year))
i += 1
dataset['edad_ingreso']=a;



#calculamos la edad de ingreso a la universidad
def calcula_dif_years_eg_in(anio,cuando):
return anio - cuando

dataset['a_egresado_colegio']=dataset.apply(lambda x: calcula_dif_years_eg_in(x['A_Ingreso'],x['A_Egreso_Colegio']), axis=1);


dataset = dataset.drop(["F_Nac","A_Ingreso","A_Egreso_Colegio","Via_Ingreso"], axis=1)


# cargamos las variables predictoras
predictors = dataset.drop(['Deserto'], axis=1)
# y estos son los resultados que se obtienen, en el mismo orden
targets = dataset['Deserto']


best=SelectKBest(k=10)
X_new = best.fit_transform(predictors, targets)
X_new.shape
selected = best.get_support(indices=True)
print(predictors.columns[selected])



#datos desde el 2005 al 2015
X_train = predictors[0:567]
X_test = predictors[568:632]
#datos del 2016
y_train = targets[0:567]
y_test = targets[568:632]



modelo = RandomForestClassifier(
random_state = 1, # semilla inicial de aleatoriedad del algoritmo
n_estimators = 5, # cantidad de arboles a crear
min_samples_split = 0.5, # cantidad minima de observaciones para dividir un nodo
min_samples_leaf = 8, # observaciones minimas que puede tener una hoja del arbol
n_jobs = -1 # tareas en paralelo. para todos los cores disponibles usar -1
)
modelo.fit(X_train[predictors.columns[selected]].values, y_train)


prediccion = modelo.predict(X_test[predictors.columns[selected]].values)

modelo.score(X_train[predictors.columns[selected]], y_train)


modelo.score(X_test[predictors.columns[selected]], y_test)



print(metrics.classification_report(y_true=y_test, y_pred=prediccion))
print(pd.crosstab(y_test, prediccion, rownames=['REAL'], colnames=['PREDICCION']))


var_imp = pd.DataFrame({
'feature':predictors.columns[selected],
'v_importance':modelo.feature_importances_.tolist()
})
print (var_imp.sort_values(by = 'v_importance', ascending=False))




#Curvas de aprendizaje
from sklearn.learning_curve import learning_curve

train_sizes, train_scores, test_scores = learning_curve(estimator=modelo,
X=X_train, y=y_train,
train_sizes=np.linspace(0.1, 1.0, 10), cv=10,
n_jobs=-1)

train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)
test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)


import matplotlib.pyplot as plt
import seaborn as sns
get_ipython().run_line_magic('matplotlib', 'inline')
sns.set_palette("deep",desat=.6)
sns.set_context(rc={"figure.figsize":(8,4)})

# graficando las curvas
plt.plot(train_sizes, train_mean, color='r', marker='o', markersize=5,
label='entrenamiento')
plt.fill_between(train_sizes, train_mean + train_std,
train_mean - train_std, alpha=0.15, color='r')
plt.plot(train_sizes, test_mean, color='b', linestyle='--',
marker='s', markersize=5, label='evaluacion')
plt.fill_between(train_sizes, test_mean + test_std,
test_mean - test_std, alpha=0.15, color='b')
plt.grid()
plt.title('Curva de aprendizaje')
plt.legend(loc='upper right')
plt.xlabel('Cant de ejemplos de entrenamiento')
plt.ylabel('Precision')
plt.show()



i = 0
a =
while i < len(X_test):
a.append(modelo.predict(X_test[predictors.columns[selected]])[i])
i += 1


print(a)


X_test['x']=a

X_test
print(X_test.groupby('x').size())









share|improve this question





























    0















    I'm working with random forest algorithm to predict college dropouts with python, the algorithm is finished and now I have to use that file and be able to run it from a website, I'm using django but I don't know how I can make it work, I import the file in views but it only display a line, it doesn't even have an structure like it has when I run the file in jupyter, so if anyone knows something I'll be very thankful.



    Sorry if is a little difficult to understand, english is not my first language.



    This is the algorithm



     import numpy as np
    from sklearn.ensemble import RandomForestClassifier
    from sklearn import metrics
    import pandas as pd
    from sklearn.feature_selection import SelectKBest

    dataset = pd.read_csv('C:/Users/danni/OneDrive/Documents/Universidad/2018/Tesis/encuestas/Nueva carpeta/Nueva carpeta/SinRanking/2005_2017_SOLO_PRIMERO_Y_SEGUNDO.csv', delimiter=";")


    datos2 = dataset['F_Nac']
    i = 0
    a =
    while i < len(datos2):
    value2 = datos2[i]
    first = value2[6:10]

    year = first
    a_ingreso = dataset['A_Ingreso']
    a.append(a_ingreso[i] - int(year))
    i += 1
    dataset['edad_ingreso']=a;



    #calculamos la edad de ingreso a la universidad
    def calcula_dif_years_eg_in(anio,cuando):
    return anio - cuando

    dataset['a_egresado_colegio']=dataset.apply(lambda x: calcula_dif_years_eg_in(x['A_Ingreso'],x['A_Egreso_Colegio']), axis=1);


    dataset = dataset.drop(["F_Nac","A_Ingreso","A_Egreso_Colegio","Via_Ingreso"], axis=1)


    # cargamos las variables predictoras
    predictors = dataset.drop(['Deserto'], axis=1)
    # y estos son los resultados que se obtienen, en el mismo orden
    targets = dataset['Deserto']


    best=SelectKBest(k=10)
    X_new = best.fit_transform(predictors, targets)
    X_new.shape
    selected = best.get_support(indices=True)
    print(predictors.columns[selected])



    #datos desde el 2005 al 2015
    X_train = predictors[0:567]
    X_test = predictors[568:632]
    #datos del 2016
    y_train = targets[0:567]
    y_test = targets[568:632]



    modelo = RandomForestClassifier(
    random_state = 1, # semilla inicial de aleatoriedad del algoritmo
    n_estimators = 5, # cantidad de arboles a crear
    min_samples_split = 0.5, # cantidad minima de observaciones para dividir un nodo
    min_samples_leaf = 8, # observaciones minimas que puede tener una hoja del arbol
    n_jobs = -1 # tareas en paralelo. para todos los cores disponibles usar -1
    )
    modelo.fit(X_train[predictors.columns[selected]].values, y_train)


    prediccion = modelo.predict(X_test[predictors.columns[selected]].values)

    modelo.score(X_train[predictors.columns[selected]], y_train)


    modelo.score(X_test[predictors.columns[selected]], y_test)



    print(metrics.classification_report(y_true=y_test, y_pred=prediccion))
    print(pd.crosstab(y_test, prediccion, rownames=['REAL'], colnames=['PREDICCION']))


    var_imp = pd.DataFrame({
    'feature':predictors.columns[selected],
    'v_importance':modelo.feature_importances_.tolist()
    })
    print (var_imp.sort_values(by = 'v_importance', ascending=False))




    #Curvas de aprendizaje
    from sklearn.learning_curve import learning_curve

    train_sizes, train_scores, test_scores = learning_curve(estimator=modelo,
    X=X_train, y=y_train,
    train_sizes=np.linspace(0.1, 1.0, 10), cv=10,
    n_jobs=-1)

    train_mean = np.mean(train_scores, axis=1)
    train_std = np.std(train_scores, axis=1)
    test_mean = np.mean(test_scores, axis=1)
    test_std = np.std(test_scores, axis=1)


    import matplotlib.pyplot as plt
    import seaborn as sns
    get_ipython().run_line_magic('matplotlib', 'inline')
    sns.set_palette("deep",desat=.6)
    sns.set_context(rc={"figure.figsize":(8,4)})

    # graficando las curvas
    plt.plot(train_sizes, train_mean, color='r', marker='o', markersize=5,
    label='entrenamiento')
    plt.fill_between(train_sizes, train_mean + train_std,
    train_mean - train_std, alpha=0.15, color='r')
    plt.plot(train_sizes, test_mean, color='b', linestyle='--',
    marker='s', markersize=5, label='evaluacion')
    plt.fill_between(train_sizes, test_mean + test_std,
    test_mean - test_std, alpha=0.15, color='b')
    plt.grid()
    plt.title('Curva de aprendizaje')
    plt.legend(loc='upper right')
    plt.xlabel('Cant de ejemplos de entrenamiento')
    plt.ylabel('Precision')
    plt.show()



    i = 0
    a =
    while i < len(X_test):
    a.append(modelo.predict(X_test[predictors.columns[selected]])[i])
    i += 1


    print(a)


    X_test['x']=a

    X_test
    print(X_test.groupby('x').size())









    share|improve this question

























      0












      0








      0








      I'm working with random forest algorithm to predict college dropouts with python, the algorithm is finished and now I have to use that file and be able to run it from a website, I'm using django but I don't know how I can make it work, I import the file in views but it only display a line, it doesn't even have an structure like it has when I run the file in jupyter, so if anyone knows something I'll be very thankful.



      Sorry if is a little difficult to understand, english is not my first language.



      This is the algorithm



       import numpy as np
      from sklearn.ensemble import RandomForestClassifier
      from sklearn import metrics
      import pandas as pd
      from sklearn.feature_selection import SelectKBest

      dataset = pd.read_csv('C:/Users/danni/OneDrive/Documents/Universidad/2018/Tesis/encuestas/Nueva carpeta/Nueva carpeta/SinRanking/2005_2017_SOLO_PRIMERO_Y_SEGUNDO.csv', delimiter=";")


      datos2 = dataset['F_Nac']
      i = 0
      a =
      while i < len(datos2):
      value2 = datos2[i]
      first = value2[6:10]

      year = first
      a_ingreso = dataset['A_Ingreso']
      a.append(a_ingreso[i] - int(year))
      i += 1
      dataset['edad_ingreso']=a;



      #calculamos la edad de ingreso a la universidad
      def calcula_dif_years_eg_in(anio,cuando):
      return anio - cuando

      dataset['a_egresado_colegio']=dataset.apply(lambda x: calcula_dif_years_eg_in(x['A_Ingreso'],x['A_Egreso_Colegio']), axis=1);


      dataset = dataset.drop(["F_Nac","A_Ingreso","A_Egreso_Colegio","Via_Ingreso"], axis=1)


      # cargamos las variables predictoras
      predictors = dataset.drop(['Deserto'], axis=1)
      # y estos son los resultados que se obtienen, en el mismo orden
      targets = dataset['Deserto']


      best=SelectKBest(k=10)
      X_new = best.fit_transform(predictors, targets)
      X_new.shape
      selected = best.get_support(indices=True)
      print(predictors.columns[selected])



      #datos desde el 2005 al 2015
      X_train = predictors[0:567]
      X_test = predictors[568:632]
      #datos del 2016
      y_train = targets[0:567]
      y_test = targets[568:632]



      modelo = RandomForestClassifier(
      random_state = 1, # semilla inicial de aleatoriedad del algoritmo
      n_estimators = 5, # cantidad de arboles a crear
      min_samples_split = 0.5, # cantidad minima de observaciones para dividir un nodo
      min_samples_leaf = 8, # observaciones minimas que puede tener una hoja del arbol
      n_jobs = -1 # tareas en paralelo. para todos los cores disponibles usar -1
      )
      modelo.fit(X_train[predictors.columns[selected]].values, y_train)


      prediccion = modelo.predict(X_test[predictors.columns[selected]].values)

      modelo.score(X_train[predictors.columns[selected]], y_train)


      modelo.score(X_test[predictors.columns[selected]], y_test)



      print(metrics.classification_report(y_true=y_test, y_pred=prediccion))
      print(pd.crosstab(y_test, prediccion, rownames=['REAL'], colnames=['PREDICCION']))


      var_imp = pd.DataFrame({
      'feature':predictors.columns[selected],
      'v_importance':modelo.feature_importances_.tolist()
      })
      print (var_imp.sort_values(by = 'v_importance', ascending=False))




      #Curvas de aprendizaje
      from sklearn.learning_curve import learning_curve

      train_sizes, train_scores, test_scores = learning_curve(estimator=modelo,
      X=X_train, y=y_train,
      train_sizes=np.linspace(0.1, 1.0, 10), cv=10,
      n_jobs=-1)

      train_mean = np.mean(train_scores, axis=1)
      train_std = np.std(train_scores, axis=1)
      test_mean = np.mean(test_scores, axis=1)
      test_std = np.std(test_scores, axis=1)


      import matplotlib.pyplot as plt
      import seaborn as sns
      get_ipython().run_line_magic('matplotlib', 'inline')
      sns.set_palette("deep",desat=.6)
      sns.set_context(rc={"figure.figsize":(8,4)})

      # graficando las curvas
      plt.plot(train_sizes, train_mean, color='r', marker='o', markersize=5,
      label='entrenamiento')
      plt.fill_between(train_sizes, train_mean + train_std,
      train_mean - train_std, alpha=0.15, color='r')
      plt.plot(train_sizes, test_mean, color='b', linestyle='--',
      marker='s', markersize=5, label='evaluacion')
      plt.fill_between(train_sizes, test_mean + test_std,
      test_mean - test_std, alpha=0.15, color='b')
      plt.grid()
      plt.title('Curva de aprendizaje')
      plt.legend(loc='upper right')
      plt.xlabel('Cant de ejemplos de entrenamiento')
      plt.ylabel('Precision')
      plt.show()



      i = 0
      a =
      while i < len(X_test):
      a.append(modelo.predict(X_test[predictors.columns[selected]])[i])
      i += 1


      print(a)


      X_test['x']=a

      X_test
      print(X_test.groupby('x').size())









      share|improve this question














      I'm working with random forest algorithm to predict college dropouts with python, the algorithm is finished and now I have to use that file and be able to run it from a website, I'm using django but I don't know how I can make it work, I import the file in views but it only display a line, it doesn't even have an structure like it has when I run the file in jupyter, so if anyone knows something I'll be very thankful.



      Sorry if is a little difficult to understand, english is not my first language.



      This is the algorithm



       import numpy as np
      from sklearn.ensemble import RandomForestClassifier
      from sklearn import metrics
      import pandas as pd
      from sklearn.feature_selection import SelectKBest

      dataset = pd.read_csv('C:/Users/danni/OneDrive/Documents/Universidad/2018/Tesis/encuestas/Nueva carpeta/Nueva carpeta/SinRanking/2005_2017_SOLO_PRIMERO_Y_SEGUNDO.csv', delimiter=";")


      datos2 = dataset['F_Nac']
      i = 0
      a =
      while i < len(datos2):
      value2 = datos2[i]
      first = value2[6:10]

      year = first
      a_ingreso = dataset['A_Ingreso']
      a.append(a_ingreso[i] - int(year))
      i += 1
      dataset['edad_ingreso']=a;



      #calculamos la edad de ingreso a la universidad
      def calcula_dif_years_eg_in(anio,cuando):
      return anio - cuando

      dataset['a_egresado_colegio']=dataset.apply(lambda x: calcula_dif_years_eg_in(x['A_Ingreso'],x['A_Egreso_Colegio']), axis=1);


      dataset = dataset.drop(["F_Nac","A_Ingreso","A_Egreso_Colegio","Via_Ingreso"], axis=1)


      # cargamos las variables predictoras
      predictors = dataset.drop(['Deserto'], axis=1)
      # y estos son los resultados que se obtienen, en el mismo orden
      targets = dataset['Deserto']


      best=SelectKBest(k=10)
      X_new = best.fit_transform(predictors, targets)
      X_new.shape
      selected = best.get_support(indices=True)
      print(predictors.columns[selected])



      #datos desde el 2005 al 2015
      X_train = predictors[0:567]
      X_test = predictors[568:632]
      #datos del 2016
      y_train = targets[0:567]
      y_test = targets[568:632]



      modelo = RandomForestClassifier(
      random_state = 1, # semilla inicial de aleatoriedad del algoritmo
      n_estimators = 5, # cantidad de arboles a crear
      min_samples_split = 0.5, # cantidad minima de observaciones para dividir un nodo
      min_samples_leaf = 8, # observaciones minimas que puede tener una hoja del arbol
      n_jobs = -1 # tareas en paralelo. para todos los cores disponibles usar -1
      )
      modelo.fit(X_train[predictors.columns[selected]].values, y_train)


      prediccion = modelo.predict(X_test[predictors.columns[selected]].values)

      modelo.score(X_train[predictors.columns[selected]], y_train)


      modelo.score(X_test[predictors.columns[selected]], y_test)



      print(metrics.classification_report(y_true=y_test, y_pred=prediccion))
      print(pd.crosstab(y_test, prediccion, rownames=['REAL'], colnames=['PREDICCION']))


      var_imp = pd.DataFrame({
      'feature':predictors.columns[selected],
      'v_importance':modelo.feature_importances_.tolist()
      })
      print (var_imp.sort_values(by = 'v_importance', ascending=False))




      #Curvas de aprendizaje
      from sklearn.learning_curve import learning_curve

      train_sizes, train_scores, test_scores = learning_curve(estimator=modelo,
      X=X_train, y=y_train,
      train_sizes=np.linspace(0.1, 1.0, 10), cv=10,
      n_jobs=-1)

      train_mean = np.mean(train_scores, axis=1)
      train_std = np.std(train_scores, axis=1)
      test_mean = np.mean(test_scores, axis=1)
      test_std = np.std(test_scores, axis=1)


      import matplotlib.pyplot as plt
      import seaborn as sns
      get_ipython().run_line_magic('matplotlib', 'inline')
      sns.set_palette("deep",desat=.6)
      sns.set_context(rc={"figure.figsize":(8,4)})

      # graficando las curvas
      plt.plot(train_sizes, train_mean, color='r', marker='o', markersize=5,
      label='entrenamiento')
      plt.fill_between(train_sizes, train_mean + train_std,
      train_mean - train_std, alpha=0.15, color='r')
      plt.plot(train_sizes, test_mean, color='b', linestyle='--',
      marker='s', markersize=5, label='evaluacion')
      plt.fill_between(train_sizes, test_mean + test_std,
      test_mean - test_std, alpha=0.15, color='b')
      plt.grid()
      plt.title('Curva de aprendizaje')
      plt.legend(loc='upper right')
      plt.xlabel('Cant de ejemplos de entrenamiento')
      plt.ylabel('Precision')
      plt.show()



      i = 0
      a =
      while i < len(X_test):
      a.append(modelo.predict(X_test[predictors.columns[selected]])[i])
      i += 1


      print(a)


      X_test['x']=a

      X_test
      print(X_test.groupby('x').size())






      python html django csv machine-learning






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 4:28









      CrusshyCrusshy

      11




      11
























          1 Answer
          1






          active

          oldest

          votes


















          1














          There are a couple of options.




          1. Run it as a separate service, so that more than one application(s) can use it independently. For this you'll need to create an API around your machine learning implementation (which should expose required functionalities like training a model, predicting etc) and deploy/host it separately. This separates concerns for your web application and the actual machine learning so this is my preferred way unless the whole application is small (like a proof of concept).

          2. Keep all the code together including your machine learning part of it and deploy it as a single monolithic application. You'll need some persistent binary (eg. file) storage to store trained models (eg Google cloud storage), from where more than one applications (with their own ML programs, which may differ, maintaining compatibility with your trained model though, if they want to share it). If all you care about is getting something in a working condition first (such as a proof of concept), this should be simpler and faster.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423905%2fhow-can-i-integrate-a-machine-learning-algorithm-in-py-file-into-django-website%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            There are a couple of options.




            1. Run it as a separate service, so that more than one application(s) can use it independently. For this you'll need to create an API around your machine learning implementation (which should expose required functionalities like training a model, predicting etc) and deploy/host it separately. This separates concerns for your web application and the actual machine learning so this is my preferred way unless the whole application is small (like a proof of concept).

            2. Keep all the code together including your machine learning part of it and deploy it as a single monolithic application. You'll need some persistent binary (eg. file) storage to store trained models (eg Google cloud storage), from where more than one applications (with their own ML programs, which may differ, maintaining compatibility with your trained model though, if they want to share it). If all you care about is getting something in a working condition first (such as a proof of concept), this should be simpler and faster.






            share|improve this answer




























              1














              There are a couple of options.




              1. Run it as a separate service, so that more than one application(s) can use it independently. For this you'll need to create an API around your machine learning implementation (which should expose required functionalities like training a model, predicting etc) and deploy/host it separately. This separates concerns for your web application and the actual machine learning so this is my preferred way unless the whole application is small (like a proof of concept).

              2. Keep all the code together including your machine learning part of it and deploy it as a single monolithic application. You'll need some persistent binary (eg. file) storage to store trained models (eg Google cloud storage), from where more than one applications (with their own ML programs, which may differ, maintaining compatibility with your trained model though, if they want to share it). If all you care about is getting something in a working condition first (such as a proof of concept), this should be simpler and faster.






              share|improve this answer


























                1












                1








                1







                There are a couple of options.




                1. Run it as a separate service, so that more than one application(s) can use it independently. For this you'll need to create an API around your machine learning implementation (which should expose required functionalities like training a model, predicting etc) and deploy/host it separately. This separates concerns for your web application and the actual machine learning so this is my preferred way unless the whole application is small (like a proof of concept).

                2. Keep all the code together including your machine learning part of it and deploy it as a single monolithic application. You'll need some persistent binary (eg. file) storage to store trained models (eg Google cloud storage), from where more than one applications (with their own ML programs, which may differ, maintaining compatibility with your trained model though, if they want to share it). If all you care about is getting something in a working condition first (such as a proof of concept), this should be simpler and faster.






                share|improve this answer













                There are a couple of options.




                1. Run it as a separate service, so that more than one application(s) can use it independently. For this you'll need to create an API around your machine learning implementation (which should expose required functionalities like training a model, predicting etc) and deploy/host it separately. This separates concerns for your web application and the actual machine learning so this is my preferred way unless the whole application is small (like a proof of concept).

                2. Keep all the code together including your machine learning part of it and deploy it as a single monolithic application. You'll need some persistent binary (eg. file) storage to store trained models (eg Google cloud storage), from where more than one applications (with their own ML programs, which may differ, maintaining compatibility with your trained model though, if they want to share it). If all you care about is getting something in a working condition first (such as a proof of concept), this should be simpler and faster.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 2 '18 at 5:33









                0xc0de0xc0de

                4,80023666




                4,80023666
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423905%2fhow-can-i-integrate-a-machine-learning-algorithm-in-py-file-into-django-website%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    鏡平學校

                    ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                    Why https connections are so slow when debugging (stepping over) in Java?