- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 703字
- 2021-07-09 21:07:55
Data cleansing and transformation
The majority of machine learning algorithms operate on features, which are typically numerical representations of the input variables that will be used for the model.
While we might want to spend the majority of our time exploring machine learning models, data collected via various systems and sources in the preceding ingestion step is, in most cases, in a raw form. For example, we might log user events such as details of when a user views the information page for a movie, when they watch a movie, or when they provide some other feedback. We might also collect external information such as the location of the user (as provided through their IP address, for example). These event logs will typically contain some combination of textual and numeric information about the event (and also, perhaps, other forms of data such as images or audio).
In order to use this raw data in our models, in almost all cases, we need to perform preprocessing, which might include:
- Filtering data: Let's assume that we want to create a model from a subset of raw data, such as only the most recent few months of activity data or only events that match certain criteria.
- Dealing with missing, incomplete, or corrupted data: Many real-world datasets are incomplete in some way. This might include data that is missing (for example, due to a missing user input) or data that is incorrect or flawed (for example, due to an error in data ingestion or storage, technical issues or bugs, or software or hardware failure). We might need to filter out bad data or alternatively decide a method to fill in missing data points (such as using the average value from the dataset for missing points, for example).
- Dealing with potential anomalies, errors, and outliers: Erroneous or outlier data might skew the results of model training, so we might wish to filter these cases out or use techniques that are able to deal with outliers.
- Joining together disparate data sources: For example, we might need to match up the event data for each user with different internal data sources, such as user profiles, as well as external data, such as geolocation, weather, and economic data.
- Aggregating data: Certain models might require input data that is aggregated in some way, such as computing the sum of a number of different event types per user.
Once we have performed initial preprocessing on our data, we often need to transform the data into a representation that is suitable for machine learning models. For many model types, this representation will take the form of a vector or matrix structure that contains numerical data. Common challenges during data transformation and feature extraction include:
- Taking categorical data (such as country for geolocation or category for a movie) and encoding it in a numerical representation.
- Extracting useful features from text data.
- Dealing with image or audio data.
- Converting numerical data into categorical data to reduce the number of values a variable can take on. An example of this is converting a variable for age into buckets (such as 25-35, 45-55, and so on).
- Transforming numerical features; for example, applying a log transformation to a numerical variable can help deal with variables that take on a very large range of values.
- Normalizing and standardizing numerical features ensures that all the different input variables for a model have a consistent scale. Many machine learning models require standardized input to work properly.
- Feature engineering, which is the process of combining or transforming the existing variables to create new features. For example, we can create a new variable that is the average of some other data, such as the average number of times a user watches a movie.
We will cover all of these techniques through the examples in this book.
This data-cleansing, exploration, aggregation, and transformation steps can be carried out using both Spark's core API functions as well as the SparkSQL engine, not to mention other external Scala, Java, or Python libraries. We can take advantage of Spark's Hadoop compatibility to read data from and write data to the various storage systems mentioned earlier.
We can also leverage Spark streaming in case the streaming input is involved.
- Hands-On Graph Analytics with Neo4j
- 實時流計算系統(tǒng)設(shè)計與實現(xiàn)
- 反饋系統(tǒng):多學(xué)科視角(原書第2版)
- IoT Penetration Testing Cookbook
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- ESP8266 Home Automation Projects
- 項目管理成功利器Project 2007全程解析
- 聊天機(jī)器人:入門、進(jìn)階與實戰(zhàn)
- Lightning Fast Animation in Element 3D
- Salesforce Advanced Administrator Certification Guide
- 自動化生產(chǎn)線安裝與調(diào)試(三菱FX系列)(第二版)
- 中文版AutoCAD 2013高手速成
- 手機(jī)游戲策劃設(shè)計
- C#求職寶典
- Drupal高手建站技術(shù)手冊