我在使用管道工具和GridSearchCV时遇到了一些问题。 我收到以下错误消息:“ TypeError:Pipeline的最后一步应实现fit或为字符串'passthrough'。'1'(type)不能实现。
您看到我的错误在哪里吗?
这是我的代码:
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline
X = wage['age'][:, np.newaxis]
y = wage['wage'][:, np.newaxis]
degree = 2
model = Pipeline(steps=[('poly', PolynomialFeatures(degree)), ('linear', LinearRegression(fit_intercept=False))])
param_grid = {'poly': [1, 2, 3, 4, 5]}
cv_model = GridSearchCV(model, param_grid, scoring='r2', cv=5, n_jobs=1)
cv_model.fit(X, y)
答案 0 :(得分:0)
问题可能出在我在param_grid中的“ poly”之后没有使用“ __”符号的事实。
使用这种表示法,它似乎可以工作:
import random
Magic_number = random.randrange(1, 100)
print(Magic_number)
guess_limit = 5
guess_counter = 0
while True:
guess = int(input("Enter guess: "))
if guess == Magic_number:
print("Well done you got it!!")
exit(0)
elif guess < Magic_number:
print("That number is too small, try again")
elif guess > Magic_number:
print("That number is too high try again")
guess_counter += 1
print(f"You have {guess_limit - guess_counter} tries left")
if guess_counter == guess_limit:
print("Game over, sorry")
exit(0)