Price as low as $4499 | Learn to build custom large language model applications

In this blog, we’re diving into a new approach called rank-based encoding that promises not just to shake things up but to guarantee top-notch results.

 

Rank-based encoding – a breakthrough?

 

Say hello to rank-based encoding – a technique you probably haven’t heard much about yet, but one that’s about to change the game.

 

rank-based encoding
An example illustrating rank-based encoding – Source: ResearchGate

 

In the vast world of machine learning, getting your data ready is like laying the groundwork for success. One key step in this process is encoding – a way of turning non-numeric information into something our machine models can understand. This is particularly important for categorical features – data that is not in numbers.

 

Join us as we explore the tricky parts of dealing with non-numeric features, and how rank-based encoding steps in as a unique and effective solution. Get ready for a breakthrough that could redefine your machine-learning adventures – making them not just smoother but significantly more impactful.

 

Problem under consideration

 

In our blog, we’re utilizing a dataset focused on House Price Prediction to illustrate various encoding techniques with examples. In this context, we’re treating the city categorical feature as our input, while the output feature is represented by the price.

 

Large language model bootcamp

 

Some common techniques

 

The following section will cover some of the commonly used techniques and their challenges. We will conclude by digging deeper into rank-based encoding and how it overcomes these challenges.

 

  • One-hot encoding  

 

In One-hot encoding, each category value is represented as an n-dimensional, sparse vector with zero entries except for one of the dimensions. For example, if there are three values for the categorical feature City, i.e. Chicago, Boston, Washington DC, the one-hot encoded version of the city will be as depicted in Table 1.

 

If there is a wide range of categories present in a categorical feature, one-hot encoding increases the number of columns(features) linearly which requires high computational power during the training phase.  

 

City  City Chicago  City Boston  Washington DC 
Chicago  1  0  0 
Boston  0  1  0 
Washington DC  0  0  1 

  Table 1 

 

  • Label encoding  

 

This technique assigns a label to each value of a categorical column based on alphabetical order. For example, if there are three values for the categorical feature City, i.e. Chicago, Boston, Washington DC, the label encoded version will be as depicted in Table 2.

 

Since B comes first in alphabetical order, this technique assigns Boston the label 0, which leads to meaningless learning of parameters.  

 

City  City Label Encoding 
Chicago  1 
Boston  0 
Washington DC  2 

Table 2 

 

  • Binary encoding  

 

It involves converting each category into a binary code and then splitting the resulting binary string into columns. For example, if there are three values for the categorical feature City, i.e. Chicago, Boston, Washington DC, the binary encoded version of a city can be observed from Table 3.

 

Since there are 3 cities, two bits would be enough to uniquely represent each category. Therefore, two columns will be constructed which increases dimensions. However, this is not meaningful learning as we are assigning more weightage to one category than others.

 

Chicago is assigned 00, so our model would give it less weightage during the learning phase. If any categorical column has a wide range of unique values, this technique requires a large amount of computational power, as an increase in the number of bits results in an increase in the number of dimensions (features) significantly. 

 

City  City 0  City 1 
Chicago  0  0 
Boston  0  1 
Washington DC  1  0 

  Table 3 

 

  • Hash encoding  

 

It uses the hashing function to convert category data into numerical values. Using hashed functions solves the problem of a high number of columns if the categorical feature has a large number of categories. We can define how many numerical columns we want to encode our feature into.

 

However, in the case of high cardinality of a categorical feature, while mapping it into a lower number of numerical columns, loss of information is inevitable. If we use a hash function with one-to-one mapping, the result would be the same as one-hot encoding. 

 

  • Rank-based Encoding: 

 

In this blog, we propose rank-based encoding which aims to encode the data in a meaningful manner with no increase in dimensions. Thus, eliminating the increased computational complexity of the algorithm as well as preserving all the information of the feature.

 

Rank-based encoding works by computing the average of the target variable against each category of the feature under consideration. This average is then sorted in decreasing order from high to low and each category is assigned a rank based on the corresponding average of a target variable. An example is illustrated in Table 4 which is explained below:

 

The average price of Washington DC = (60 + 55)/2 = 57.5 Million 

The average price of Boston = (20 +12+18)/3 = 16.666 Million 

The average price of Chicago = (40 + 35)/2 = 37.5 Million

 

In the rank-based encoding process, each average value is assigned a rank in descending order.

 

For instance, Washington DC is given rank 1, Chicago gets rank 2, and Boston is assigned rank 3. This technique significantly enhances the correlation between the city (input feature) and price variable (output feature), ensuring more efficient model learning.

 

Learn to build LLM applications

 

