RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a random machine learning script"
-- ScripterAI can only help with scripting as of now so here's a script for a machine learning algorithm -- Initialize the weights local weights = {1, 1, 1, 1, 1} -- Define the learning rate local learningRate = 0.1 -- Define the training data local trainingData = { {inputs = {0, 0, 0, 0, 0}, expectedOutput = 0}, {inputs = {0, 0, 0, 0, 1}, expectedOutput = 1}, {inputs = {0, 0, 0, 1, 0}, expectedOutput = 1}, {inputs = {0, 0, 0, 1, 1}, expectedOutput = 0}, {inputs = {0, 0, 1, 0, 0}, expectedOutput = 1}, {inputs = {0, 0, 1, 0, 1}, expectedOutput = 0}, {inputs = {0, 0, 1, 1, 0}, expectedOutput = 0}, {inputs = {0, 0, 1, 1, 1}, expectedOutput = 1}, {inputs = {0, 1, 0, 0, 0}, expectedOutput = 1}, {inputs = {0, 1, 0, 0, 1}, expectedOutput = 0}, {inputs = {0, 1, 0, 1, 0}, expectedOutput = 0}, {inputs = {0, 1, 0, 1, 1}, expectedOutput = 1}, {inputs = {0, 1, 1, 0, 0}, expectedOutput = 0}, {inputs = {0, 1, 1, 0, 1}, expectedOutput = 1}, {inputs = {0, 1, 1, 1, 0}, expectedOutput = 1}, {inputs = {0, 1, 1, 1, 1}, expectedOutput = 0}, {inputs = {1, 0, 0, 0, 0}, expectedOutput = 1}, {inputs = {1, 0, 0, 0, 1}, expectedOutput = 0}, {inputs = {1, 0, 0, 1, 0}, expectedOutput = 0}, {inputs = {1, 0, 0, 1, 1}, expectedOutput = 1}, {inputs = {1, 0, 1, 0, 0}, expectedOutput = 0}, {inputs = {1, 0, 1, 0, 1}, expectedOutput = 1}, {inputs = {1, 0, 1, 1, 0}, expectedOutput = 1}, {inputs = {1, 0, 1, 1, 1}, expectedOutput = 0}, {inputs = {1, 1, 0, 0, 0}, expectedOutput = 0}, {inputs = {1, 1, 0, 0, 1}, expectedOutput = 1}, {inputs = {1, 1, 0, 1, 0}, expectedOutput = 1}, {inputs = {1, 1, 0, 1, 1}, expectedOutput = 0}, {inputs = {1, 1, 1, 0, 0}, expectedOutput = 1}, {inputs = {1, 1, 1, 0, 1}, expectedOutput = 0}, {inputs = {1, 1, 1, 1, 0}, expectedOutput = 0}, {inputs = {1, 1, 1, 1, 1}, expectedOutput = 1} } -- Train the model for i = 1, 1000 do for j = 1, #trainingData do local data = trainingData[j] local prediction = 0 for k = 1, #data.inputs do prediction = prediction + data.inputs[k] * weights[k] end local error = data.expectedOutput - prediction for k = 1, #weights do weights[k] = weights[k] + learningRate * error * data.inputs[k] end end end -- Test the model for i = 1, #trainingData do local data = trainingData[i] local prediction = 0 for j = 1, #data.inputs do prediction = prediction + data.inputs[j] * weights[j] end print(data.expectedOutput .. " --> " .. prediction) end