Unused variable 'y_test'
12 def train_model(self):
13 X = self.data.drop("target", axis=1)
14 y = self.data["target"]
15 X_train, X_test, y_train, y_test = train_test_split(16 X, y, test_size=0.2, random_state=42
17 )
18 model = RandomForestClassifier(n_estimators=100, random_state=42)
Unused variable 'X_test'
12 def train_model(self):
13 X = self.data.drop("target", axis=1)
14 y = self.data["target"]
15 X_train, X_test, y_train, y_test = train_test_split(16 X, y, test_size=0.2, random_state=42
17 )
18 model = RandomForestClassifier(n_estimators=100, random_state=42)
Description
An unused variable takes up space in the code, and can lead to confusion, and it should be removed. If this variable is necessary, name the variable _
to indicate that it will be unused, or start the name with unused
or _unused
.
Bad practice
def update():
for i in range(10): # Usused variable `i`
time.sleep(0.01)
display_result()
Preferred:
def update():
for _ in range(10):
time.sleep(0.01)
display_result()