Hey
Machine Learning notes
skearn 的非数值进行数值性编码与 sklearn 的库进行准确率的计算
1. 可以使用 python 自带的 skearn 对 result 的非数值进行数值性编码
1 2
| from sklearn.model_selection import train_test_split y = LabelEncoder().fit_transform(data[4])
|
2. 可以使用 sklearn 的库进行准确率的计算
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| from sklearn.metrics import accuracy_socre from sklearn.preprocessing import LabelEncoder from sklearn.tree import DecisionTreeClassifier x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.7, random_state=1) model = DecisionTreeClassifier(criterion='entorpy') model.fit(x_train,y_train) y_test_hat = model.predict(x_test)
print("accuracy_score",accuracy_socre(y_test_hat,y_test))
y_test = y_test.reshape(-1) result = (y_test_hat==y_test) acc = np.mean(result) print(f"准确率:{100*acc}")
|
Gitalk 加载中 ...