concept database in category machine learning

appears as: database, database, databases, The database, A database, databases
Machine Learning Systems: Designs that scale

This is an excerpt from Manning's book Machine Learning Systems: Designs that scale.

In this version of Pooch Predictor, the scripts were run on a nightly basis, scheduled by cron. They still dumped their intermediate results to files, but now they needed to insert their models into the application’s database. And now the backend server was responsible for producing the predictions displayed in the app. It would pull the model out of the database and use it to provide predictions to the app’s users.

This new system was definitely better than the initial version, but in its first several months of operation, the team discovered several pain points with it. First of all, Pooch Predictor wasn’t very reliable. Often something would change in the database, and one of the queries would fail. Other times there would be high load on the server, and the modeling job would fail. This was happening more and more as both the size of the social network and the size of the dataset used by the modeling system increased. One time, the server that was supposed to be running the data-processing job failed, and all the relevant data was lost. These sorts of failures were hard to detect without building up a more sophisticated monitoring and alerting infrastructure. But even if someone did detect a failure in the system, there wasn’t much that could be done other than kick off the job again and hope it succeeded this time.

Listing 2.7. An unreliable database
class DatabaseConnection(url: String) { #1 var votes = new mutable.HashMap[String, Any]() #2 def insert(updateMap: Map[String, Any]) = { if (Random.nextBoolean()) throw new Exception #3 updateMap.foreach { case (key, value) => votes.update(key, value) #4 } } } #1 A simple object used to represent a database #2 A hash map to hold the votes #3 This will throw an exception half the time. #4 A pattern-matching expression is used to destructure the map entry into a key and a value. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":59},{\"line\":0,\"ch\":61}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":2}],[{\"line\":1,\"ch\":59},{\"line\":1,\"ch\":61}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":2}],[{\"line\":4,\"ch\":59},{\"line\":4,\"ch\":61}],[{\"line\":14,\"ch\":0},{\"line\":14,\"ch\":2}],[{\"line\":7,\"ch\":59},{\"line\":7,\"ch\":61}],[{\"line\":15,\"ch\":0},{\"line\":15,\"ch\":2}]]"} !@%STYLE%@!

For many applications, this partial view of the database would be entirely usable. After all, the facts recorded don’t reflect a current certainty that a definite number of zebras are present at Location 55. You could even use a linear model to interpolate the missing value if you wanted to. The trend is the same, and the overall picture provided by a query over readings would present a similar view. The actions you would choose to take upon seeing this incomplete data are likely the same that you would take upon seeing the full dataset: you would send out some lionesses to go get you some lunch with stripes on it. By using a fact-based data model with explicit uncertainty, you’ve already built the ability to handle incomplete views of data into your usage of the database.

There are even more properties of this system that are worth highlighting. A database’s internal concurrency models are its plan for how to coordinate multiple users. Couchbase uses a concurrency model called multiversion concurrency control (MVCC). Systems that use MVCC don’t internally lock records for mutation but instead replicate data.

Introducing Data Science: Big data, machine learning, and more, using Python tools

This is an excerpt from Manning's book Introducing Data Science: Big data, machine learning, and more, using Python tools.

If you need to store huge amounts of data, you require software that’s specialized in managing and querying this data. Traditionally this has been the playing field of relational databases such as Oracle SQL, MySQL, Sybase IQ, and others. While they’re still the go-to technology for many use cases, new types of databases have emerged under the grouping of NoSQL databases.

We start this chapter with an overview of the problems you face when handling large data sets. Then we offer three types of solutions to overcome these problems: adapt your algorithms, choose the right data structures, and pick the right tools. Data scientists aren’t the only ones who have to deal with large data volumes, so you can apply general best practices to tackle the large data problem. Finally, we apply this knowledge to two case studies. The first case shows you how to detect malicious URLs, and the second case demonstrates how to build a recommender engine inside a database.

First let’s connect Python to MySQL to create our data. Make a connection to MySQL using your username and password. In the following listing we used a database called “test”. Replace the user, password, and database name with the appropriate values for your setup and retrieve the connection and the cursor. A database cursor is a control structure that remembers where you are currently in the database.

Listing 4.8. Creating customers in the database

4.5. Case study 2: Building a recommender system inside a database

In reality most of the data you work with is stored in a relational database, but most databases aren’t suitable for data mining. But as shown in this example, it’s possible to adapt our techniques so you can do a large part of the analysis inside the database itself, thereby profiting from the database’s query optimizer, which will optimize the code for you. In this example we’ll go into how to use the hash table data structure and how to use Python to control other tools.