In my evaluation, I assessed model metrics such as R2 and RMSE. The results demonstrated significantly lower values compared to other techniques discussed earlier, affirming the effectiveness of this approach in improving overall model performance. 

 

City  Price  City Rank 
Washington DC  60 Million  1 
Boston  20 Million  3 
Chicago  40 Million  2 
Chicago  35 Million  2 
Boston  12 Million  3 
Washington DC  55 Million  1 
Boston  18 Million  3 

Table 4 

 

Results

 

We summarize the pros and cons of each technique in Table 5. Rank-based encoding emerges to be the best in all aspects. Effective data preprocessing is crucial for the optimal performance of machine learning models. Among the various techniques, rank-based encoding is a powerful method that contributes to enhanced model learning.

 

Rank-based encoding technique facilitates a stronger correlation between input and output variables, leading to improved model performance. The positive impact is evident when evaluating the model using metrics like RMSE and R2 etc. In our case, these enhancements reflect a notable boost in overall model performance. 

 

Encoding Technique  Meaningful Learning  Loss of Information  Increase in Dimensionality 
One-hot x 
Label x  x 
Binary x  x 
Hash x 
Rank-based x  x 

Table 5 

What is web scraping?

Web scraping is the act of extracting the content and data from a website. The vast amount of data available on the internet is not open and available to download. As a result, ethical web scraping is the most effective technique to collect this data. There is also a debate about the legality of web scraping as the content may get stolen or the website can crash as a result of web scraping.

Ethical Web Scraping is the act of harvesting data legally by following ethical rules about web scraping. There are certain rules in ethical web scraping that when followed ensure trust between the website owner and web scraper.

Web scraping using Python

In Python, a learner can write a small piece of code to do large tasks. Since web scraping is used to save time, a small code written in Python can save a lot of time. Also, Python is simple and easy to understand and provides an extensive set of libraries for web scraping and further manipulation required on extracted data.

PRO TIP: Join our 5-day instructor-led Python for Data Science training to enhance your web scraping skills.

Challenges for individuals

Individuals who are new to web scraping and wish to flourish in their field usually lack the necessary computing and learning resources to obtain hands-on expertise. Also, they may face compatibility issues when installing libraries.

What we provide

With just a single click, Jupyter Hub for Ethical Web Scraping using Python comes with pre-installed Web Scraping python libraries, which gives the learner an effortless coding environment in the Azure cloud and reduces the burden of installation. Moreover, this offer provides the learner with a repository of the famous book on web scraping which contains chapter-wise notebooks which serve as a learning resource for a user in gaining hands-on experience with web scraping.

Through this offer, a learner can collect data from various sources legally by following the best practices for ethical web scraping mentioned in the latter section of this blog. Once the data is collected, it can be further analyzed to get valuable insights into almost everything while all the heavy computations are performed on Microsoft Azure hence saving the user from the trouble of running high computations on the local machine.

Python libraries:

Listed below are the pre-installed web scraping python libraries and the sources of repositories of web scraping book provided by this offer:

  •          Pandas
  •          NumPy
  •          Scikit-learn
  •          Beautifulsoup4
  •          lxml
  •          MechanicalSoup
  •          Requests
  •          Scrapy
  •          Selenium
  •          urllib

Repository:

  •          GitHub repository of book Web Scraping with Python 2nd Edition,
    by author Ryan Mitchell.

Best practices for ethical web scraping

Globally, there is a debate about whether web scraping is an ethical concept or not. The reason it is unethical is that when a website is queried repeatedly by the same user (in this case bot), too many requests land on the server simultaneously and all resources of the server may be consumed in generating responses for each request, preventing it from responding to other legitimate users.

In this way, the server denies responses to any further users, commonly known as a Denial of Service (DoS) attack.

Below are the best practices for ethical web scraping, and compliance with these will allow a web scraper to work ethically.

1.   Check out for ROBOTS.TXT

Robots.txt file, also known as the Robots Exclusion Standard, is used to inform the web scrapers if the website can be crawled or not, if yes then how to index the website. A legitimate web scraper is expected to respect the instructions in this file and not disobey the website owner’s allowed instructions.

2.   Check for website APIs

An ethical web scraper is expected to first look for the public API of the website in question instead of scraping it all together. Many website owners provide public API access which can be used by anyone looking to gain from the information available on the website. Provision of public API works in the best interests of both the ethical scrapper as well as the website owner, avoiding web scraping altogether.

3.   Avoid repeated requests

Vigorous scraping can occasionally cause functionality issues, resulting in a poor user experience for humans. As a result, it is always advised to scrape during off-peak hours. An ethical web scraper is expected to delay recurrent requests to avoid a DoS attack.

4.   Provide your identity

