183183#
184184
185185url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" # url to data
186- filename = url .split ("/" )[- 1 ]
186+ filename = os . path . join ( "data" , url .split ("/" )[- 1 ])
187187
188188# Download file if it doesn't already exist
189189if not os .path .exists (filename ):
190+ os .makedirs ("data" )
190191 print ("Downloading..." )
191- wget .download (url , 'iris.data' )
192+ wget .download (url , filename )
192193 print ("Download complete!" )
193194else :
194195 print ("File exists, skipping download." )
195196
196197# Print 10 random lines
197- with open (filename , 'rb ' ) as datafile :
198+ with open (filename , 'r ' ) as datafile :
198199 lines = datafile .readlines ()
199200 # Last line in file is empty, we'll deal with this later
200201 lines = lines [:- 1 ]
218219
219220# Takes a filename with comma separated contents, returns dataset list
220221def create_dataset (filepath ):
221- with open (filepath , 'rb ' ) as datafile :
222+ with open (filepath , 'r ' ) as datafile :
222223 # Create dataset list
223224 lines = csv .reader (datafile )
224225 dataset = list (lines )
@@ -233,7 +234,7 @@ def create_dataset(filepath):
233234
234235
235236# Load dataset
236- dataset = create_dataset ("iris.data" )
237+ dataset = create_dataset ("data/ iris.data" )
237238
238239
239240######################################################################
0 commit comments