我需要帮助
我正在研究机器学习。
我尝试使用以下代码导入数据集:
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('Rural3.csv', low_memory=False)
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 77].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
但是,出现错误:
ValueError:输入包含无穷大或值对于dtype('float64')
我该怎么办?我是python的新手。
提前致谢。
最佳答案
我建议您在用熊猫加载数据集后,看看是否具有空值:
dataset = dataset.dropna()
还请确保您的X值是数字,您可以使用dataset.describe()或dataset.info():
print(dataset.info()) # will give you info about the dataset columns
您也可以尝试更新sklearn,某些版本的sklearn中存在一个已知的错误(我不记得哪个版本)
# if you are using conda
conda install scikit-learn
# if you are using pip
pip install -U scikit-learn
关于python - ValueError:输入包含无穷大或值对于dtype('float64'),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55500822/