It is always a good idea to take responsibility for one’s actions. An ethical web scraper never hides his or her identity and provides it in a user-agent string. Not only does this make the intentions of the scraper clear but also provides a means of contact for any questions or concerns of the website owner.

5.   Avoid fake ownership

The content scraped through web scraper should always be respected and never passed on under the fake information of scraper as the author. This act can be regarded as highly unethical as well as illegal since the website owner may file a copyright claim. It also damages the reputation of genuine web scrapers and hurts the trust of the website owner.

6.  Ask for permission

Since the website information belongs to the owner, one should never presume it to be free and ask politely to use it for their means. An ethical web scraper always seeks permission from the website owner to avoid any future problems. The website owner should be given the choice of whether she agrees to scrape the data.

 7.  Give due credit

To encourage the website owner as a token of thanks, the web scraper should give due credit wherever possible. This can be done in many ways such as providing a link to the original website on any blog, article, or social media post by generating traffic for the original website.

Ethical web scraping

Conclusion

Ethical web scraping is a two-way street in which the website owner should be mindful of the global availability of the data, similarly, the scraper should not harm the website in any way and also first seek permission from the website owner. If a web scraper abides by the above-mentioned practices, I.e., he/she works ethically, the web owner may not only allow scraping his or her website but also provide helpful means to the scraper in the form of Meta data or a public API.

At Data Science Dojo, we deliver data science education, consulting, and technical services to increase the power of data. We are therefore adding a free Jupyter Notebook Environment dedicated specifically for Ethical Web Scraping using Python. Install the Jupyter Hub offer now from the Azure Marketplace by Data Science Dojo, your ideal companion in your journey to learn data science!

Try now - CTA

Data Science Dojo has launched a RabbitMQ offering to the Azure Marketplace with pre-configured settings which helps the user to take deep dive into RabbitMQ with just a single click.

What is message queuing?

A message queue is a system that allows a sender and recipient process to communicate with one another asynchronously.

Key terminologies for RabbitMQ

  1. Publisher: A Publisher is a sender who sends a message first.
  2. Consumer: A consumer is attached at the end of the queue and consumes a published message.
  3. Exchange: When a publisher sends a message to the broker, the exchange accepts it and passes it to the proper queue.
  4. Queue: A queue is a channel for transferring and storing messages or buffers.
  5. Binding Key: A binding key is a key through which an Exchange is bound with a queue.
  6. Routing Key: Whenever a publisher publishes a message, it also specifies a routing key along with a message.

Challenges for individuals

If a publisher publishes a message directly to the consumer, there is a high chance of messages getting lost to a consumer as there might be a scenario in which the receiver is not available or running up.

What we provide

RabbitMQ is the most widely deployed, cross-platform, lightweight open source message broker that implements different messaging protocols including Advanced Message Queuing Protocol(AMQP). The biggest advantage of RabbitMQ is that published messages are never lost as they always reside in a safe place until they are received by the consumer. This safe place acts as an intermediary agent and is referred to as “Queues” in RabbitMQ. Through this offer, a learner can fire and forget about who will process the published message and when.

Working of RabbitMQ

When a message is published by a publisher, it first gets received by an exchange. The exchange then forwards the message to the queue based on the exchange type. RabbitMQ includes four important exchange types that cover the majority of messaging scenarios:

  1. Fan-out Exchange: This exchange broadcasts the message to all of the queues attached to the exchange.
  2. Direct Exchange: The message is forwarded only to the queue by an exchange whose Binding key exactly matches the Routing key specified by the publisher.
  3. Topic Exchange: The topic exchange allows the forwarding of messages based on partial matching of Binding and Routing keys.
  4. Header Exchange: This exchange takes advantage of the structure of AMQP messages and may do complex routing based on the AMQP message’s headers (including custom ones). Each message sent via AMQP has metadata attached to it called headers.
RabbitMQ Workflow
RabbitMQ Workflow

Use case of RabbitMQ

RabbitMQ Use case
Use case of RabbitMQ

Let us look at a use case of RabbitMQ in an online banking application. In the modern era, large-scale applications are built using microservice architecture in which each microservice is responsible for its task. Let us suppose in the given use case we have two microservices ‘Email service’ and ‘SMS service’. As soon as a user makes a transaction, he or she must be notified via email and SMS service. In technical jargon, a publisher publishes a message to the exchange along with the routing key ‘email’. In this scenario, we assume the exchange type as a direct exchange. The exchange then compares this routing key against the binding key of each queue. Based on the matching of keys, the message will be forwarded to the Email notification queue. The Email microservice then consumes the message from the Email notification queue and performs its task i.e., it will send a notification to the customer’s email address about the successful transaction. If for any reason, the server is down on which the email service is deployed or the service is not working for any reason, the published message is retained in the email notification queue and is not lost. When the email service starts working again, the message is consumed and the customer is notified via the email service.

