这是我的代码,应该是一个简单的回归算法。数据集约有500个样本,每个样本都有12个因子。但是,我收到此错误:
ValueError:输入包含NaN,无穷大或值对于 dtype('float64')。
代码:
dataset = pd.read_csv('/Users/chrisrivas/Documents/Andrew Haines/Datasets/GRD.csv', header=None, sep=',')
#coverts dataset into 2d array of values and seperates target column
#[1st to: last rows, and 1st to: 12th columns ]
samples = dataset.loc[:, 1:12].values
targets = dataset[13].values
print(samples)
print(targets)
#training and testing of dataset
X_train, X_test, y_train, y_test = cross_validation.train_test_split(
samples, targets, test_size=0.35, random_state=0)
knn = KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
#calculates accuracy of algorithm
print("Test set score: {:.2f}%".format(np.mean(y_pred == y_test)*100))
#opens new data for algorithm to make classification predictions
dataset2 = pd.read_csv('/Users/chrisrivas/Documents/Datasets/GoldRushDataset-41.csv', header=None, sep=',').values
#continues to loop for each sample and their classification prediction
for sample in dataset2:
prediction = knn.predict([sample])
print("Prediction: {}".format(prediction))
print(' ')
#other format for predictions: all at a time in array
prediction = knn.predict(dataset2)
print("Prediction: {}".format(prediction))