MachineLL - Machine Learning Library For Roblox! (Linear, Logistic + 2 more) [Version 1.2]

Don’t forget to like this video and subscribe!

I’ll also add more supervised and unsupervised machine learning model later!

Also for featureMatrix, number of rows are equal to number of data. Meanwhile number of columns are equal to number of variables contained in that particular data in featureMatrix.

Same goes for labelVector, where number of rows are number of data, but only have one column because that is the actual value related to one given data.

Available Models
  • Linear Regression
  • Logistic Regression
  • KMeans
  • (Linear) Support Vector Machine
How To Use

You need two libraries (one for matrix library and another for machine learning library). You must use the matrix library that is made by me or it will not work!

(PS: it’s probably not the fastest or best matrix library, but I really don’t want to deal with legal issues if I use other people’s matrix libraries)

Step 1
Once you put those two libraries into your game make sure you link the Machine Learning Library with the Matrix Library. This can be done via setting the “AqwamRobloxMatrixLibraryLinker” value (under the Machine Learning library) to the Matrix Library.

Step 2
Use require() on Machine Learning Library.

Step 3
Here are the examples.


local MachineLL = require(game.ServerScriptService.AqwamRobloxMachineLearningLibrary)

local LinearRegression = MachineLL.LinearRegression
local LogisticRegression = MachineLL.LogisticRegression

local modelParameters, cost = LinearRegression:train(featureMatrix, labelVector, maxNumberOfIterations, learningRate, lossFunction, targetCost, suppressOutput)

local result =  LinearRegression:predict(featureMatrix, modelParameters)

local modelParameters, cost = LogisticRegression:train(featureMatrix, labelVector, maxNumberOfIterations, learningRate, sigmoidFunction, targetCost, suppressOutput)

local result =  LogisticRegression:predict(featureMatrix, modelParameters)

Make sure the matrices/vectors are created like shown below:


local featureMatrix = {
	
	{ 0,  0},
	{10, 10},
	{-3, -3},
	{-2, -2},
	{ 2,  2},
	{ 1,  1},
	{-1, -1},
	{ 3,  3},
	{-8, -8},

}

local labelVectorRegression = {
	
	{ 0},
	{10},
	{-3},
	{-2},
	{ 2},
	{ 1},
	{-1},
	{ 3},
	{-8},

}

local labelVectorLogistic = {
	
	{1},
	{1},
	{0},
	{0},
	{1},
	{1},
	{0},
	{1},
	{0}
	
}

local testFeatureMatrix = {

	{-3, -3}, 	

}

Explanation
  1. In order for you to create a machine learning model, you need to train using input data first by putting it in the first two arguments :train() function (featureMatrix and labelVector). featureMatrix is the matrix for values to be input, and labelVector is the vector containing actual values (or rather, selected feature) that has certain relationship with the featureMatrix.

  2. You may set additional settings to other arguments. However, you can leave it to set it as default. Using nil as a value will set that particular setting as default.

  3. Once the model is run using the values given, it will generate a model parameter that you can use for your future prediction. Make sure to save it in DataStore if you want to keep the model parameters!

  4. To predict values, you can use :predict() function, where the first argument will be your feature matrix and the second argument is your generated model.

Differences Between Linear and Logistic Regression

  • Linear Regression: predicts continuous values (e.g. 1.2, -3.1, 2, and so on)

  • Logistic Regression: predicts discrete values that falls either 0 or 1 only

How To Save Models
  • Save it to DataStoreService

  • Copy paste to any text editor

Important Notes
  • When using the feature matrix and label vector to train the models, make sure the number of rows are the same!

  • The labelVector must only have (n x 1) dimension!

  • Make sure the value of learningRate is between 0 and 1! Anything else may cause the machine learning model not work properly!

  • For the best model accuracy, ensure that the cost decreases until it stabilizes. If there is a large increase of cost value after a while, then it means the training is not complete and the model may not be accurate. To get best model accuracy, make sure you play around with the argument settings

  • Consequently, if the cost keeps on steadily increasing, it means your learning rate is too large and started to diverge. Try smaller values.

Use Cases

LinearRegression:

  • Make prediction on how long will a player reach certain level
  • Spawn an enemy where the difficulty is based on input

LogisticRegression:

  • Make an enemy that makes decision between 2 choices (e.g. fighting and running)
  • Detect hacking players

KMeans

  • Group players in terms of experience level

SupportVectorMachine

  • Detect hacking players
Libraries Download Links

Required Libraries:

Aqwam's Roblox Machine Learning Library - Roblox

Aqwam's Roblox Matrix Library - Roblox

Bonus Libraries:

Aqwam's Roblox Data Mining Library - Roblox

Documentation

Required Libraries Documentation:

