Deprecated: Required parameter $query follows optional parameter $post in /var/www/html/wp-content/plugins/elementor-extras/modules/breadcrumbs/widgets/breadcrumbs.php on line 1215
Number Classifier and Regression (ML) - Blocks, Python Functions, Projects | PictoBlox Extension
[PictoBloxExtension]

Number Classifier and Regression (ML)

Numbers icon
Extension Description
Create ML models to perform number-based data classification and regression.

Introduction

Numbers(C/R) is the extension of the ML Environment that deals with the classification and regression of numeric data.

Datasets on the internet are hardly ever fit to directly train on. Programmers often have to take care of unnecessary columns, text data, target columns, correlations, etc. Thankfully, PictoBlox’s ML Environment is packed with features to help us pre-process the data as per our liking.

Opening Number (C/R) Workflow

Alert: The Machine Learning Environment for model creation is available in the only desktop version of PictoBlox for Windows, macOS, or Linux. It is not available in Web, Android, and iOS versions.

Follow the steps below:

  1. Open PictoBlox and create a new file.
  2. Select the coding environment as appropriate Coding Environment.
  3. Select the “Open ML Environment” option under the “Files” tab to access the ML Environment.
  4. You’ll be greeted with the following screen.
    Click on “Create New Project“.
  5. A window will open. Type in a project name of your choice and select the “Numbers(C/R)” extension. Click the “Create Project” button to open the Numbers(C/R) window.
  6. You shall see the Numbers C/R workflow with an option to either “Upload Dataset” or “Create Dataset”.

Uploading/Creating Dataset

Datasets can either be uploaded or created on the ML Environment. Lets see how it is done.

Uploading a dataset

  1. To upload a dataset, click on the Upload Dataset button and the Choose CSV from your files button.
    Note: An uploaded dataset must be a “.csv” file.
  2. Once uploaded the first 50 rows of the uploaded CSV document will show up in the window.

Creating a Dataset

  1. To create a dataset, click on the Create Dataset button.
  2. Select the number of rows and columns that are to be added and click on the Create button. More rows and columns can be added as and when needed.
  3. The dataset will appear in the window with every value set to 0. Click on the values to edit them.

Notes:

  1. Each column represents a feature. These are the values used by the model to train itself.
  2. The “Output” column contains the target values. These are the values that we expect the model to return when features are passed.
  3. The window only shows the first 50 rows of the dataset.
  4. Un-check the “Select All” checkbox to un-select all the columns.

“Dataset Setting” Section

This section contains functions that help in pre-precessing the data.

  1. Dataset Shuffle: This function shuffles the rows of the dataset. This can often lead to better training and testing results. Simply click on the button to shuffle the dataset.
  2. Set as Output: This button sends the selected column to the “Output” column. This will convert the column into the target column.
    Alert: The target column must be a numerical column. If not numerical, the column must be converted into one (refer to the “Text to Number” function).

  3. Features Manipulation: The column is the features for which you will train the data. There are a lot of options available to edit it:
    1. Add Features: This function adds the given number of columns to the dataset.
    2. Create Copy: Creates a copy of the selected column.
    3. Delete: This option deletes the selected columns.
    4. Reset: This option resets all the data of the selected columns.
    5. Disable: This option does not delete the selected column but excludes it from training, i.e. the column becomes invisible to the model.
    6. Enable: This option enables a previously disabled column.
  4. Selected rows: Create Copy, Delete, Reset, Enable, Disable options are similar to the column.
  5. Selected columns(Graphs): These are visualization methods that help in making sense of the data. They can also be used to remove unnecessary columns from the dataset.
    1. Draw Graph: Plots the values of the two selected columns on the x-y plane. Helps in visualizing the relation between two columns.
      Note: Can only be used for two columns at once.

      To draw a graph, simply select the two columns, and click on the “Draw Graph” button.

    2. Correlation: Correlation denotes the relationship between the columns of a dataset. Highly correlated columns create redundant features that are not of significance in the model training, such columns are best disabled. This technique is extremely helpful when dealing with datasets with a large number of columns as they can often slow down and sometimes adversely affect training. Correlation can be observed between two columns as well, but it’s often more useful to observe correlation for the entire dataset.
      Alert: Make sure that no particular columns are selected and click on the “Correlation” button.

      The range of correlation is (-1,1). It’s always a good idea to drop a column with an extremely high correlation with another. Set the threshold on the right side panel and click on the “Disable” button to disable the column(s).

  6. Text to Number: The “Text to Number” button assigns a number to all the unique values in a column. If a column has three unique values, they will be assigned corresponding numbers starting with 0. Hence, the values in the case of three unique values would be 0, 1, and 2.

    Note: Notice how each species has been assigned to a unique number. This method is also called “Label Encoding”.
  7. Replace: Replaces a particular number of a column with another number. To replace all the instances of 3 in column “SepalWidthCm” with 11, select the column, do the desired changes, and click on the “Replace” button.

Training the Model

After data is pre-processed and optimized, it’s fit to be used in model training. To train the model, simply click the “Train Model” button found in the “Training” panel.

By training the model, meaningful information is extracted from the numbers, and that in turn updates the weights. Once these weights are saved, the model can be used to make predictions on data previously unseen.

The model’s function is to use the input data and predict the output. The target column must always contain numbers.

However, before training the model, there are a few hyperparameters that need to be understood. Click on the “Advanced” tab to view them.

