Decision Tree Classifier Python Code Example

In this post, you will learn about how to train a decision tree classifier machine learning model using Python. The following points will be covered in this post:

  • What is decision tree?
  • Decision tree python code sample

What Is a Decision Tree?

Simply speaking, the decision tree algorithm breaks the data points into decision nodes resulting in a tree structure. The decision nodes represent the question based on which the data is split further into two or more child nodes. The tree is created until the data points at a specific child node is pure (all data belongs to one class). The criteria for creating the most optimal decision questions is the information gain. The diagram below represents a sample decision tree.

How IoT Data Can Help Accelerate Digital Transformation

Every business is dreaming about how digital transformation will push productivity and profits to the max. The buzzword (or rather the phrase) of the last couple of years is known for “driving efficiencies and innovation”. It is the famous digital transformation that will replace the useless manual processes, enhance the company’s productivity, and spare time for the human flight of fancy to search for new strategies and creative approaches. Digital perfection will remove human errors making the business and production processes run smoother.

The utopian idea of digital transformation continues to flourish all over the net, making digital transformation consulting even harder than ever. Why harder? Because consultants have to crash the rose-tinted glasses and “reveal” that chaotic and unreasonable investments in digitalization are time-consuming, expensive, and hence useless.

PostgreSQL Performance Metrics

We can get the best performance out of their PostgreSQL database by tracking key performance metrics. Keeping these metrics on your dashboard will help. Ignoring these problems could result in a plunge in the productivity of Postgresql. Here I want to explain how to monitor PostgreSQL, I added in details what exactly you should be looking at when monitoring the performance of your database. There are several key metrics you'll definitely want to keep track of when it comes to database performance

Database Connection Parameters

A PostgreSQL database server can have multiple active connections running concurrently in the database. If the number of connections is high, you may need to analyze the state of these user sessions, and terminate idle sessions that are slowing down the server.

Machine Learning Algorithms: Mathematics Behind Linear Regression

There are several machine learning algorithms that can provide the desired outputs by processing the input data. One of the widely used algorithms is linear regression.

Linear regression is a type of supervised learning algorithm where the output is in a continuous range and isn’t classified into categories. Through a linear regression machine learning algorithm, we can predict values with a constant slope.

Change Data Capture Architecture Using Debezium, Postgres, and Kafka

Change Data Capture (CDC) is a technique used to track row-level changes in database tables in response to create, update and delete operations. Different databases use different techniques to expose these change data events - for example, logical decoding in PostgreSQL, MySQL binary log (binlog) etc. This is a powerful capability, but useful only if there is a way to tap into these event logs and make it available to other services which depend on that information.

Debezium does just that! It is a distributed platform that builds on top of Change Data Capture features available in different databases. It provides a set of Kafka Connect connectors which tap into row-level changes (using CDC) in database table(s) and convert them into event streams. These event streams are sent to Apache Kafka which is a scalable event streaming platform - a perfect fit! Once the change log events are in Kafka, they will be available to all the downstream applications.

Shipper, Now Much Less Sh**ter (1.1.5)

When we first set out to build a migration plugin, we reached for the stars. We probably shouldn’t have.

We didn’t want to build your regular ‘zip this up and transfer it across’ plugin that failed on most shared hosts or any sort of decent sized site.

And we wanted 100% success rates. Something brand new. File by file. Heck yeah!

Which was a great idea, and a lofty concept that was going to change the WordPress World. Until it wasn’t.

Because while Shipper was extraordinarily thorough and reliable, it, well, tended to take a medium size site at the very least a few hours… and a large site, let’s say, the better part of a week to migrate.

And it turns out while users really really would like stable and successful migrations, they generally would like them done within the calendar month. Fancy that!

But that’s cool… because we figured let’s put all we’ve learned into an absolutely excellent ‘package’ (yep, zipping it up) migration that isn’t crap.

And we did! The only problem was we kinda forgot to, erm, change the design to let you know!

So, while it’s been great for ages… it’s been hard to see this in action.

Which you didn’t hesitate to point out at length in the recent 2020 survey.

“I want it to work but it doesn’t!”

“Shipper always fails”

“2 AND A HALF DAYS???!!!”

“But we’ve fixed him” we cried, “he works beautifully now” we plaintively wailed into the ether.

As of Shipper’s latest release (1.1.5) his interface has been completely revamped.

His migration capabilities are now fully on display, and he’s also added another important security feature that was highly requested.

So without further ado…

Presenting: Shipper’s Extreme [Plugin] Makeover.

Shipper looking rather nervous about his extreme plugin makeover
Shipper won’t know himself after this extreme plugin makeover.

Check out Shipper’s new look below and let us know if it floats your boat.

Here’s a quick breakdown of some of the notable UI and UX changes:

