-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_load_ml_data.py
36 lines (26 loc) · 900 Bytes
/
4_load_ml_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Load CSV
import csv
import numpy as np
filename = 'pima-indians-diabetes.data.csv'
raw_data = open(filename, 'rt')
reader = csv.reader(raw_data, delimiter=',', quoting=csv.QUOTE_NONE)
x = list(reader)
data = np.array(x).astype('float')
print(data.shape)
# Load CSV from URL using Numpy
from numpy import loadtxt
from urllib.request import urlopen
url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.data.csv'
raw_data = urlopen(url)
dataset = loadtxt(raw_data, delimiter=',')
print(dataset.shape)
# Load data from a text file.
# Each row in the text file must have the same number of values.
# Load CSV using Pandas
import pandas as pd
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
data = pd.read_csv(filename, names=names)
print(data.shape)
# Load CSV from url using Pandas
data = pd.read_csv(url)
print(data.shape)