После примера из Databricks с моими собственными данными я не могу заставить работать преобразование VectorAssembler.
string_indexer = StringIndexer(inputCol='ptype', outputCol='index_ptype', handleInvalid="skip")
string_indexer_model = string_indexer.fit(sample_df)
indexed_df = string_indexer_model.transform(sample_df)
ohe = OneHotEncoder(inputCol='index_ptype', outputCol='ohe_ptype', handleInvalid="keep")
ohe_model = ohe.fit(indexed_df)
ohe_df = ohe_model.transform(indexed_df)
ohe_df.show()
+-----+-----------+-------------+
|ptype|index_ptype| ohe_ptype|
+-----+-----------+-------------+
| 5.0| 2.0|(6,[2],[1.0])|
| 7.0| 4.0|(6,[4],[1.0])|
| 3.0| 1.0|(6,[1],[1.0])|
| 1.0| 0.0|(6,[0],[1.0])|
| 6.0| 3.0|(6,[3],[1.0])|
| 8.0| 5.0|(6,[5],[1.0])|
+-----+-----------+-------------+
assembler = VectorAssembler(inputCols=['ohe_ptype'], outputCol="features")
result_df_dense = assembler.transform(ohe_df)
result_df_dense.show(truncate=False)
+-----+-----------+-------------+-------------+
|ptype|index_ptype|ohe_ptype |features |
+-----+-----------+-------------+-------------+
|5.0 |2.0 |(6,[2],[1.0])|(6,[2],[1.0])|
|7.0 |4.0 |(6,[4],[1.0])|(6,[4],[1.0])|
|3.0 |1.0 |(6,[1],[1.0])|(6,[1],[1.0])|
|1.0 |0.0 |(6,[0],[1.0])|(6,[0],[1.0])|
|6.0 |3.0 |(6,[3],[1.0])|(6,[3],[1.0])|
|8.0 |5.0 |(6,[5],[1.0])|(6,[5],[1.0])|
+-----+-----------+-------------+-------------+
Как мы видим, мои функции точно такие же, как у ohe_ptype!
Я ожидаю получить что-то вроде этого
+-----+-----------+-------------+-------------------------+
|ptype|index_ptype|ohe_ptype |features |
+-----+-----------+-------------+-------------------------+
|5.0 |2.0 |(6,[2],[1.0])|[0.0,0.0,1.0,0.0,0.0,0.0]|
Подробнее здесь: https://stackoverflow.com/questions/792 ... rassembler
Без изменений при использовании pyspark.ml.feature VectorAssembler ⇐ Python
Программы на Python
-
Anonymous
1736282620
Anonymous
После примера из Databricks с моими собственными данными я не могу заставить работать преобразование VectorAssembler.
string_indexer = StringIndexer(inputCol='ptype', outputCol='index_ptype', handleInvalid="skip")
string_indexer_model = string_indexer.fit(sample_df)
indexed_df = string_indexer_model.transform(sample_df)
ohe = OneHotEncoder(inputCol='index_ptype', outputCol='ohe_ptype', handleInvalid="keep")
ohe_model = ohe.fit(indexed_df)
ohe_df = ohe_model.transform(indexed_df)
ohe_df.show()
+-----+-----------+-------------+
|ptype|index_ptype| ohe_ptype|
+-----+-----------+-------------+
| 5.0| 2.0|(6,[2],[1.0])|
| 7.0| 4.0|(6,[4],[1.0])|
| 3.0| 1.0|(6,[1],[1.0])|
| 1.0| 0.0|(6,[0],[1.0])|
| 6.0| 3.0|(6,[3],[1.0])|
| 8.0| 5.0|(6,[5],[1.0])|
+-----+-----------+-------------+
assembler = VectorAssembler(inputCols=['ohe_ptype'], outputCol="features")
result_df_dense = assembler.transform(ohe_df)
result_df_dense.show(truncate=False)
+-----+-----------+-------------+-------------+
|ptype|index_ptype|ohe_ptype |features |
+-----+-----------+-------------+-------------+
|5.0 |2.0 |(6,[2],[1.0])|(6,[2],[1.0])|
|7.0 |4.0 |(6,[4],[1.0])|(6,[4],[1.0])|
|3.0 |1.0 |(6,[1],[1.0])|(6,[1],[1.0])|
|1.0 |0.0 |(6,[0],[1.0])|(6,[0],[1.0])|
|6.0 |3.0 |(6,[3],[1.0])|(6,[3],[1.0])|
|8.0 |5.0 |(6,[5],[1.0])|(6,[5],[1.0])|
+-----+-----------+-------------+-------------+
Как мы видим, мои функции точно такие же, как у ohe_ptype!
Я ожидаю получить что-то вроде этого
+-----+-----------+-------------+-------------------------+
|ptype|index_ptype|ohe_ptype |features |
+-----+-----------+-------------+-------------------------+
|5.0 |2.0 |(6,[2],[1.0])|[0.0,0.0,1.0,0.0,0.0,0.0]|
Подробнее здесь: [url]https://stackoverflow.com/questions/79279731/no-change-using-pyspark-ml-feature-vectorassembler[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия