【问题标题】:could not convert string to float - float DF with no spaces无法将字符串转换为浮点数 - 没有空格的浮点 DF
【发布时间】:2020-10-19 14:25:30
【问题描述】:

我的 sklearn MinMaxScaler 进程出现一个错误:无法将字符串转换为浮点数 但是我所有的数据框都是浮动的,没有空格:

Data columns (total 10 columns):
 #   Column       Non-Null Count  Dtype         
---  ------       --------------  -----         
 0   Data         124 non-null    datetime64[ns] - THIS ONE I EXCLUDED
 1   p1           124 non-null    float64       
 2   p2           124 non-null    float64       
 3   p3           124 non-null    float64       
 4   p4           124 non-null    float64       
 5   p5           124 non-null    float64       
 6   p6           124 non-null    float64       
 7   p7           124 non-null    float64       
 8   p8           124 non-null    float64       
 9   p9           124 non-null    float64


from sklearn.model_selection import train_test_split

X=df.drop('p0',axis=1).values

X=df.drop('p9',axis=1).values

y=df['p9'].values

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=101)

from sklearn.preprocessing import MinMaxScaler

scaler=MinMaxScaler()

X_train=scaler.fit_transform('X_train')

ValueError:无法将字符串转换为浮点数:'X_train'

谁能告诉我问题出在哪里?

提前谢谢你

【问题讨论】:

  • 你能打印(X)吗?让我们看看会发生什么。

标签: python machine-learning scikit-learn type-conversion data-science


【解决方案1】:

问题出在最后一行:

X_train=scaler.fit_transform('X_train')

应该是

X_train = scaler.fit_transform(X_train)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-25
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多