我对Python和SKLearn比较陌生。我试图做一个简单的分类器,但我遇到了一个问题。我遵循了一些不同的教程,但是在尝试使用.fit方法时遇到了一个错误。我是新概念,并尝试了文件,但发现很难理解,谁能帮助我错误或指出我的正确方向。在
我在错误背后的想法是,这些值超出了dtype的范围,因为我已经转换了所有丢失的值或nan值,但是错误仍然存在
编码def main():
setup_files()
imputer = Imputer()
#the training data minus id and type:
t_num_data = load_csv(training_set_file_path, range(1, 17))
t_num_data_imputed = imputer.fit_transform(t_num_data)
print(t_num_data_imputed)
#the training type column
t_type_col = load_csv(training_set_file_path, 17, dtype=np.dtype((str, 5)))
#the query data minus id and type:
q_data = load_csv(queries_file_path, range(1, 17))
#the query id column
q_id = load_csv(queries_file_path, 0, dtype=np.dtype((str, 10)))
#fit data above to DTC and predict import
model = tree.DecisionTreeClassifier(criterion='entropy')
model.fit_transform(t_num_data, t_type_col)
predictions = model.predict(q_data)
#output the predictions:
with open(solutions_file_path, 'w') as f:
for i in range(len(predictions)):
f.write("{},{}\n".format(q_id[i], predictions[i]))
#fit data above to DTC and predict import
model = tree.DecisionTreeClassifier(criterion='entropy')
model.fit(t_num_data, t_type_col)
predictions = model.predict(q_data)
#output the predictions:
with open(solutions_file_path, 'w') as f:
for i in range(len(predictions)):
f.write("{},{}\n".format(q_id[i], predictions[i]))
错误
^{pr2}$