我正在尝试将DictVectorizer用于分类作业。这是我第一次使用它。
我的字典看起来像这样
students =
[{'courses': [], 'state': 'CA', 'textbook': [9704873, 11067976], 'zip': 104},
{'courses': ['HIST 2'], 'state': 'CA', 'textbook': [7072542], 'zip': 104},
{'courses': ['BIOSC 4'], 'state': 'CA', 'textbook': [4359080, 13320], 'zip': 110}]
from sklearn.feature_extraction import DictVectorizer
vec = DictVectorizer()
array = vec.fit_transform(students).toarray()
当我试图将它放入DictVectorizer时,它会给我带来以下错误:
Traceback (most recent call last):
File "C:/Users/aanam/PycharmProjects/predict_school/scikit_test.py", line 36, in <module>
array = vec.fit_transform(students).toarray()
File "C:\Python27\lib\site-packages\sklearn\feature_extraction\dict_vectorizer.py", line 142, in fit_transform
return self.transform(X)
File "C:\Python27\lib\site-packages\sklearn\feature_extraction\dict_vectorizer.py", line 230, in transform
values.append(dtype(v))
ValueError: could not convert string to float: HIST 2