Code Monkey home page Code Monkey logo

recommendation's Introduction

Recommendation project

How does it work

There are 2 python files and 1 Dockerfile in this project. 
1. train.py
    This is the script for training the SVD model 
        - Step
            1. Load rating data
            2. Preprocessing/Clean data by dropping null data.
            3. Using GridSearchCV for Hyperparameter tuning
            4. Select the best param
            5. Feed rating data to SVD model
            6. Save model
2. app.py
    Flask application for serving REST API.
    There are 2 API
    1. GET /recommendations
    2. GET /features

    For Recommendation, we  are using a Hybrid approach
    for the user that we know what movies they have watched, we will recommend based on the history
    for the user that we don't have any data, we will first serve the list with the most rating movie by calculate_top_rate_movies
3. Dockerfile
    Create Docker image: docker image build -t flask_docker .
    Run docker image: docker run -p 5674:5000 -it -d flask_docker
    Docker hub: https://hub.docker.com/r/rpzzzzzz/flask_recommendation
4. Postman: 
    http://localhost:5674/recommendations?user_id=418&returnMetadata=true
    http://localhost:5674/features?user_id=18

Current accuracy

SVD model
Best RMSE score:  0.8728238441724732
params: {'n_epochs': 20, 'lr_all': 0.005, 'n_factors': 50}

How to feed input and get output

Use ratings.csv
Input: List of rating --> user ID, movie ID and rating ['userId','movieId','rating']
Output: Prediction(uid=1, iid=318, r_ui=3.497929962032474, est=5, details={'was_impossible': False}))

How to improve in the future

SVDPP model
User search history or recent watched movies
Feedback from user after using the model.
A/B testing

API

http://localhost:5674/recommendations?user_id=418&returnMetadata=true
{
    "items": [
        {
            "genres": [
                "Crime",
                "Drama"
            ],
            "id": "858",
            "title": "Godfather, The (1972)"
        },
        {
            "genres": [
                "Crime",
                "Drama"
            ],
            "id": "1221",
            "title": "Godfather: Part II, The (1974)"
        },
        {
            "genres": [
                "Action",
                "Adventure",
                "Sci-Fi"
            ],
            "id": "260",
            "title": "Star Wars: Episode IV - A New Hope (1977)"
        },
        {
            "genres": [
                "Action",
                "Sci-Fi",
                "Thriller"
            ],
            "id": "2571",
            "title": "Matrix, The (1999)"
        },
        {
            "genres": [
                "Action",
                "Adventure",
                "Comedy",
                "Fantasy",
                "Horror"
            ],
            "id": "1215",
            "title": "Army of Darkness (1993)"
        },
        {
            "genres": [
                "Crime",
                "Drama"
            ],
            "id": "1213",
            "title": "Goodfellas (1990)"
        },
        {
            "genres": [
                "Action",
                "Adventure",
                "Drama",
                "War"
            ],
            "id": "1262",
            "title": "Great Escape, The (1963)"
        },
        {
            "genres": [
                "Adventure",
                "Drama",
                "War"
            ],
            "id": "1204",
            "title": "Lawrence of Arabia (1962)"
        },
        {
            "genres": [
                "Crime",
                "Mystery",
                "Thriller"
            ],
            "id": "1089",
            "title": "Reservoir Dogs (1992)"
        },
        {
            "genres": [
                "Comedy",
                "Crime"
            ],
            "id": "2502",
            "title": "Office Space (1999)"
        }
    ]
}
http://localhost:5674/recommendations?user_id=418
{
    "items": [
        {
            "id": "858"
        },
        {
            "id": "1221"
        },
        {
            "id": "260"
        },
        {
            "id": "2571"
        },
        {
            "id": "1215"
        },
        {
            "id": "1213"
        },
        {
            "id": "1262"
        },
        {
            "id": "1204"
        },
        {
            "id": "1089"
        },
        {
            "id": "2502"
        }
    ]
}

