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

Controls the camera functionality, allowing users to turn the camera on or off and switch to other camera.
Starts the script whenever you press a specified button of the wizbot.
Calibrates wizbot sensors, ensuring accurate readings for line following
Switches the state of the wizbot to Grid mode.
The block takes the motor port, the direction of rotation (forward or reverse) and speed of rotation (between 0 to 100 %) as input from the user and rotates the motor accordingly.
evive has two tactile switches; this block checks if either of them is pressed. The switch whose state you want to check can be chosen from the drop-down menu on this block. It returns “true” if the switch is pressed and “false” if the switch is not pressed.
The block compares the latest string message in the terminal with the data input by the user in the block. If the data matches, it returns the true, else it returns false. 
The block reports either the temperature or humidity (selected from the dropdown menu) from DHT sensor connected to the digital pin selected from the drop-down menu.
The block is used to draw characters and symbols on evive TFT Display. The matrix size for the block is 20 horizontally and 16 vertically. 
This block defines the PWM pins to which each of the servos is connected.
This block defines the PWM pins to which all the four servos of legs(2 servos of legs + 2 servos of feet) are connected.
The blocks turn their sprite the specified amount of degrees clockwise. This changes the direction the sprite is facing.
The block gives its sprite a speech bubble with the specified text — the speech bubble stays until another speech or thought block is activated, or the stop sign is pressed.
The block will play the specified sound, with no pause to its script.
Blocks held inside this block will loop a given amount of times, before allowing the script to continue. If a decimal is put in, the number is rounded up.
Scripts placed underneath this block will activate when the specified key is pressed.
The block checks whether its sprite is touching a specified color. If it is, the block returns “true”.
The block checks if the first value is equal to the other value. If the values are equal, the block returns true; if not, false. This block is not case-sensitive.
The block will change the specified variable by a given amount.
The block enables or disables the automatic display of the box on the human pose or hand detection on the stage. This is useful when you want to see if the detection is happening or not.
The recognize () in image after () seconds block starts the camera and takes an image after the specified time and analyzes it. It then saves the image features in PictoBlox.
The function enables or disables the automatic display of the box on face detection on the stage.
This block is used to analyze the image received as input from the camera, for the handwritten and printed text.
When the block is executed, the recognition window will open and you will get a specified time during which PictoBlox will record whatever you say. Once recorded, the speech will be converted to the text of the language you spoke in and saved locally.
The block opens the recognition window and shows the machine learning analysis on the camera feed. Very good for visualization of the model in PictoBlox.
The block trains the NLP model with the data added with add () as () block.
The block enables or disables the automatic display of the box on object detection on the stage. This is useful when you want to see if the object detection happens during the analysis or not.
The block causes the text in the Text to Speech extension to be spoken using the pronunciation of the given language but does not translate the text.
The block returns the PictoBlox language of the current user. This block can be used with the translate () to () block, to translate to or from the end user’s set language.
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