{"id":13619333,"url":"https://github.com/goessl/MachineLearning","last_synced_at":"2025-04-14T16:31:16.263Z","repository":{"id":65264161,"uuid":"95824962","full_name":"goessl/MachineLearning","owner":"goessl","description":"An easy neural network for Java!","archived":false,"fork":false,"pushed_at":"2019-03-03T18:29:28.000Z","size":43,"stargazers_count":126,"open_issues_count":0,"forks_count":35,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-29T23:21:43.721Z","etag":null,"topics":["artificial-intelligence","begginer","easy-to-use","hidden-layers","java","learning","learning-rate","lightweight","machine-learning","matrices","matrix","matrix-calculations","neural-network","neurons","prediction","weight","weights"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goessl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-29T22:22:31.000Z","updated_at":"2025-03-16T22:33:20.000Z","dependencies_parsed_at":"2023-01-16T15:00:54.001Z","dependency_job_id":null,"html_url":"https://github.com/goessl/MachineLearning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2FMachineLearning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2FMachineLearning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2FMachineLearning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2FMachineLearning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goessl","download_url":"https://codeload.github.com/goessl/MachineLearning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248916598,"owners_count":21182836,"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":["artificial-intelligence","begginer","easy-to-use","hidden-layers","java","learning","learning-rate","lightweight","machine-learning","matrices","matrix","matrix-calculations","neural-network","neurons","prediction","weight","weights"],"created_at":"2024-08-01T21:00:38.492Z","updated_at":"2025-04-14T16:31:16.246Z","avatar_url":"https://github.com/goessl.png","language":"Java","readme":"# Machine Learning\n# Deprecated\n**This repository is deprecated! Please use [NeuralNetwork](https://github.com/sebig3000/NeuralNetwork) instead!**\n\nJava collection that provides Java packages for developing machine learning algorithms and that is\n- easy to use -\u003e great for small projects or just to learn how machine learning works\n- small and simple -\u003e easy to understand and make changes\n- lightweight (mostly because I'm a student who just started to learn how to code Java and can't code more complex :P)\n\n## Getting Started\n\n### Prerequisites\n\nThis project is written in pure vanilla Java so there is nothing needed than the standard libraries.\n\n### Installation\n\nJust add all packages with the source files in the [Source folder /src](src) to your project and you are ready to go!\nEvery class has a main test method. After installation just run any class so you can check if the installation was successful.\n\n## Code Example\n\n### [Neural Network](src/main/java/neural)\n\nInitialize a new network with a given architecture (number or inputs, number of neurons in the hidden layers and each layers activation function)\n(If you don't know what to choose, here is a rule of thumb for a average looking network: \n- number of hidden layers = 2\n- number of neurons per layer: number of inputs (except the last layer is the output layer = as many neurons as outputs)\n- activation functions: none)\n\n```\n//New network\nfinal Network net = new Network(\n        2,                                    //2 inputs\n        new int[]{3, 1},                      //2 layers with 3 \u0026 1 neurons\n        new Network.ActivationFunction[]{\n          Network.ActivationFunction.NONE,    //both layers with ...\n          Network.ActivationFunction.NONE});  //... no activation function\n```\n\nThen you can seed the weights in the network (= randomize it).\n\n```\nnet.seedWeights(-1, 1);\n```\n\nPrepare your training data and put it into a [Matrix] (src/main/java/neural/Matrix.java)\n\n```\n//Generate 10 training sets\n//Every row represents one training set (10 rows = 10 sets)\n//Every column gets fed into the same input/comes out of the same output\n//(first column gets into the first input)\n//(2 columns = 2 inputs / 1 column = 1 output)\nfinal Matrix trainInput = new Matrix(10, 2);\nfinal Matrix trainOutput = new Matrix(10, 1);\n//Fill the training sets\n//Inputs: two random numbers\n//Outputs: average of these two numbers\nfinal Random rand = new Random();\nfor(int set=0; set\u003ctrainInput.getHeight(); set++) {\n  trainInput.set(set, 0, rand.nextInt(10));\n  trainInput.set(set, 1, rand.nextInt(10));\n  \n  final double out = (trainInput.get(set, 0) + trainInput.get(set, 1)) / 2;\n  trainOutput.set(set, 0, out);\n}\n```\n\nNow your network is ready for training!\nJust tell it how drastic the changes should be, give it the training data and if it should print it's progress to the console.\n* learning rate: higher = faster training but to high could miss the optimum, slower = better result (sometimer it goes crazy and the cost just increase, then try decreasing the laerning rate)\n* inputs: training set inputs\n* outputs: wanted outputs the network should learn from\n* printToConsole: show the progress in the console\n\n\n```\nnet.train(0.2, trainInput, trainOutput, true);\n```\n\nNow the network should be trained so let's have a look at the network itself by simply printing a basic representation and try forwarding the inputs.\n\n```\nSystem.out.println(net);\nSystem.out.println(net.forward(trainInput));\n```\n\nAnd if we would like to get the mean squared error we just call the cost function on some data:\n\n```\nSystem.out.println(net.cost(trainInput, trainOutput));\n```\n\n## Contributors\n\nThe two people who inspired me to try making my own machine learning project are Brandon Rohrer and Stephen Welch.\nBoth make awesome YouTube videos that explain how machine learning works.\n\nBrandon Rohrer:\n- YouTube https://www.youtube.com/channel/UCsBKTrp45lTfHa_p49I2AEQ\n- Blog: https://brohrer.github.io/blog.html\n- GitHub: https://github.com/brohrer\n\nStephen Welch:\n- YouTube: https://www.youtube.com/user/Taylorns34\n- Homepage: http://www.welchlabs.com/\n- GitHub: https://github.com/stephencwelch\n\n## License (MIT)\n\nMIT License\n\nCopyright (c) 2017 Sebastian Gössl\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":["Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoessl%2FMachineLearning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoessl%2FMachineLearning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoessl%2FMachineLearning/lists"}