Aqwam’s Roblox Machine Library Documentation

Aqwam's Roblox Matrix Library Documentation

Github

GitHub - AqwamCreates/Aqwam-Roblox-Machine-Learning-Library: A Machine Learning Library For Roblox
GitHub - AqwamCreates/Aqwam-Roblox-Matrix-Library: A Matrix Library For Roblox
GitHub - AqwamCreates/Aqwam-Roblox-Data-Mining-Library: A Data Mining Library For Roblox

Known Problems
  • Some times the cost value can turn to nan. This is because there are very long decimal points when training the model parameters. A short term fix is to add target cost or limit the max number of iterations when training the model.

  • Setting c value for support vector machine does not change anything in the model for now. You can use this model without issues.

Models Under Development
  • Expectation-Maximization
28 Likes

Tip: when making a contribution, it’s often appreciated to include a documentation and/or examples so other developers can see the value. Just a code drop will often be ignored.

1 Like

Ah. Alright. I’ll just put some examples here then.

I’m done adding examples…
Tough that is quite a lot of edit there…

Just fixed one of the issues where the LinearRegression incorrectly calculate the error values.

I have added KMeans to the library. Still a hit or miss though, so I’m figuring this out for now.
Also please update the matrix library as well.

Fixed KMeans giving the parameter values of infinity. I just made sure whenever there are zero data points assigned to that particular centroids, it will be set to 1.

Hopefully no significant impact on the accuracy.

Couple of updates made to the library. Also, I will release a data mining library suited for this machine learning library so you don’t waste time coding.

Hmm… The library sure don’t like very long decimal values… It’s probably causing the nan issue, which eventually cause the models to not train properly.

Hopefully I can find some fix for this soon.

For now, I recommend you guys set a targetCost to avoid this problem.

Interesting module, probably gonna use it in my next project.

1 Like

New machine learning model introduced!
Support Vector Machine!

Fixed everything except cValue issue for support vector machine.

Final fix and I will stop working on this project for a while. Any complaints or issues, please reply to this post.

Still no reinforcement learning libraries for roblox? Damn.

1 Like

I’m planning to make deep learning library later, but I am unsure if I have time for that. I’ve created a couple of deep learning models from scratch in python but that was like three years ago.

So yeah, we’ll see…

1 Like

The issue with reinforcement learning is that it is highly specific and is hard to put as a resource. I know this since I’ve made a reinforcement learning algorithm before, but it’s not generic. To make it a resource, it would require me to make it generic, and suitable for many use cases.


What would I input to the model to support this use case? Would I not use a linear regression to determine the confidence level in which the player is hacking?

I’ve never seen a machine learning library for Roblox before, but this seems pretty cool.

It is highly specific sometimes, yes and requires a lot of extra hyperparameters to be adjusted for it to work but there are libraries that show it is possible. Many generic reinforcement learning algorithms already exist.

If you just look at the RLZoo library on python it has plenty of common general RL algorithms like the DQN family, actor critics and policy gradient methods e.g REINFORCE, TRPO, PPO. Those are the 3 main types of algorithms and there are a few more algorithms under those categories that I didn’t put. These algorithms alone are enough to solve many types of problems.

Also, to answer your question about linear regression, linear regression is a method used for regression problems while logistic regression is used for classification problems. What this essentially means is linear regression is not bounded within a range while logistic regression is bounded between [0,1].


Source: Linear Regression vs Logistic Regression - Javatpoint

I had a few ideas like velocity or change in X, Y, and Z though there are probably more that I didn’t think of.

(My original answer for which model to use was not great, so just look at the replies below for a better understanding.) It’s not really necessary to use machine learning to detect hackers. Only do so if you have a specific use-case in mind.

Hmm… I don’t necessarily agree that it is a sequential problem, but rather an anomaly problem.
Usually hackers have traits that are way out of bounds (such as speed) that do not exists in normal players.

To be honest, using a Support Vector Machine/KMeans would be a better way to separate between hackers and the normal players than the logistic regression.

Additionally, the best case is to use Expectation-Maximization Algorithm to detect hackers like in this case, but it isn’t included in this library. Too bad I’m lacking brainpower to build one LOL.

Ah. In addition to what Scriptorial said, you can also use support vector machine or KMeans to detect hackers. Those are better ways to detect hackers as I said here.

That’s true, but I was accounting for a use-case where you couldn’t use normal checks like walk speed or jump power and maybe you were trying to detect teleportation. If it was just a normal speed or jump hack check you don’t really need to use any machine learning to detect it. But maybe a sequential model is not the right type of model for teleportation detection. I was thinking of how you could make the model separate between laggy players and people who are actually hacking and a sequential model was the first thing that came to mind, lol.