【发布时间】:2019-08-25 07:36:40
【问题描述】:
我需要帮助 我正在研究机器学习。 我尝试使用以下代码导入数据集:
# 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的新手。 提前致谢。
【问题讨论】:
-
哪一行是错误?
-
在
X或Y中可能只有np.inf值需要您删除。您可以通过dataset.iloc[dataset.values==np.inf]之类的过滤器找到这些值 -
X_test = sc.transform(X_test)应该是X_test = sc.transform(X_test)或更改上面的行 -
非常感谢您回答我,但我该怎么做呢?我没听懂?
-
@yosemite_k ,错误出现在特征缩放部分..?!这有什么改变吗?