1.Shipper no longer looks like he has a bad case of sea sickness.

This wasn’t an issue that affected everyone, but we had reports that some users were still seeing the old Shipper character design.

Now while we love him, I’m pretty sure even Shipper himself would have to admit he isn’t looking his best in the frame below.

Before:

Shipper was looking rather seasick before his new updated look
Shipper moves so many sites, no wonder he was suffering from motion sickness.

Safe to say he’s looking a lot happier now. :)

After:

After his update, Shipper is looking a lot happier
Shipper feeling brand new.

2.He’s got a new dashboard that allows easy access and explains both forms of migration.

In the past Shipper had been quite forthcoming with new users.

Encouraging them to jump head first into a site migration without explaining much about the process first.

Before:

A look at Shipper's dash before the new update
Shipper certainly wasn’t messing around before. Jumping straight into a migration many might not be ready for.

There were a couple of problems with this:

  1. Users were pretty much thrown into thinking an API migration was their only option, unless they happened to be paying close attention to the WP dashboard sidebar.
  2. Users were given little to no context as to what was involved in both of Shipper’s migration options and what to expect.

As the “After” screenshot below shows, you no longer have worry about these things, as our chuffed captain has been equipped with a slick new dashboard.

Including an overview of previous migrations, as well as details about both forms of migration, and what’s involved with each process. Scroll down further and you can also directly access more helpful Shipper settings and tools.

After:

A look at Shipper's new and improved WordPress dashboard
Everything you need to know about the migration process on one central dashboard.

3. Shipper now offers up some helpful hints before continuing with your migration.

Although previous versions of Shipper did run pre-flight checks, the newly upgraded UI takes things a step further.

Before you proceed with your migration, Shipper will point out some possible issues and point out solutions
API migration looking like it’s going to take too long? Try a Package Migration!

Along with alerting you of any destination server issues, Shipper now also offers up some handy tips to help speed up your migration process.

This includes letting users know they have the option of a Package Migration, which might otherwise have been overlooked in the past.

4. ETA’s and calculated website sizes are now more accurate.

Another issue with the migration process in the past has been the clarity of package sizes and ETAs.

Mostly because in many cases ETA’s simply weren’t accurate, and migrations were a lot quicker than displayed. But sadly the described time frames ended up deterring most users.

Before:

An old look at the Shipper migration screen
Migrations actually took a lot less time than actually stated!

In Shipper’s new “Migration in progress” modal you can see that the ETA and package size are clearly stated, and have been upgraded to be more accurate.

After:

A look at the brand new and improved Shipper migration in progress screen
Setting clear and accurate expectations like a true captain.

Bonus Feature: Protect your connected sites from hackers with password confirmation.

For increased security, Shipper now asks for a password confirmation before you continue with your migration
Password confirmation helps to protect your connected sites from hackers.

Along with Shipper’s new extreme plugin-makeover, he’s also received an important new security update.

When running an API migration, Shipper automatically gives you access to all of the sites you have connected to The Hub.

Normally this wouldn’t be an issue, however, if one of your sites were to get hacked, the hacker would in-turn have access to your other connected sites, and could wreak havoc by running migrations and breaking them.

To help prevent this, Shipper now asks for your WPMU DEV password before fetching the connected sites in the API migration.

This acts as a second level of security, so even if someone were to gain access to one of your sites, they’ll still need your WPMU DEV password to begin a migration.

So, what do you think of Shipper’s new makeover?

The truth is, Shipper’s been a new [sea] man for a while now.

It just took a quick cut and polish to reveal what our migration master could really do underneath all the boat rust.

If you do like the look of Shipper’s new style and time-saving migration features, we invite you to hop aboard. Just keep in mind Shipper is one of our premium-only plugins.

If you’re already a member be sure to check out his new looks for yourself… If you’re NOT a member, you’ll have to become one to join the migration party…

The good news is, there’s never been a better time to take a WPMU DEV membership for a free 7-day trial.

Because along with Shipper Pro… you also get access to all of our other premium plugins, our world-beating WP hosting, our ultimate website management platform The Hub, 24/7 expert support, and a whole community of like-minded WP buffs.

Just let us know when you’re ready to set sail.

A Bit on Web Component Libraries

A run of Web Components news crossed my desk recently so I thought I’d group it up here.

To my mind, one of the best use cases for Web Components is pattern libraries. Instead of doing, say, <ul class="nav nav-tabs"> like you would do in Bootstrap or <div class="tabs"> like you would in Bulma, you would use a custom element, like <designsystem-tabs>.

The new Shoelace library uses the sl namespace for their components. It’s a whole pattern library entirely in Web Components. So the tabs there are <sl-tab-group> elements.

Why is that good? Well, for one thing, it brings a component model to the party. That means, if you’re working on a component, it has a template and a stylesheet that are co-located. Peeking under the hood of Shoelace, you can see this is all based on Stencil.

