如何删除缩进错误:在Google Colab中,期望有一个缩进块:除了ValueError:

huangapple go评论49阅读模式
英文:

How to Remove IndentationError: expected an indented block: except ValueError: in Google Colab

问题

在给定的数据集上,我被要求对数据集执行 5 个机器学习模型。

以下是我的代码:

standard_scaler = StandardScaler()
try:
  X_train=standard_scaler.fit_transform(X_train)
  X_test=standard_scaler.fit_transform(X_test)

except ValueError:

但是我一直在得到以下错误:

except ValueError:
                 ^
IndentationError: expected an indented block 

有人能帮助我解决这个问题吗?

英文:

Given a dataset I was asked to perform 5 machine learning models on the dataset.

Here is my code:

standard_scaler = StandardScaler()
try:
  X_train=standard_scaler.fit_transform(X_train)
  X_test=standard_scaler.fit_transform(X_test)

except ValueError:

I keep getting

except ValueError:
                 ^
IndentationError: expected an indented block 

Can someone please help me figure out this issue?

答案1

得分: 0

你需要在 ValueError 中添加一个代码块:

standard_scaler = StandardScaler()
try:
  X_train = standard_scaler.fit_transform(X_train)
  X_test = standard_scaler.fit_transform(X_test)
except ValueError:
    pass  # 或者其他你需要的值
英文:

You need a block in ValueError:

standard_scaler = StandardScaler()
try:
  X_train=standard_scaler.fit_transform(X_train)
  X_test=standard_scaler.fit_transform(X_test)
except ValueError:
    pass  #or any other value you need

huangapple
  • 本文由 发表于 2023年3月9日 21:12:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定