报错与解决 | notfittederror:This StandardScaler instance is not fitted yet.

文章目录

  • 报错问题
  • 报错原因
  • 报错解决
    • 补充内容

报错问题

notfittederror:This StandardScaler instance is not fitted yet. Call ‘fit’ with appropriate arguments before using this estimator.

报错原因

报错位置:reg.fit = (X_train,y_train)

报错解决

将代码更改为reg.fit.(X_train,y_train)

补充内容

注:编码流程(以笔者正在跑的代码为例,只用关注红色部分代码即可)

for reg_name,reg in tqdm_notebook(regressors.items(),desc='regressors'):
	reg = make_pipeline(*preprocessfunc,reg)
    reg.fit(X_train,y_train) #训练
    y_pred = reg.predict(X_test)
    results[reg_name] = y_pred
    results.to_csv(os.path.join('temp_results',f'{filePrefix}_regression_results_{labelName}.csv'))

具体分析:

reg = make_pipeline(*preprocessfunc,reg) # 此处的*preprocessfunc是指数据预处理步骤,如[StandardScaler()]

reg.fit(X_train,y_train) #训练

y_pred = reg.predict(X_test)

results[reg_name] = y_pred

results.to_csv(os.path.join(‘temp_results’,f’{filePrefix}regression_results{labelName}.csv’))

你可能感兴趣的:(机器学习,python,机器学习)