|
Contents
Preface iii
1 Introduction 1
1.1 How to read this book? . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 A short introduction to R . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Starting with R . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.2 R objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.3 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.4 Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.5 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.6 Generating sequences . . . . . . . . . . . . . . . . . . . . 11
1.2.7 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.8 Matrices and arrays . . . . . . . . . . . . . . . . . . . . . 14
1.2.9 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2.10 Data frames . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.2.11 Some useful functions . . . . . . . . . . . . . . . . . . . . 23
1.2.12 Creating new functions . . . . . . . . . . . . . . . . . . . 25
1.2.13 Managing your sessions . . . . . . . . . . . . . . . . . . . 28
1.3 A short introduction to MySQL . . . . . . . . . . . . . . . . . . . 29
2 Predicting Algae Blooms 33
2.1 Problem description and objectives . . . . . . . . . . . . . . . . . 33
2.2 Data Description . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3 Loading the data into R . . . . . . . . . . . . . . . . . . . . . . . 34
2.4 Data Visualization and Summarization . . . . . . . . . . . . . . . 35
2.5 Unknown values . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.5.1 Removing the observations with unknown values . . . . . 43
2.5.2 Filling in the unknowns with the most frequent values . . 44
2.5.3 Filling in the unknown values by exploring correlations . 45
2.5.4 Filling in the unknown values by exploring similarities
between cases . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.6 Obtaining prediction models . . . . . . . . . . . . . . . . . . . . . 52
2.6.1 Multiple linear regression . . . . . . . . . . . . . . . . . . 52
2.6.2 Regression trees . . . . . . . . . . . . . . . . . . . . . . . 58
2.7 Model evaluation and selection . . . . . . . . . . . . . . . . . . . 64
2.8 Predictions for the 7 algae . . . . . . . . . . . . . . . . . . . . . . 70
2.8.1 Preparing the test data . . . . . . . . . . . . . . . . . . . 71
2.8.2 Comparing the alternative models . . . . . . . . . . . . . 71
v
vi CONTENTS
2.8.3 Obtaining the prediction for the test samples . . . . . . . 74
2.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3 Predicting Stock Market Returns 79
3.1 Problem description and objectives . . . . . . . . . . . . . . . . . 79
3.2 The available data . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.2.1 Reading the data from the CSV file . . . . . . . . . . . . 81
3.2.2 Reading the data from a MySQL database . . . . . . . . . 82
3.2.3 Getting the data from the Web . . . . . . . . . . . . . . . 85
3.3 Time series predictions . . . . . . . . . . . . . . . . . . . . . . . . 87
3.3.1 Obtaining time series prediction models . . . . . . . . . . 90
3.3.2 Evaluating time series models . . . . . . . . . . . . . . . . 96
3.3.3 Model selection . . . . . . . . . . . . . . . . . . . . . . . . 100
3.4 From predictions into trading actions . . . . . . . . . . . . . . . . 103
3.4.1 Evaluating trading signals . . . . . . . . . . . . . . . . . . 104
3.4.2 A simulated trader . . . . . . . . . . . . . . . . . . . . . . 106
3.5 Going back to data selection . . . . . . . . . . . . . . . . . . . . . 110
3.5.1 Enriching the set of predictor variables . . . . . . . . . . . 110
Bibliography 119
下载:
Data Mining with R.pdf
(1.68 MB, 下载次数: 175, 售价: 5 金钱)
|
|