Key features of RabbitMQ

Our solution provides RabbitMQ combined with the power of Azure services to enable web servers to quickly respond to requests rather than resource-heavy procedures on spot. Features included in this offer:

  • Multiple message protocols are supported through Asynchronous messaging. 
  • Provides messaging across different programming languages.
  • To achieve increased throughput and high availability, they can be deployed as clusters. Federate across multiple availability zones and regions.
  • RabbitMQ also provides TLS and LDAP authentication.
  • Continuous integration, operational metrics, and integration to other enterprise systems can be achieved through different tools & plugins in RabbitMQ.
  • Monitor every aspect of messaging through an interactive UI.

Conclusion

RabbitMQ messaging enables software applications to connect and communicate asynchronously which ensures that the message is received by the intended recipient and never lost. The offering leverages the power of Microsoft Azure services to run effortlessly with outstanding responsiveness. RabbitMQ offered by Data Science Dojo is ideal to start working with RabbitMQ without the need to worry about configurations and computing resources.

Install the RabbitMQ offer now from the Azure Marketplace by Data Science Dojo, your ideal companion in your journey to learn data science!

Try RabbitMQ!

Data Science Dojo has launched Jupyter Hub for Machine Learning using Python offering to the Azure Marketplace with pre-installed machine learning libraries and pre-cloned GitHub repositories of famous machine learning books which help the learner to take the first steps into the field of machine learning.

What is machine learning?

Machine learning is a sub-field of Artificial Intelligence. It is an innovative technology that allows machines to learn from historical data and provide the best results to predict outcomes.

Machine learning using Python

Machine learning requires exploratory data analysis, data processing, and the training of data to predict outcomes. Python provides a vast number of libraries and frameworks that let the user collect, analyze and transform data by just using built-in functions provided by the library which makes coding easy and also saves a significant amount of time.

machine learning python
Machine learning using Python

 PRO TIP: Join our 5-day instructor-led Python for Data Science training to enhance your machine learning skills.

Challenges for individuals

Individuals who are new to machine learning and want to excel in their path in machine learning usually lack computing as well as learning resources to gain hands-on experience with machine learning. A beginner in machine learning also faces compatibility issues while installing libraries.

What we provide

With just a single click, Jupyter Hub for Machine Learning using Python comes with pre-installed machine learning python libraries, which gives the learner an effortless coding environment in the Azure cloud and reduces the burden of installation. Moreover, this offer provides the learner with repositories of famous books on machine learning which contain chapter-wise notebooks which serve as a learning resource for a user in gaining hands-on experience with machine learning. The heavy computations required for Machine Learning applications are not performed on the user’s local machine. Instead, they are performed in the Azure cloud, which increases responsiveness and processing speed.

Listed below are the pre-installed machine learning python libraries and the sources of repositories of machine learning books provided by this offer:

Python libraries

  • Pandas
  • NumPy
  • scikit-learn
  • mlpack
  • matplotlib
  • SciPy
  • Theano
  • Pycaret
  • Orange3
  • seaborn

Repositories

  •  Github repository of book ‘Python Machine Learning Book 1st Edition’, by author Sebastian Raschka.
  •  Github repository of book ‘Python Machine Learning Book 2nd Edition’, by author Sebastian Raschka.
  •  Github repository of the book ‘Hands-on Machine Learning with Scikit Learn, Keras, and TensorFlow’, by author Geron-Aurelien.
  •  Github repository of ‘Microsoft Azure Cloud Advocates 12-week Machine Learning curriculum’.

Conclusion

Jupyter Hub for Machine Learning using Python provides an in-browser coding environment with just a single click, hence providing ease of installation. Through this offer, a user can work on a variety of machine learning applications including stock market trading, email spam and malware filtering, product recommendations, online customer support, medical diagnosis, online fraud detection, and image recognition.

Jupyter Hub for Machine Learning using Python offered by Data Science Dojo is ideal to learn more about machine learning without the need to worry about configurations and computing resources. The heavy resource requirement for processing and training large data for these applications is no longer an issue as data-intensive computations are now performed on Microsoft Azure which increases processing speed.

At Data Science Dojo, we deliver data science education, consulting, and technical services to increase the power of data. We are therefore adding a free Jupyter Notebook Environment dedicated specifically for Machine Learning using Python. The offering leverages the power of Microsoft Azure services to run effortlessly with outstanding responsiveness. Install the Jupyter Hub offer now from the Azure Marketplace by Data Science Dojo, your ideal companion in your journey to learn data science!

Try Now!