Another reason it’s good is that it means components can (and they do) use the Shadow DOM. This offers a form of isolation that comes right from the web platform. For CSS folks like us, that means the styling for a tab in the tab component is done with a .tab class (hey, wow, cool) but it is isolated in that component. Even with that generic of a name, I can’t accidentally mess with some other component on the page that uses that generic class, nor is some other outside CSS going to mess with the guts here. The Shadow DOM is a sort of wall of safety that prevents styles from leaking out or seeping in.

I just saw the FAST framework¹ too, which is also a set of components. It has tabs that are defined as <fast-tabs>. That reminds me of another thing I like about the Web Components as a pattern library approach: if feels like it’s API-driven, even starting with the name of the component itself, which is literally what you use in the HTML. The attributes on that element can be entirely made up. It seems the emerging standard is that you don’t even have to data-* prefix the attributes that you also make up to control the component. So, if I were to make a tabs component, it might be <chris-tabs active-tab="lunch" variation="rounded">.

Perhaps the biggest player using Web Components for a pattern library is Ionic. Their tabs are <ion-tabs>, and you can use them without involving any other framework (although they do support Angular, React, and Vue in addition to their own Stencil). Ionic has made lots of strides with this Web Components stuff, most recently supporting Shadow Parts. Here’s Brandy Carney explaining the encapsulation again:

Shadow DOM is useful for preventing styles from leaking out of components and unintentionally applying to other elements. For example, we assign a .button class to our ion-button component. If an Ionic Framework user were to set the class .button on one of their own elements, it would inherit the Ionic button styles in past versions of the framework. Since ion-button is now a Shadow Web Component, this is no longer a problem.

However, due to this encapsulation, styles aren’t able to bleed into inner elements of a Shadow component either. This means that if a Shadow component renders elements inside of its shadow tree, a user isn’t able to target the inner element with their CSS.

The encapsulation is a good thing, but indeed it does make styling “harder” (on purpose). There is an important CSS concept to know: CSS custom properties penetrate the Shadow DOM. However, it was decided — and I think rightly so — that “variablizing” every single thing in a design system is not a smart way forward. Instead, they give each bit of HTML inside the Shadow DOM a part, like <div part="icon">, which then gives us the ability to “reach in from the outside” with CSS, like custom-component::part(icon) { }.

I think part-based styling hooks are mostly fine, and a smart way forward for pattern libraries like this, but I admit some part of it bugs me. The selectors don’t work how you’d expect. For example, you can’t conditionally select things. You also can’t select children or use the cascade. In other words, it’s just one-off, or like you’re reaching straight through a membrane with your hand. You can reach forward and either grab the thing or not, but you can’t do anything else at all.

Speaking of things that bug people, Andrea Giammarchi has a good point about the recent state of Web Components:

Every single library getting started, including mine, suggest we should import the library in order to define what [sic] supposed to be a “portable Custom Element”.

Google always suggests LitElement. Microsoft wants you to use FASTElement. Stencil has their own Component. hyperHTML has their own Component. Nobody is just using “raw” Web Components. It’s weird! What strikes me as the worst part about that is that Web Components are supposed to be this “native platform” thing meaning that we shouldn’t need to buy into some particular technology in order to use them. When we do, we’re just as locked to that as we would be if we just used React or whatever.

Andrea has some ideas in that article, including the use of some new and smaller library. I think what I’d like to see is a pattern library that just doesn’t use any library at all.

  1. FAST calls itself a “interface system,” then a “UI framework” in consecutive sentences on the homepage. Shoelaces calls itself a “library” but I’m calling it a “pattern library.” I find “design system” to be the most commonly used term to describe the concept, but often used more broadly than a specific technology. FAST uses that term in the code itself for the wrapper element that controls the theme. I’d say the terminology around all this stuff is far from settled.

The post A Bit on Web Component Libraries appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

Calculating Application Availability in the Cloud

When deploying business-critical applications in the cloud you want to make sure they are highly available. The good news is that if you plan properly, you can achieve 99.99% (4-nines) of availability or more. However, calculating your true availability may not be as straightforward as it seems.

When considering availability you must consider the key components that make access to your application possible, which I'll call the availability chain. Component of the availability chain are:

Gutenberg 8.6 Adds Cover Block Video Positioning and Updates Block Patterns

Gutenberg 8.6 landed quietly last week. Much of the focus right now is ironing out the remaining bugs for WordPress 5.5 during its beta cycle. However, that does not mean the Gutenberg project has come to a complete halt in terms of new features. The team is marching forward with extra goodies for those who use the plugin.

The latest update of the plugin did not cover as much ground as normal, but it does include an enhancement for the Cover block when using a video background and several updates to block patterns.

