You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MinMaxScaler.inverse_transform()报ValueError:操作数无法广播匹配的问题求助

MinMaxScaler.inverse_transform()报ValueError:操作数无法广播匹配的问题求助

我正在做一个棒球数据预测的项目,现在基本快完成了——之前解决了原模型(从YouTube视频里扒的)的一堆问题,但卡在最后一步:我想整理一个结果汇总的DataFrame。

现在的问题是,我想把之前缩放的数据还原成原始值。之前我用MinMaxScaler处理了一批列(标记为selected_columns),代码是这样的:

batting.loc[:, selected_columns] = scaler.fit_transform(batting[selected_columns])

到了项目末尾,我想把数据还原,于是针对upcoming_season这个DataFrame(里面是下赛季球员的信息,包括player_id、球队,还有所有设为0的统计数据,毕竟还没打比赛)写了这段代码:

upcoming_season = upcoming_season.drop(['Name', 'Team', 'H', 'L-Hits', 'Next_Hits', 'player_season', 'h_diff'], axis=1)
next_season = pd.DataFrame(upcoming_season)
next_season = next_season.apply(pd.to_numeric)
inverse_next_season = scaler.inverse_transform(next_season)

结果最后一行inverse_transform触发了错误,Traceback是这样的:

ValueError                                Traceback (most recent call last)
Cell In[82], line 1
----> 1 inverse_next_season = scaler.inverse_transform(next_season)

File /opt/anaconda3/lib/python3.12/site-packages/sklearn/preprocessing/_data.py:574, in MinMaxScaler.inverse_transform(self, X)
    564 xp, _ = get_namespace(X)
    566 X = check_array(
    567     X,
    568     copy=self.copy,
   (...)
    571     force_all_finite="allow-nan",
    572 )
--> 574 X -= self.min_
    575 X /= self.scale_
    576 return X

ValueError: operands could not be broadcast together with shapes (285,141) (137,) (285,141) 

我搞不懂这个(137,)的“第三个”维度是哪来的。

要是需要更多代码我可以提供,你们觉得哪些信息有用尽管说,我会补充的。

我只找到两个有点类似的问题,但都解决不了我的情况。

备注:内容来源于stack exchange,提问作者Richard C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 08:30:27