- Advanced Machine Learning with R
- Cory Lesmeister Dr. Sunil Kumar Chinnamgari
- 170字
- 2021-06-24 14:24:46
Loading the data
As for this data, it is the same that we used in Chapter 2, Linear Regression. What is different is that I've prepared the data exactly as before, but saved the features and response as an RData file. You can download that from GitHub: https://github.com/PacktPublishing/Advanced-Machine-Learning-with-R/blob/master/Data/amesDL.RData.
Once you have that in your working directory, load it into the environment:
> load("amesDL.RData")
Notice that you now have four new objects:
- trained: The training data features
- tested: The testing data features
- train_logy: The log of home sales
- test_logy: The log of home sales
It is essential that the data is centered and scaled for a neural network (in the prior exercise, all features were either zero or one, which is acceptable). To perform this task, a function is available in the caret package. Let's use the training data to create the mean and standard deviation values that we will apply to both train and test data:
> prep <- caret::preProcess(trained, method = c("center", "scale"))
> trainT <- predict(prep, trained)
This gives us our transformed training data. However, Keras will not accept a dataframe as an input. It needs an array for both the features and the response. This is an easy fix with the data.matrix() function:
> train_logy <- data.matrix(train_logy)
> trainT <- data.matrix(trainT)
Now, you can just repeat these steps with the test data features:
> testT <- predict(prep, tested)
> testT <- data.matrix(testT)
It's about to get interesting.
- Learning Cocos2d-x Game Development
- Android NDK Game Development Cookbook
- Unity 5.x Game Development Blueprints
- AMD FPGA設計優化寶典:面向Vivado/SystemVerilog
- Artificial Intelligence Business:How you can profit from AI
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- Learning Stencyl 3.x Game Development Beginner's Guide
- Svelte 3 Up and Running
- 微服務分布式架構基礎與實戰:基于Spring Boot + Spring Cloud
- The Deep Learning with Keras Workshop
- Machine Learning with Go Quick Start Guide
- 面向對象分析與設計(第3版)(修訂版)
- Hands-On Artificial Intelligence for Banking
- RISC-V處理器與片上系統設計:基于FPGA與云平臺的實驗教程
- Blender Game Engine:Beginner's Guide