Giter Site home page Giter Site logo

embed-ml-model-to-web's Introduction

Embed-ML-model-to-Web

forthebadge forthebadge forthebadge

This is a simple web based ML mode

Aim of the model is to get the weightage of the elements as input for the type glass and predict the type of glass usage



The Model folder contains the ML program in python which is converted to .sav using joblib python module.

That .sav file is used in django to integrate with the website



The djangoMl folder contains the django files which using put it in your django virtual environment and add the path (urls.py)to this folder

The ml folder contains the template of the website in html format (home.html for input) and (result.html for output)

Adjust the setting.py file in django so that you can integrate the template with the django view.py

Similar way you can add your model and adjust the webiste too.

Important python module

joblib

pip3 install joblib

This module will convert the python Ml model to sav file which can be further used in django-website to predict result



Machine Learning model used

random forest (model.py)

import numpy as np
import pandas as pd
import joblib

dataset = pd.read_csv('glass.csv')

x = dataset.iloc[:,:-1]
y = dataset.iloc[:,9]

from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.20,random_state = 42)

from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
x_train = sc_x.fit_transform(x_train)
x_test = sc_x.transform(x_test)

from sklearn.ensemble import RandomForestClassifier

clss = RandomForestClassifier(criterion='entropy',n_estimators=300,random_state=42)
clss.fit(x_train,y_train)

print('accuracy is ', clss.score(x_test,y_test)*100,'%')

#saving the model
filename = 'finalized_model.sav'
joblib.dump(clss,filename)

Code Snippet used in django views

view.py

from django.shortcuts import render
import joblib
# Create your views here.
def home_view(request):
    return render(request,"ml/home.html")

def result_view(request):
    clss = joblib.load('model/finalized_model.sav')
    lis = []
    lis.append(request.GET['RI'])
    lis.append(request.GET['Na'])
    lis.append(request.GET['Mg'])
    lis.append(request.GET['Al'])
    lis.append(request.GET['Si'])
    lis.append(request.GET['K'])
    lis.append(request.GET['Ca'])
    lis.append(request.GET['Ba'])
    lis.append(request.GET['Fe'])
    
    ans = clss.predict([lis])
    
    usage = [
        'building windows float processed',
        'building windows non float processed',
        'vehicle windows  float processed',
        'vehicle windows float processed (none in this dataset)',
        'containers',
        'tableware',
        'headlamps'
    ]
    
    return render(request,"ml/result.html",{'ans':usage[ans[0] - 1]})

Screenshot

Input page

Result page

embed-ml-model-to-web's People

Contributors

geek-ninja avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.