Machine Learning with R Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

Perform the following steps to retrieve data for machine learning:

  1. Access the UCI machine learning repository: http://archive.ics.uci.edu/ml/.
  2. Click on view all data sets. Here you will find a list of datasets containing field names, such as Name, Data Types, Default Task, Attribute Types, #Instances, #Attributes, and Year:
  3. Use Ctrl + F to search for Iris:
  4. Click on Iris. This will display the data folder and the dataset description:
  5. Click on Data Folder, which will display a directory containing the iris dataset:
  1. You can then either download iris.data or use the read.csv function to read the dataset:
        > iris.data = read.csv(url("http://archive.ics.uci.edu/ml/machine-
learning-databases/iris/iris.data"), header = FALSE, col.names =
c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width",
"Species")) > head(iris.data) Output: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 Iris-setosa 2 4.9 3.0 1.4 0.2 Iris-setosa 3 4.7 3.2 1.3 0.2 Iris-setosa 4 4.6 3.1 1.5 0.2 Iris-setosa 5 5.0 3.6 1.4 0.2 Iris-setosa 6 5.4 3.9 1.7 0.4 Iris-setosa