如何使用 dictVectorizer() 在稀疏数组中表示特征?

问题描述 投票:0回答:0

我一直在网上搜索这个,但我一无所获。让我们考虑这个例子

measurements = [
     {'city': 'Dubai', 'temperature': 33.},
     {'city': 'London', 'temperature': 12.},
     {'city': 'San Francisco', 'temperature': 18.}]
vec = DictVectorizer()
transformed_sparse = vec.fit_transform(measurements)
print(transformed_sparse)

结果

  (0, 0)    1.0
  (0, 3)    33.0
  (1, 1)    1.0
  (1, 3)    12.0
  (2, 2)    1.0
  (2, 3)    18.0

```


first row  in the sparse array tells us about the existence of the key
in the first row of dictionary why the temperature value is indexed ad
(0,3)  it means first row, third column?  should not it be second?



I was not able to find the relation  between the indexing of array and the dictionary, I have used chat gpt,but every time it gives different answer
python machine-learning feature-extraction
© www.soinside.com 2019 - 2024. All rights reserved.