The primary focus for version 8.6 was squashing bugs. The development team addressed over three dozen of them while correcting a handful of performance issues. While new features and enhancements from 8.6 onward are not expected in the upcoming WordPress 5.5, most bug fixes should be included.

Focal Point Selector for Video Covers

Using the focal point picker with a video background for the Cover block.
Selecting a focal point for a video background.

The Cover block has long allowed users to pick a focal point for background images. However, this feature was missing when users added a background video to the block. As of version 8.6, that is no longer the case. Both image and video backgrounds should work in much the same way.

Gutenberg now has a new “Focal point picker” option located under the “Media settings” tab when adding a video background. Users can select the focal point by dragging the circle icon in the video box or hardcode left and top percentage values in the input fields below it.

This is not a particularly exciting development for most Gutenberg users. Self-hosting video is not cheap and remains unused for most. However, for those who do use video backgrounds, it is one of those nice-to-have features that is there when needed.

Updated Block Patterns

Inserting the Quote block pattern into the editor.
Inserting the updated quote block pattern.

The Gutenberg team updated several of the existing block patterns. For the most part, the pattern updates were minor cosmetic changes, tweaks that improve the overall design. The button-related patterns received simple changes, such as new text labels and colors. The developers also changed the colors and text of the large header patterns.

The team moved the header above the columns in the two columns text pattern and changed the text to make the columns appear equal height by default. It is a poor use of textual columns, which would ideally be handled with CSS instead so that it works appropriately across screen sizes. Perhaps it would be better to have a “Text Columns” block in the long run.

The nicest block pattern update was for the quote pattern. It now has an image at the top and a separator at the bottom. It is akin to a single testimonial, which is more of a pattern than a basic quote.

Theme authors can also remove support for the core block patterns with a single line of code: remove_theme_support( 'core-block-patterns' ). This does not drop support for patterns altogether. For example, patterns added by plugins or the theme will still appear in the inserter.

Site Icon Used in Fullscreen Mode

Testing the site icon button with fullscreen editing mode.
Site icon appears in top left in fullscreen mode.

When writing in fullscreen mode, the “back to posts” link has utilized the WordPress logo in the past. In version 8.6, the user’s custom site icon will take its place. However, this will only happen if the user has uploaded an icon via the customizer.

I am unsure how I feel about this change. In practice, it almost feels like clicking the icon should take me to the front end of the site instead of the post management screen. At least with the WordPress icon, it felt like it was pointing toward an admin-side screen instead. For my workflow, I would rather see this link/icon replaced with a button that toggles between fullscreen and normal mode, popping the admin menu back into place rather than departing the editing screen altogether.

Database Architectures and Use Cases – Explained

With over 300 databases on the market, how do you determine which is right for your specific use case or skill set?

We continue to see the common debate of SQL vs. NoSQL and other database comparisons all over social media and platforms like dev.to. In most cases, it’s not that one database is better than the other, it’s that one is a better fit for a specific use case due to numerous factors.

Analysis of Merge Requests in GitLab Using PVS-Studio For C#

Do you like GitLab and don't like bugs? Do you want to improve the quality of your source code? Then you've come to the right place. Today we will tell you how to configure the PVS-Studio C# analyzer for checking merge requests. Enjoy the reading and have a nice unicorn mood.

PVS-Studio is a tool designed to detect errors and potential vulnerabilities in the source code of programs, written in C, C++, C#, and Java. Works in 64-bit systems on Windows, Linux, and macOS. Can analyze the code meant for 32-bit, 64-bit, and embedded ARM platforms.

Kotlin Wiremock

WireMock is a popular library for stubbing web services. It runs an HTTP server that acts as an actual web service. We just set up expectations and run the server.

In this tutorial, we will present the kotlin-wiremock library that provides a nice domain-specific language for stubbing WireMock expectations.

Jenkins Pipeline Groovy Script – Part 1: Creating Gitlab Group

In this article, I am discussing a simple groovy functionality along with Jenkinsfile pipeline script on how to automatically create a new GitLab group or subgroup under the parent group.  In DevOps Continuous Integration(CI) and Continuous Delivery(CD), managing projects in git level is very much important and useful for version control.  These projects are organized under a specific groups to have a disciplined structure in order to handle the application deployment well via DevOps.

What Is Jenkins Groovy?

Groovy is  an object-oriented programming language like Java and has Domain Specific Language(DSL) features. Jenkins provides pipeline capabilities along with groovy DSL features for Continuous Integration(CI). So how to use Jenkins pipeline groovy script, use load keyword in Jenkinsfile to create constructor for groovy class. Using constructor or class object of that Groovy class, functions can be inherited and values are returned. In order to use Jenkins Pipeling Groovy script, in Jenkins CI server Pipeline Groovy Plugin should be installed as prerequisite.