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

机器学习新手求助:Python语法错误,提示将=替换为==或:=?

解决train_test_split语法错误问题

你的语法错误出在函数调用的括号使用错误上:Python中调用函数必须使用圆括号(),而你代码里误用了方括号[](方括号仅用于列表/数组的索引操作)。

错误代码行:

X_train, X_test, Y_train, Y_test = model_selection.train_test_split[X, Y, test_size=validation_size, random_state=seed]

修正后的完整代码:

array = dataset.values
X = array[:,0:4]
Y = array[:,4]
validation_size = 0.20
seed = 6
X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, Y, test_size=validation_size, random_state=seed)

只需将train_test_split后的[]替换为(),即可解决该语法错误。Python规定函数调用时,参数必须包裹在圆括号内,这是基础语法规则。

内容的提问来源于stack exchange,提问作者user19733366

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 05:04:53