首页 > 解决方案 > 无法将字符串转换为浮点数:'4,49E+09

问题描述

我收到了这个错误:

无法将字符串转换为浮点数:'4,49E+09

当我运行我的 KNN 代码时。

这是我的代码:

import pandas as pd 
import matplotlib.pyplot as plt
import numpy as np

data = pd.read_csv("TotalFeatureRatio2.csv",';')

y = data.AHI 
list = ['AHI', 'Epworth', 'Id'] 
x_data = data.drop(list, axis=1)

x = (x_data - np.min(x_data))/(np.max(x_data)-np.min(x_data))

from sklearn.model_selection import train_test_split 
x_train, x_test, y_train, y_test = train_test_split(x_data, y, test_size=0.3, random_state=1)

from sklearn.neighbors import KNeighborsClassifier 
knn = KNeighborsClassifier(n_neighbors = 5) # n_neighbors = k
knn.fit(x_train,y_train) prediction = 
knn.predict(x_test) print(" {} nn score: {} ".format(5, knn.score(x_test, y_test)))

标签: pythonclassificationknn

解决方案


推荐阅读