最近在写关于模糊树的论文,在GitHub找到了相关的代码,但运行时出现报错
# -*- coding: utf-8 -*-
"""
=========================================================
Comparison of crisp and fuzzy classifiers on iris dataset
=========================================================
A comparison plot for :class:`FuzzyDecisionTreeClassifier`
and sklearn's :class:`DecisionTreeClassifier` on iris
dataset (only two features were selected)
"""
import matplotlib.pyplot as plt
from matplotlib import gridspec
from mlxtend.plotting import plot_decision_regions
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from fuzzytree import FuzzyDecisionTreeClassifier
iris = load_iris()
features = [2, 3]
X = iris.data[:, features]
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf_fuzz = FuzzyDecisionTreeClassifier().fit(X_train, y_train)
clf_sk = DecisionTreeClassifier().fit(X_train, y_train)
gs = gridspec.GridSpec(2, 2)
fig = plt.figure(figsize=(10, 8))
labels = ["Fuzzy Decision Tree", "sklearn Decision Tree"]
for clf, lab, grd in zip([clf_fuzz, clf_sk], labels, [[0, 0], [0, 1]]):
plt.subplot(gs[grd[0], grd[1]])
plot_decision_regions(X=X_train, y=y_train, clf=clf, legend=2)
plt.title("%s (train)" % lab)
plt.subplot(gs[grd[0] + 1, grd[1]])
plot_decision_regions(X=X_test, y=y_test, clf=clf, legend=2)
plt.title("%s (test)" % lab)
plt.show()
报错
'FuzzyDecisionTreeClassifier' object has no attribute '_validate_data'
仔细看了下版本要求:
scikit-learn>=0.24.0
立马去更新一下,
pip install --upgrade scikit-learn
更新过程中又出现问题
ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'c:\\users\\13749\\anaconda3\\lib\\site-packages\\~klearn\\datasets\\_svmlight_format_fast.cp37-win_amd64.pyd'
Consider using the `--user` option or check the permissions.
按照提示改了下:
pip install --user --upgrade scikit-learn
更新成功。
重新运行后有新的问题
TypeError: check_array() got an unexpected keyword argument 'warn_on_dtype'