Use of unique(col) in lab2
In lab2 under 5.0.1 there is a method using col:
There is a line of code calling this method like so: 
When the latter is run I get the following error: 
If I refer to the finished lab to check for differences it uses a different library, the old torch data datapipes which have a different syntax.
Understanding:
My understanding is that we will pass in one string from cat_attr and call the method for each. Each gen_encoder_dict(series) call is going to run the unique() func and expect col to have a value BUT there is no access to that variable. I did try a couple different things, but I am not 100% sure what the proper fix would be for this since it appears this way in the lab & lesson notes.
Question
Does this code block compile and run on your side?
Best Answer
-
Hi @p.hanel ,
Apologies for the delayed response.
You're right, the function should read:def gen_encoder_dict(dataset, col): values = sorted(dataset.unique(col)) values += ['UNKNOWN'] return dict(zip(values, range(len(values))))And when it's called, it should be:
dropdown_encoders = {col: gen_encoder_dict(datasets['train'], col) for col in cat_attr}Moreover, the
preproc()function is duplicated. Please ignore the first one. The second - the correct one - is unfortunately missing proper indentation. It should read:def preproc(row): colnames = ['model', 'year', 'price', 'transmission', 'mileage', 'fuel_type', 'road_tax', 'mpg', 'engine_size']#, 'manufacturer'] cat_attr = ['model', 'transmission', 'fuel_type'] cont_attr = ['year', 'mileage', 'road_tax', 'mpg', 'engine_size'] target = 'price' cont_X = [float(row[name]) for name in cont_attr] cat_X = [dropdown_encoders[name].get(row[name], dropdown_encoders[name]['UNKNOWN']) for name in cat_attr] return {'label': np.array([float(row[target])], dtype=np.float32), 'cont_X': np.array(cont_X, dtype=np.float32), 'cat_X': np.array(cat_X, dtype=int)}For the full picture, you can also look at the corresponding notebook in the course's repository: https://github.com/lftraining/LFD273-code/blob/main/labs/Lab 2.ipynb
Best regards,
Daniel1
Categories
- All Categories
- 177 LFX Mentorship
- 177 LFX Mentorship: Linux Kernel
- 768 Linux Foundation IT Professional Programs
- 379 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 101 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 4 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 11 Cloud & Containers Training
- 1 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 2 Open Source Best Practice Training
- 3 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 796 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 91 Storage
- 771 Linux Distributions
- 81 Debian
- 68 Fedora
- 23 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 120 Mobile Computing
- 20 Android
- 85 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 395 Off Topic
- 121 Introductions
- 30 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 693 Software Development
- 1K Software
- 400 Applications
- 182 Command Line
- 5 Compiling/Installing
- 69 Games
- 318 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
