1 of 8

Cookbook for Practice 6.2

Cong Li 李聪

实践6.2攻略

2 of 8

Mysterious Dictionary �神秘的字典

yields/NNS 3386

on/IN 96

money-market/JJ 7478

mutual/JJ 358

Word 词

Attribute index 属性下标

3 of 8

Use the Dictionary (1)�使用该字典

In ‘interestData.py’, in the initialization function, pass in a new variable for the dimension, & use a member variable to store it

在“interestData.py”文件里,为初始化函数传入一个新的维度变量,并用一个成员变量来存储之

A default of 0 means using all the attributes

缺省值0表示使用所有的属性

4 of 8

Use the Dictionary (2)�使用该字典

Write a new member function to read the dictionary & only include the specified dimension of attributes

写一个新的成员函数来读取该字典,并只引入特定维度的属性

Check whether the attribute should be used

检查是否需要使用该属性

5 of 8

Use the Dictionary (3)�使用该字典

Go back to the initialization function, now read the dictionary instead of building the dictionary

回到初始化函数,现在将创建字典改为读取字典

6 of 8

Run It 运行之 (1)

Based on Practice 5.2, in ‘test.py’, import ‘numpy’�基于实践5.2,在“test.py”中导入“numpy”

In the main section, involve all the code into a loop

在主程序中,把所有的代码放置于一个循环里

Add the dimension when reading the data

在读取数据的时候加入维度参数

Add the dimension

加入维度

7 of 8

Run It 运行之 (2)

Rename the variable of the instance of the class ‘tester’ into ‘t’ to avoid ambiguity in the 2nd iteration of the loop, & extract the accuracy 把“tester”类型的实例的变量名改为“t”,防止循环体执行第二次时产生歧义,并取回准确率

Run it 运行之

Output the dimension & the corresponding accuracy

输出维度和相应的准确率

8 of 8

The End