{"id":15891587,"url":"https://github.com/yoyolicoris/ML_HW2","last_synced_at":"2025-10-18T01:30:41.697Z","repository":{"id":140051774,"uuid":"110664502","full_name":"yoyolicoris/ML_HW2","owner":"yoyolicoris","description":"My implementation of homework 2 for the Machine Learning class in NCTU (course number 5088).","archived":false,"fork":false,"pushed_at":"2017-11-21T16:00:03.000Z","size":792,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T07:36:34.213Z","etag":null,"topics":["bayesian-inference","bayesian-linear-regression","logistic-regression","multiclass-logistic-regression"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoyolicoris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-14T08:50:31.000Z","updated_at":"2023-07-17T06:40:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"e49404d8-4b10-4776-8344-eaccc263a3a4","html_url":"https://github.com/yoyolicoris/ML_HW2","commit_stats":null,"previous_names":["yoyolicoris/ml_hw2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyolicoris%2FML_HW2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyolicoris%2FML_HW2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyolicoris%2FML_HW2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyolicoris%2FML_HW2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoyolicoris","download_url":"https://codeload.github.com/yoyolicoris/ML_HW2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236887953,"owners_count":19220438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-inference","bayesian-linear-regression","logistic-regression","multiclass-logistic-regression"],"created_at":"2024-10-06T07:40:38.479Z","updated_at":"2025-10-18T01:30:41.347Z","avatar_url":"https://github.com/yoyolicoris.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Homework 2 for Machine Learning\n\n## Environment\n\n* ubuntu 16.04 LTS\n* python2.7.12 (using Pycharm 2017.2.4)\n* extra modules: numpy, scipy, pandas\n\n## Usage of each file\n\n### Bayesian Inference for Gaussian (HW 1-2)\n\nFor the task 1-2, type the following command:\n\n```\npython bayesian_inference.py 1_data.mat\n```\nIt will find the MAP solution of the covariance matrix, and compare it to the true covariance (using numpy.cov).\nThe output is like the following:\n```\nthe true covariance is\n[[ 0.30082961  0.39309777]\n [ 0.39309777  0.89266987]]\n\u003c N = 10 \u003e\nthe MAP solution of covariance is\n[[ 0.72927715  1.06310276]\n [ 1.06310276  2.47424115]]\nerror of MAP solution is 0.837507199995\n\u003c N = 100 \u003e\nthe MAP solution of covariance is\n[[ 0.36316943  0.45461111]\n [ 0.45461111  1.03532019]]\nerror of MAP solution is 0.0820042028936\n\u003c N = 500 \u003e\nthe MAP solution of covariance is\n[[ 0.31936913  0.39865164]\n [ 0.39865164  0.88775764]]\nerror of MAP solution is 0.00863987484804\n```\nI also try another approach, which will randomly generate muliple covariance matrix, and compute their probability to pick up the maximum one.\n\n```\npython bayesian_inference_random_generate.py 1_data.mat \u003cnumber of data\u003e \u003cnumber of random covariance matrix\u003e\n\n#the output format\n----testing----\nthe approximated MAP solution of covariance is\n[[ 0.31907513  0.39842093]\n [ 0.39842093  0.88619125]]\nthe true covariance is\n[[ 0.30082961  0.39309777]\n [ 0.39309777  0.89266987]]\nerror of approximated MAP solution is 0.00884261234455\nthe posterior probability is 15.4547626093\n```\n\n### Bayesian Linear Regression (HW 2-2, 2-3)\n\nFor the task 2-2, type the following command:\n```\npython bayesian_linear_regression.py 2_data.mat\n```\nThis will plot four image similar to Fig. 3.9 on the testbook for different N, like the following image:\n![](images/blr_1.png)\n\nFor the task 2-3, type the following command:\n```\npython bayesian_lin_regress_show_region.py 2_data.mat\n```\nThis will plot four image similar to Fig. 3.8 on the testbook for different N, like the following image:\n![](images/blr_2.png)\n\n### Logistic Regression (HW 3-1~3, 3-5, 3-6)\n\nFor the task 3-1 and 3-2, type the following command:\n```\npython lofistic_regression.py train.csv test.csv\n```\nThis will first plot the cross entropy and accuracy versus number of epochs like the following image:\n![](images/logistic_1.png)\n\nAnd the classification result :\n```\nThe test data classification result is :\n[2 2 2 1 2 2 2 2 2 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0]\n```\nThe number means the target class name by columns.\n\nFor the task 3-3, please type the following command:\n```\npython plot_training_data.py train.csv\n```\n\nThis will create series of image ploting the distribution of each variable named with the column index:\n![](images/hist_1.png)\n\nFor the task 3-5 and 3-6, type the following command:\n```\npython most_contributive_variable.py train.csv test.csv\n```\n\nIt will first display the following message and plot the distribution of the two variable:\n```\nThe most contributive variable pair is column 3 and 12\n```\n![](images/3\u002612.png)\n\nAnd then redo the task 3-1 \u0026 3-2 again using these two variable.\nThe test data classification result is:\n```\n[2 2 2 0 2 2 2 2 2 2 0 1 0 1 1 0 1 1 2 0 1 1 1 0 0 0 1 1 1]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoyolicoris%2FML_HW2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoyolicoris%2FML_HW2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoyolicoris%2FML_HW2/lists"}