ValueError: could not convert string to float

ValueError: could not convert string to float

from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.preprocessing import StandardScaler

def read_data(data_path):
    with open(data_path, 'r') as f:
        data = []
        for line in f.readlines():
            data.append(line.strip())
    return data


features = read_data(r"features.dat")
labels = read_data(r"labels.dat")

train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size=0.33,
                                                                            random_state=33)

scaler = StandardScaler()
train_features = scaler.fit_transform(train_features)
test_features = scaler.fit_transform(test_features)

model = svm.SVC()
model.fit(train_features, train_labels)

prediction = model.predict(test_features)
x = metrics.accuracy_score(prediction, test_labels)
print(x)

运行会出现这个错误:
ValueError: could not convert string to float

检查后发现如果:

	print(features)
	部分片段 >>>,-0.403', '0.52817,
	会有 ' , 出现, 请问怎么解决? 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值