There are three hyperparameters that can be altered in the Numbers(C/R) Extension:

  1. Epochs– The total number of times the data will be fed through the training model. Therefore, in 10 epochs, the dataset will be fed through the training model 10 times. Increasing the number of epochs can often lead to better performance.
  2. Batch Size– The size of the set of samples that will be used in one step. For example, if there are 160 data samples in the dataset, and the batch size is set to 16, each epoch will be completed in 160/16=10 steps. This hyperparameter rarely needs any altering.
  3. Learning Rate– It dictates the speed at which the model updates the weights after iterating through a step. Even small changes in this parameter can have a huge impact on the model performance. The usual range lies between 0.001 and 0.0001.
Note: Hover the mouse pointer over the question mark next to the hyperparameters to see their description.

It’s a good idea to train a numeric classification model for a high number of epochs. The model can be trained in both JavaScript and Python. In order to choose between the two, click on the switch on top of the Training panel.

Alert: Dependencies must be downloaded to train the model in Python, JavaScript will be chosen by default.

The accuracy of the model should increase over time. The x-axis of the graph shows the epochs, and the y-axis represents the accuracy at the corresponding epoch.

Testing the Model

To test the model, simply enter the input values in the “Testing” panel and click on the “Predict” button.

The model will return the probability of the input belonging to the classes.

Export in Block Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Block Coding Environment if you have opened the ML Environment in the Block Coding.

Export in Python Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Python Coding Environment if you have opened the ML Environment in Python Coding.

The following code appears in the Python Editor of the selected sprite.

import numpy as np
import tensorflow as tf

#Load Number Model
model = tf.keras.models.load_model("num_model.h5",
                                   custom_objects=None,
                                   compile=True,
                                   options=None)

#Inputs
sepal_length = 0
sepal_width = 0
petal_length = 0

#List of classes
class_list = [
    'Iris-versicolor',
    'Iris-setosa',
    'Iris-virginica',
]

#Input List
inputValue = [
    sepal_length,
    sepal_width,
    petal_length,
]

#Input Tensor
inputTensor = tf.expand_dims(inputValue, 0)

#Predict
predict = model.predict(inputTensor)
predict_index = np.argmax(predict[0], axis=0)

#Output
predicted_class = class_list[predict_index]
print(predicted_class)
Note: You can edit the code to add custom code according to your requirement.
Read More

PictoBlox Blocks

The Block makes a request to ChatGPT with the specified text and stores the response in PictoBlox, which can then be accessed with the Block ‘Get AI Response’. This Block also features three types of AI bots – Normal AI, Sarcastic AI, and Friend AI.
This block enables users to set the digital state of an Arduino digital pin to either a High (5V) or Low (0V) voltage output. It can be used on the Arduino Uno, Mega, and Nano boards.
The block allows the user to set the cursor position in an LCD module. It takes two parameters, the column and row numbers, and moves the cursor to that position. This allows the user to create more precise output for the display.
This block adds the offset on the end effector position along the specified length direction i.e. the direction in which the robotic arm is facing and the Z direction.
This block moves the robot forward and backward for a set time, collecting IR sensor data on both white and black lines.
Starts the script when the sprite is touched by another sprite.
Moves the sprite a specified number of grid squares up.
Makes the sprite disappear as if fully invisible.
Runs the script over and over forever, untill stop by Stop button (🛑).
Play’s a specified sound from the list.
This makes a image copy of the sprite on the stage.
After connection is established, rotates the quarky a specified number of step to the left.
Shows a specified emotion with animation on the quarky LED display.
Detects and counts the number of human faces present in a view captured from the camera.
Allows the sprite to follow the movement of a detected hand in real-time on specified finger.
Runs the blocks inside if a specfied state(active/inactive) of the sensors of the wizbot is detected.
After connection is established, moves the wizbot in a specified direction forever.
The block sets a text color (choose from the color selector), a particular background color (choose from the color selector) and the text size (value varying from 1 to 7) for the text.
evive has a 5-way navigation key, 4 of them are for up, down, right and left direction. This block checks if the navigation key is in one of the four particular directions. The direction for which you wish to check is your choice and can be chosen from the drop down on the block.
The block sends the written message on the terminal module of the Dabble app.
The block reports the digital state of the digital sensor, connected to the selected digital pin.
This block should be included every time you work with the humanoid robot for the first time as it calibrates the angles of all the four servo motors of the leg (2 servos of legs + 2 servos of feet) and saves the angles in the memory of evive.
The block points its sprite in the specified direction; this rotates the sprite.
The block gives its sprite a thought bubble with the specified text. The thought bubble stays until a speech or thought block with its text block empty is activated, or the stop sign is pressed.
The options for the Change () Effect by () block’s drop-down menu are pan left/right and pitch. The input is for selecting how much the sound will be changed. A positive number will make the sound effect have more effect, while a negative number will make it smaller.
The block will check its Boolean condition. If the condition is true, the blocks held inside it will run, and then the script involved will continue. If the condition is false, the code inside the block will be ignored and the script will move on (unlike in the If () Then, Else block). The condition is only checked once; if the condition turns to false while the script inside the block is running, it will keep running until it has finished.
Scripts that wear the block will activate once its sprite or clone of the sprite is clicked. Contrary to its definite name, the block will also execute the clone’s script when the clone is clicked on.
The block reports the Euclidean distance, in pixels, between it and the mouse-pointer or a specified sprite’s costume center.
The block will make an input box (with the specified text above it) show at the bottom of the screen. Scratchers can input text into it and submit it, and the input is stored then in the Answer block. The Answer block automatic updates to the most recent input.
All articles loaded
No more articles to load

Block Coding Examples

All articles loaded
No more articles to load

Python Coding Examples

All articles loaded
No more articles to load
Table of Contents