{
    "componentChunkName": "component---src-templates-docs-js",
    "path": "/assignments/a4",
    "result": {"data":{"site":{"siteMetadata":{"title":"Linnaeus University","language":"en"}},"mdx":{"fields":{"id":"c799bb44-7b46-5d60-af59-2a94c051ca46","title":"A4 - Machine Learning","slug":"/assignments/a4"},"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"A4 - Machine Learning\",\n  \"metaTitle\": \"2DV515 | A4\",\n  \"metaDescription\": \"metaDescription\",\n  \"order\": 4\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar Hint = makeShortcode(\"Hint\");\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h2\", null, \"Description\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"In this assignment, you shall implement the Na\\xEFve Bayes machine learning algorithm and use it on some datasets.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"You can use any programming language you like.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"You shall present your application and code at an oral examination.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"You are not required to build a REST web service for this assignment.\")), mdx(\"h2\", null, \"Submission instructions\"), mdx(\"p\", null, \"See the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"../study-guide/deadlines-and-submissions\"\n  }, \"Deadlines and Submissions\"), \" page.\"), mdx(\"h2\", null, \"Requirements\"), mdx(\"table\", null, mdx(\"tr\", null, mdx(\"th\", null, \"Grade\"), mdx(\"th\", null, \"Requirements\")), mdx(\"tr\", null, mdx(\"td\", null, \"E\"), mdx(\"td\", null, mdx(\"ul\", null, mdx(\"li\", null, \"Implement the Na\\xEFve Bayes algorithm, using the code structure below (you are allowed to add more classes and methods if needed).\"), mdx(\"li\", null, \"Train the model on the \", mdx(\"em\", null, \"Iris\"), \" and \", mdx(\"em\", null, \"Banknote authentication datasets\"), \" (see \", mdx(\"a\", {\n    href: \"datasets\"\n  }, \"Datasets\"), \" page).\"), mdx(\"li\", null, \"Calculate classification accuracies for both datasets (use all data for both training and testing).\")))), mdx(\"tr\", null, mdx(\"td\", null, \"C-D\"), mdx(\"td\", null, mdx(\"ul\", null, mdx(\"li\", null, \"Implement code for generating confusion matrices, using the code structure below.\")))), mdx(\"tr\", null, mdx(\"td\", null, \"A-B\"), mdx(\"td\", null, mdx(\"ul\", null, mdx(\"li\", null, \"Implement code for n-fold cross-validation, using the code structure below.\"), mdx(\"li\", null, \"It shall be possible to use 3, 5 or 10 folds (it is okay if your implementation supports other folds).\"), mdx(\"li\", null, \"Calculate accuracy score for 5-fold cross-validation on both datasets.\"))))), mdx(Hint, {\n    type: \"warning\",\n    mdxType: \"Hint\"\n  }, mdx(\"b\", null, \"Note!\"), \" The purpose of this assignment is that you shall learn how to implement Na\\xEFve Bayes, encoding label strings to integers, calculating accuracy scores, performing cross-validation, and generating a confusion matrix. These functionalities are often available in machine learning libraries such as Weka or Scikit-learn, which you are not allowed to use. You are allowed to use library functions for loading and shuffling the data and all necessary mathematical operations, data structures, etc.\"), mdx(\"h2\", null, \"Code structure requirements\"), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"NaiveBayes class\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"span\", {\n    style: {\n      \"fontFamily\": \"monospace\"\n    }\n  }, mdx(\"font\", {\n    color: \"red\"\n  }, \"void\"), \" fit ( \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"X:float\", \"[][]\"), \", \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"y:int[]\"), \" )\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }, mdx(\"em\", {\n    parentName: \"td\"\n  }, \"Trains the model on input examples X and labels y.\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"span\", {\n    style: {\n      \"fontFamily\": \"monospace\"\n    }\n  }, mdx(\"font\", {\n    color: \"red\"\n  }, \"int[]\"), \" predict ( \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"X:float\", \"[][]\"), \" )\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }, mdx(\"em\", {\n    parentName: \"td\"\n  }, \"Classifies examples X and returns a list of predictions.\"))))), mdx(\"br\", null), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Other methods\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"span\", {\n    style: {\n      \"fontFamily\": \"monospace\"\n    }\n  }, mdx(\"font\", {\n    color: \"red\"\n  }, \"float\"), \" accuracy_score ( \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"preds:int[]\"), \", \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"y:int[]\"), \" )\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }, mdx(\"em\", {\n    parentName: \"td\"\n  }, \"Calculates accuracy score for a list of predictions.\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"span\", {\n    style: {\n      \"fontFamily\": \"monospace\"\n    }\n  }, mdx(\"font\", {\n    color: \"red\"\n  }, \"int\", \"[][]\"), \" confusion_matrix ( \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"preds:int[]\"), \", \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"y:int[]\"), \" )\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }, mdx(\"em\", {\n    parentName: \"td\"\n  }, \"Generates a confusion matrix and returns it as an integer matrix.\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"span\", {\n    style: {\n      \"fontFamily\": \"monospace\"\n    }\n  }, mdx(\"font\", {\n    color: \"red\"\n  }, \"int[]\"), \" crossval_predict ( \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"X:float\", \"[][]\"), \", \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"y:int[]\"), \", \", mdx(\"font\", {\n    color: \"blue\"\n  }, \"folds:int\"), \"  )\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": \"center\"\n  }, mdx(\"em\", {\n    parentName: \"td\"\n  }, \"Runs n-fold cross-validation and returns a list of predictions.\"))))), mdx(Hint, {\n    mdxType: \"Hint\"\n  }, \"Input data (a float matrix with input variables as columns and examples as rows) is usually denoted with \", mdx(\"code\", null, \"X\"), \". The categories/labels (a list of integers) is usually denoted as \", mdx(\"code\", null, \"y\"), \". Predictions (a list of integers) shall be compared with the actual labels (\", mdx(\"code\", null, \"y\"), \") when calculating the accuracy score (percentage correct predictions) and generating the confusion matrix.\"), mdx(\"h2\", null, \"Test cases\"), mdx(\"p\", null, \"You can verify your results with the results in \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"http://aiguy.freecluster.eu/webml/experimenter.html\"\n  }, \"Web ML Demonstrator\"), \". The \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Iris\"), \" dataset is built-in in Web ML (click the \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Try Iris dataset\"), \" button), and the \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Banknote authentication\"), \" can be uploaded from the CSV file. Note that the cross-validation results can differ slightly due to how the data is split into folds, but the accuracy you get should be almost similar to the accuracy in Web ML.\"));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{"items":[{"url":"#description","title":"Description"},{"url":"#submission-instructions","title":"Submission instructions"},{"url":"#requirements","title":"Requirements"},{"url":"#code-structure-requirements","title":"Code structure requirements"},{"url":"#test-cases","title":"Test cases"}]},"parent":{"relativePath":"assignments/a4.md"},"frontmatter":{"metaTitle":"2DV515 | A4","metaDescription":"metaDescription"}},"allMdx":{"edges":[{"node":{"fields":{"slug":"/","title":"Web Intelligence (2DV515)"}}},{"node":{"fields":{"slug":"/_playground/_todo-examination","title":"TODO: Examination"}}},{"node":{"fields":{"slug":"/_playground/expectations","title":"Expectations"}}},{"node":{"fields":{"slug":"/_playground","title":"Playground"}}},{"node":{"fields":{"slug":"/assignments/a1","title":"A1 - Recommendation System"}}},{"node":{"fields":{"slug":"/assignments/a2","title":"A2 - Clustering"}}},{"node":{"fields":{"slug":"/assignments/a3","title":"A3 - Search Engine"}}},{"node":{"fields":{"slug":"/assignments/a4","title":"A4 - Machine Learning"}}},{"node":{"fields":{"slug":"/assignments/datasets","title":"Datasets"}}},{"node":{"fields":{"slug":"/assignments","title":"Assignments"}}},{"node":{"fields":{"slug":"/lectures","title":"Lectures"}}},{"node":{"fields":{"slug":"/lectures/lecture01","title":"L01 - Introduction"}}},{"node":{"fields":{"slug":"/lectures/lecture02","title":"L02 - Recommendation Systems"}}},{"node":{"fields":{"slug":"/lectures/lecture03","title":"L03 - Clustering"}}},{"node":{"fields":{"slug":"/lectures/lecture04","title":"L04 - Search Engines"}}},{"node":{"fields":{"slug":"/lectures/lecture05","title":"L05 - What is Machine Learning?"}}},{"node":{"fields":{"slug":"/lectures/lecture06","title":"L06 - Data and Learning"}}},{"node":{"fields":{"slug":"/lectures/lecture07","title":"L07 - Naïve Bayes"}}},{"node":{"fields":{"slug":"/projects","title":"Projects"}}},{"node":{"fields":{"slug":"/projects/p1","title":"P1 – Recommendation System"}}},{"node":{"fields":{"slug":"/projects/p2","title":"P2 – Clustering"}}},{"node":{"fields":{"slug":"/projects/p3","title":"P3 – Text Classification"}}},{"node":{"fields":{"slug":"/projects/p4","title":"P4 – Web scraping"}}},{"node":{"fields":{"slug":"/projects/project","title":"Project"}}},{"node":{"fields":{"slug":"/sandbox/basic-elements","title":"Basic elements"}}},{"node":{"fields":{"slug":"/sandbox/code","title":"Code"}}},{"node":{"fields":{"slug":"/sandbox/exercise","title":"Exercises"}}},{"node":{"fields":{"slug":"/sandbox/frontmatter","title":"Frontmatter"}}},{"node":{"fields":{"slug":"/sandbox/hint","title":"Hint"}}},{"node":{"fields":{"slug":"/sandbox","title":"Sandbox"}}},{"node":{"fields":{"slug":"/sandbox/markdown-import","title":"Imported markdown"}}},{"node":{"fields":{"slug":"/sandbox/mermaid","title":"Mermaid"}}},{"node":{"fields":{"slug":"/sandbox/tabs","title":"Tabs"}}},{"node":{"fields":{"slug":"/sandbox/youtube","title":"YouTube"}}},{"node":{"fields":{"slug":"/study-guide/communication","title":"Communication"}}},{"node":{"fields":{"slug":"/study-guide/deadlines-and-submissions","title":"Deadlines and Submissions"}}},{"node":{"fields":{"slug":"/study-guide/grading","title":"Grading"}}},{"node":{"fields":{"slug":"/study-guide/registration","title":"Registration"}}},{"node":{"fields":{"slug":"/study-guide/welcome","title":"🎉 Welcome"}}},{"node":{"fields":{"slug":"/projects/_DEPRECATED/project","title":"Project"}}},{"node":{"fields":{"slug":"/study-guide/guides/an-introduction-to-git","title":"An introduction to Git"}}},{"node":{"fields":{"slug":"/study-guide/guides/git-and-multiple-computers","title":"Git and multiple computers"}}},{"node":{"fields":{"slug":"/study-guide/guides/git-commit-best-practices","title":"Git commit best practices"}}},{"node":{"fields":{"slug":"/study-guide/guides","title":"Guides"}}},{"node":{"fields":{"slug":"/study-guide/guides/set-up-git","title":"Set up Git"}}},{"node":{"fields":{"slug":"/study-guide/guides/multiple-git-user-configs","title":"Multiple Git user configs"}}},{"node":{"fields":{"slug":"/study-guide/guides/submit-an-assignment-as-a-merge-request","title":"Submit an assignment as a merge request"}}},{"node":{"fields":{"slug":"/study-guide/guides/this-happens-with-git-commands","title":"This happens with Git commands"}}},{"node":{"fields":{"slug":"/study-guide/guides/troubleshooting-ssh","title":"Troubleshooting SSH"}}},{"node":{"fields":{"slug":"/study-guide/readings","title":"Readings"}}},{"node":{"fields":{"slug":"/study-guide/instructors","title":"Instructors"}}},{"node":{"fields":{"slug":"/study-guide","title":"Study Guide"}}}]}},"pageContext":{"id":"c799bb44-7b46-5d60-af59-2a94c051ca46"}},
    "staticQueryHashes": ["253607798","3706406642","710574383"]}