繁体   English   中英

preprocessing.MinMaxScaler().fit_transform() 上的值错误

[英]Value Error on preprocessing.MinMaxScaler().fit_transform()

帮助我了解我在这里做错了什么

# Read Data
dataset = pd.read_csv("PS_20174392719_1491204439457_log.csv")
dataset = dataset.iloc[1:50000]
print (dataset.head())

上述代码的输出,

   step      type    amount     nameOrig  oldbalanceOrg  newbalanceOrig  \
1     1   PAYMENT   1864.28  C1666544295        21249.0        19384.72   
2     1  TRANSFER    181.00  C1305486145          181.0            0.00   
3     1  CASH_OUT    181.00   C840083671          181.0            0.00   
4     1   PAYMENT  11668.14  C2048537720        41554.0        29885.86   
5     1   PAYMENT   7817.71    C90045638        53860.0        46042.29   

      nameDest  oldbalanceDest  newbalanceDest  isFraud  isFlaggedFraud  
1  M2044282225             0.0             0.0        0               0  
2   C553264065             0.0             0.0        1               0  
3    C38997010         21182.0             0.0        1               0  
4  M1230701703             0.0             0.0        0               0  
5   M573487274             0.0             0.0        0               0  

当我运行下面的代码时,我得到一个值错误

# Scale dataset and split into fraud and non-fraud instances
x = dataset.drop(["isFraud"], axis=1)
y = dataset["isFraud"].values 

x_scale = preprocessing.MinMaxScaler().fit_transform(x.values)
x_norm, x_fraud = x_scale[y == 0], x_scale[y == 1]



ValueError: could not convert string to float: 'PAYMENT'

我到底做错了什么?

尝试这个:

  • 删除具有字符串值的列,因为您想缩放数字
  • 将具有数字的列转换为浮点数(也许您的数字在.csv文件中保存为string
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
x = dataset.drop(columns=['type', 'nameOrig', 'nameDest', 'isFraud'])).astype(np.float32)
x_scale = scaler.fit_transform(x)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM