当我尝试使用SimpleImputer计算缺失值时, 我收到类似TypeError的错误:无法哈希的类型:'slice'。
我使用的代码粘贴在下面。请帮忙。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# for calculating mean
from sklearn.impute import SimpleImputer
# Read data from the csv file
dataset = pd.read_csv('Data.csv')
#independant vector
independant_matrix = dataset.iloc[:, :-1] # [rows, columns] all the rows, all the columns except the last one.
#depandent matrix, just get the last column. but all rows.
depandent_matrix = dataset.iloc[:, 3] # all the rows and 4th column. index strts at 0.
# take mean of values as the missing data
imputer = SimpleImputer(missing_values = 'NaN', strategy = 'mean')
# upper bound is excluded :(
imputer.fit(independant_matrix[:, 1:3])
independant_matrix[:, 1:3] = imputer.transform(independant_matrix[:, 1:3])