小编Vyg*_*has的帖子

scikit-learn.impute 不会使用 Machine Learning AZ 教程中的代码通过 Spyder 从 Imputer 导入

我从机器学习 AZ™:Python 和 R 数据科学教程课程中逐字逐句复制的代码不起作用。我使用的是 Python 3.7,我已经在我的环境中安装了 scikit-learn 包。它不起作用,我试图寻找一个有 sklearn 的包,尽管它似乎没有找到任何东西。它给了我这个错误。
我正在通过 Anaconda 运行我的环境。

ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (C:\Users\vygan\.conda\envs\env\lib\site-packages\sklearn\preprocessing\__init__.py)

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



# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = pd.DataFrame(dataset.iloc[:, :-1].values)
y = pd.DataFrame(dataset.iloc[:, 3].values)

# Taking care of missing data
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
imputer = imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform(X[:, 1:3])
Run Code Online (Sandbox Code Playgroud)

machine-learning spyder scikit-learn python-3.7

5
推荐指数
1
解决办法
7444
查看次数