尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

PySpark - MinMaxScaler

PySpark - MinMaxScaler
📅 发布时间:2026/6/19 21:23:22
PySpark - MinMaxScaler

 

from pyspark.ml.feature import MinMaxScalerscaler = MinMaxScaler(inputCol='features', outputCol='scaled_features')
scaler_model = scaler.fit(df)
scaled_df = scaler_model.transform(df)
scaled_df.show(truncate=False)

 

+---+--------------+---------------+
|id |features      |scaled_features|
+---+--------------+---------------+
|0  |[1.0,0.1,-1.0]|(3,[],[])      |
|1  |[2.0,1.1,1.0] |[0.5,0.1,0.5]  |
|2  |[3.0,10.1,3.0]|[1.0,1.0,1.0]  |
+---+--------------+---------------+

Please help me understand the values of the scaled_features column.

 

Here is what’s happening in your scaled_features column and why you see values like (3,[],[]) for the first row.


✅ How MinMaxScaler Works

MinMaxScaler rescales each feature column-wise to the range [0, 1]:

1

Applied per column, not per row.


📌 Your Input

Row 0: [1.0, 0.1, -1.0]
Row 1: [2.0, 1.1,  1.0]
Row 2: [3.0,10.1,  3.0]

Let’s compute min and max for each column:

Feature IndexValuesMinMaxRange
0 1.0, 2.0, 3.0 1.0 3.0 2.0
1 0.1, 1.1, 10.1 0.1 10.1 10.0
2 -1.0, 1.0, 3.0 -1.0 3.0 4.0

📌 Compute Scaled Values

Row 1 (id = 1) → [2.0, 1.1, 1.0]

Index 0:

(2.0−1.0)/(3.0−1.0)=1/2=0.5

Index 1:

(1.1−0.1)/(10.1−0.1)=1/10=0.1

Index 2:

(1.0−(−1.0))/(3.0−(−1.0))=2/4=0.5

✔ Output: [0.5, 0.1, 0.5]

Row 2 (id = 2) → [3.0, 10.1, 3.0]

All are max values → scale to 1:

✔ [1.0, 1.0, 1.0]


❗ Why Row 0 → (3,[],[]) (all zeros)

For row 0:

[1.0, 0.1, -1.0]

Index 0:

(1.0−1.0)/2.0=0

Index 1:

(0.1−0.1)/10.0=0

Index 2:

(−1.0−(−1.0))/4.0=0

👉 All scaled values are 0:

[0.0, 0.0, 0.0]

But Spark uses SparseVector format to store vectors with many zeros:

(3, [], [])

This means:

  • size = 3

  • no non-zero indices = []

  • no non-zero values = []

This is equivalent to:

[0.0, 0.0, 0.0]

✅ Summary

idfeaturesscaled_featuresMeaning
0 [1.0,0.1,-1.0] (3,[],[]) all zeros → min values
1 [2.0,1.1,1.0] [0.5,0.1,0.5] mid-range values
2 [3.0,10.1,3.0] [1.0,1.0,1.0] max values

 

相关新闻

  • ubuntu 无网络连接/无网络标识解决方法
  • P14134 【MX-X22-T5】「TPOI-4E」Get MiN? Get MeX!
  • 使用injected Provider在remix中调试合约的坑 -- 时间(或者最新块)更新不及时 - 详解

最新新闻

  • SAP BOM查询实战:从正查到反查的完整指南
  • 【2026年6月】热水离心泵厂家推荐指南 - 多才菠萝
  • Python图片压缩方法全解:从入门到进阶
  • 【JAVA毕设源码分享】基于SpringBoot的中华传统文化网站(程序+文档+代码讲解+一条龙定制)
  • 全国学历提升继续教育学习体验实录
  • 验证码绕过实战:从Pikachu靶场剖析客户端与服务端漏洞原理

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号