How to use 'iris.csv download' in Python

Every line of 'iris.csv download' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
12def iris(path):
13 """Load the Iris Plants data set [@fisher1936use].
14 It contains 150 examples of iris plants, each with 4 real-valued
15 attributes and its class.
16
17 Args:
18 path: str.
19 Path to directory which either stores file or otherwise file will
20 be downloaded and extracted there. Filename is `iris.data`.
21
22 Returns:
23 Tuple of np.darray `x_train`, np.ndarray `y_train`, and dictionary
24 `metadata` of column headers (feature names).
25 """
26 path = os.path.expanduser(path)
27 filename = 'iris.data'
28 if not os.path.exists(os.path.join(path, filename)):
29 url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/' \
30 'iris/iris.data'
31 maybe_download_and_extract(path, url)
32
33 with open(os.path.join(path, filename)) as f:
34 iterator = csv.reader(f)
35 x_train = []
36 y_train = []
37 for row in iterator:
38 if row:
39 x_train.append(row[:-1])
40 y_train.append(row[-1])
41 x_train = np.array(x_train, dtype=np.float)
42 y_train = np.array(y_train)
43 columns = ['sepal length (cm)', 'sepal width (cm)',
44 'petal length (cm)', 'petal width (cm)']
45 metadata = {'columns': columns}
46 return x_train, y_train, metadata

Related snippets