http://localhost:5674/features?user_id=18
{
    "features": [
        {
            "histories": [
                "1",
                "2",
                "6",
                "16",
                "32",
                "34",
                "36",
                "47",
                "50",
                "70",
                "104",
                "110",
                "111",
                "145",
                "163",
                "165",
                "180",
                "208",
                "223",
                "231",
                "235",
                "260",
                "288",
                "293",
                "296",
                "318",
                "329",
                "337",
                "344",
                "356",
                "364",
                "367",
                "370",
                "374",
                "377",
                "380",
                "431",
                "435",
                "442",
                "457",
                "466",
                "480",
                "500",
                "502",
                "508",
                "527",
                "541",
                "555",
                "586",
                "588",
                "589",
                "590",
                "593",
                "595",
                "608",
                "628",
                "648",
                "653",
                "673",
                "745",
                "778",
                "780",
                "784",
                "849",
                "858",
                "904",
                "908",
                "913",
                "919",
                "923",
                "924",
                "1020",
                "1036",
                "1059",
                "1080",
                "1086",
                "1089",
                "1095",
                "1136",
                "1148",
                "1193",
                "1196",
                "1198",
                "1201",
                "1203",
                "1206",
                "1207",
                "1208",
                "1209",
                "1210",
                "1212",
                "1213",
                "1214",
                "1219",
                "1221",
                "1222",
                "1223",
                "1227",
                "1234",
                "1240",
                "1245",
                "1246",
                "1247",
                "1252",
                "1260",
                "1270",
                "1275",
                "1276",
                "1291",
                "1356",
                "1370",
                "1371",
                "1374",
                "1375",
                "1391",
                "1466",
                "1517",
                "1527",
                "1544",
                "1580",
                "1608",
                "1617",
                "1625",
                "1653",
                "1676",
                "1682",
                "1704",
                "1721",
                "1729",
                "1732",
                "1784",
                "1805",
                "1892",
                "1917",
                "1918",
                "1924",
                "1954",
                "1961",
                "2000",
                "2001",
                "2002",
                "2011",
                "2012",
                "2019",
                "2028",
                "2058",
                "2115",
                "2184",
                "2194",
                "2268",
                "2278",
                "2291",
                "2324",
                "2329",
                "2409",
                "2410",
                "2411",
                "2412",
                "2420",
                "2421",
                "2422",
                "2470",
                "2490",
                "2542",
                "2571",
                "2683",
                "2692",
                "2706",
                "2762",
                "2918",
                "2951",
                "2953",
                "2959",
                "2997",
                "3052",
                "3081",
                "3147",
                "3253",
                "3257",
                "3275",
                "3462",
                "3578",
                "3681",
                "3702",
                "3751",
                "3785",
                "3793",
                "3896",
                "3949",
                "3994",
                "4007",
                "4011",
                "4226",
                "4239",
                "4262",
                "4306",
                "4327",
                "4383",
                "4643",
                "4728",
                "4816",
                "4886",
                "4896",
                "4963",
                "4973",
                "4993",
                "4995",
                "5008",
                "5120",
                "5218",
                "5266",
                "5349",
                "5418",
                "5445",
                "5459",
                "5464",
                "5481",
                "5574",
                "5608",
                "5669",
                "5679",
                "5816",
                "5903",
                "5944",
                "5952",
                "5956",
                "5989",
                "5995",
                "6287",
                "6300",
                "6333",
                "6365",
                "6373",
                "6377",
                "6378",
                "6440",
                "6534",
                "6539",
                "6548",
                "6709",
                "6787",
                "6807",
                "6863",
                "6870",
                "6874",
                "6888",
                "6934",
                "7018",
                "7147",
                "7153",
                "7254",
                "7293",
                "7317",
                "7318",
                "7323",
                "7361",
                "7373",
                "7438",
                "7753",
                "7843",
                "8117",
                "8360",
                "8361",
                "8368",
                "8641",
                "8644",
                "8665",
                "8784",
                "8798",
                "8917",
                "8950",
                "8957",
                "8958",
                "8961",
                "8984",
                "26444",
                "26614",
                "27689",
                "27716",
                "27773",
                "27831",
                "27878",
                "30793",
                "30812",
                "31685",
                "32460",
                "32587",
                "33004",
                "33615",
                "33794",
                "34150",
                "34405",
                "36519",
                "36529",
                "37386",
                "37729",
                "37733",
                "37741",
                "38038",
                "38061",
                "40819",
                "44022",
                "44191",
                "44199",
                "44555",
                "44665",
                "45499",
                "45517",
                "45722",
                "46578",
                "46965",
                "47200",
                "47491",
                "48394",
                "48516",
                "48780",
                "49651",
                "50872",
                "51357",
                "51540",
                "51662",
                "52604",
                "53125",
                "53129",
                "53318",
                "53464",
                "53972",
                "53996",
                "54272",
                "54286",
                "55118",
                "55247",
                "55276",
                "55290",
                "55765",
                "56757",
                "57528",
                "57640",
                "57669",
                "58295",
                "58299",
                "58559",
                "59315",
                "59615",
                "59784",
                "60040",
                "60074",
                "60684",
                "60756",
                "62434",
                "63131",
                "64197",
                "64614",
                "64839",
                "64957",
                "65596",
                "66934",
                "67255",
                "68073",
                "68157",
                "68159",
                "68319",
                "68358",
                "68954",
                "69122",
                "69640",
                "69757",
                "69951",
                "70286",
                "71108",
                "71156",
                "71899",
                "72011",
                "72378",
                "72998",
                "73017",
                "73268",
                "73321",
                "73323",
                "73499",
                "74458",
                "74510",
                "74789",
                "74948",
                "76077",
                "76175",
                "76251",
                "77561",
                "78469",
                "78499",
                "79132",
                "79293",
                "79592",
                "79695",
                "79702",
                "80219",
                "80489",
                "81788",
                "83349",
                "84392",
                "85354",
                "85414",
                "86190",
                "86332",
                "86628",
                "86880",
                "87232",
                "88094",
                "88129",
                "88140",
                "89745",
                "90600",
                "91485",
                "91500",
                "91529",
                "91542",
                "91658",
                "92094",
                "95441",
                "96432",
                "96488",
                "96610",
                "96655",
                "97752",
                "97938",
                "98124",
                "98585",
                "98809",
                "99114",
                "99728",
                "99813",
                "102125",
                "102445",
                "102903",
                "103253",
                "103772",
                "104241",
                "104879",
                "106072",
                "106487",
                "106489",
                "106782",
                "106839",
                "107846",
                "109374",
                "109487",
                "110102",
                "111362",
                "111759",
                "112183",
                "112334",
                "112421",
                "112552",
                "112852",
                "114060",
                "114066",
                "115713",
                "116797",
                "116823",
                "117176",
                "118900",
                "119145",
                "122886",
                "122892",
                "122900",
                "122904",
                "122918",
                "122920",
                "122924",
                "122926",
                "128620",
                "134130",
                "134853",
                "135569",
                "139385",
                "140289",
                "141688",
                "142488",
                "144210",
                "145283",
                "148626",
                "150548",
                "155168",
                "157108",
                "157110",
                "158238",
                "158972",
                "159093",
                "160438",
                "161582",
                "162350",
                "162606",
                "164179",
                "166015",
                "166635",
                "168252",
                "171023",
                "176101",
                "177593",
                "180095",
                "180777",
                "185135"
            ]
        }
    ]
}

recommendation's People

Contributors

suraphanl avatar

Watchers

James Cloos avatar  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.