如何解决此错误? &quot”功能'对象没有属性'标准标准器;

发布于 2025-02-06 23:56:37 字数 606 浏览 2 评论 0原文

def preprocessing(df:pd.DataFrame,scaler:str):
  standard_scaler= preprocessing.StandardScaler()
  not_uv=[]
  for column in df.columns:
    if column != 'uv': # uv is target
      not_uv.append(column)
  if scaler == 'standard':
    standard_df = pd.DataFrame(standard_scaler.fit_transfrom(df[not_uv]), columns = not_uv)
    standard_df = pd.concat([standard_df,df[['uv']]],axis=1)
    return standard_df
preprocessing(df_13,'standard')
AttributeError: 'function' object has no attribute 'StandardScaler'

我想制作预处理功能 我的代码怎么了?

def preprocessing(df:pd.DataFrame,scaler:str):
  standard_scaler= preprocessing.StandardScaler()
  not_uv=[]
  for column in df.columns:
    if column != 'uv': # uv is target
      not_uv.append(column)
  if scaler == 'standard':
    standard_df = pd.DataFrame(standard_scaler.fit_transfrom(df[not_uv]), columns = not_uv)
    standard_df = pd.concat([standard_df,df[['uv']]],axis=1)
    return standard_df
preprocessing(df_13,'standard')
AttributeError: 'function' object has no attribute 'StandardScaler'

i want to make preprocssing function
whats wrong with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

や三分注定 2025-02-13 23:56:37

此代码在用户定义的功能预处理和Sklearn内置功能预处理之间产生冲突。只需导入并进行这样的实例。

from sklearn.preprocessing import StandardScaler

standard_scaler= StandardScaler()

将您的功能名称更改为预处理 预处理或其他东西。切勿声明或制作内置关键字的实例。

This code generates a conflict between user-defined function preprocessing and sklearn built-in function preprocessing. Simply import and make instance like this.

from sklearn.preprocessing import StandardScaler

standard_scaler= StandardScaler()

OR

Change your function name preprocessing to preprocessings or something else. Never declare or make an instance of built-in keywords.

柏拉图鍀咏恒 2025-02-13 23:56:37

函数的名称def预处理(...):preprocessing.standardscaler()相同。这意味着您正在覆盖内存。更改功能的名称。例如:

def new_preprocessing(df:pd.DataFrame,scaler:str):
  standard_scaler= preprocessing.StandardScaler()
  not_uv=[]
  for column in df.columns:
    if column != 'uv': # uv is target
      not_uv.append(column)
  if scaler == 'standard':
    standard_df = pd.DataFrame(standard_scaler.fit_transfrom(df[not_uv]), columns = not_uv)
    standard_df = pd.concat([standard_df,df[['uv']]],axis=1)
    return standard_df

The name of the function def preprocessing(...): is same as preprocessing.StandardScaler(). Which means you are overwriting the memory. Change the name of the function. For Example:

def new_preprocessing(df:pd.DataFrame,scaler:str):
  standard_scaler= preprocessing.StandardScaler()
  not_uv=[]
  for column in df.columns:
    if column != 'uv': # uv is target
      not_uv.append(column)
  if scaler == 'standard':
    standard_df = pd.DataFrame(standard_scaler.fit_transfrom(df[not_uv]), columns = not_uv)
    standard_df = pd.concat([standard_df,df[['uv']]],axis=1)
    return standard_df
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文