【发布时间】:2026-01-19 19:30:01
【问题描述】:
我正在尝试在数据预处理阶段解决丢失数据的问题,并且一直在认真学习 udemy 教程。
这是我的数据集“Data.csv”
Country Age Salary Purchased
France 44 72000 No
Spain 27 48000 Yes
Germany 30 54000 No
Spain 38 61000 No
Germany 40 Yes
France 35 58000 Yes
Spain 52000 No
France 48 79000 Yes
Germany 50 83000 No
France 37 67000 Yes
这是完整的代码。
# Data Preprocessing
#Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
Y = dataset.iloc[:, -1].values
# Taking care of missing data
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = "NaN", strategy = "mean", axis = 0)
#This line below throws the error
imputer = Imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform(X[:, 1:3])
上面的代码在教程视频中运行得非常好,但是当我运行上面的代码时,我得到以下错误:
**imputer = Imputer.fit(X[:, 1:3])
Traceback (most recent call last):
File "<ipython-input-3-dddb27392326>", line 1, in <module>
imputer = Imputer.fit(X[:, 1:3])
TypeError: fit() missing 1 required positional argument: 'X'**
我使用以下规格:
操作系统:Win 8.1 教程有一个 MAC IDE:Spyder 3.2.8 Python 3.6
谁能帮我调试一下这个错误。
【问题讨论】:
标签: machine-learning scikit-learn python-3.6 spyder