请为我提供一个python编写的使用逻辑回归算法处理wine数据集的代码
时间: 2023-05-31 17:07:22 浏览: 173
当然,我很乐意为您提供该代码。以下是使用sklearn库中的逻辑回归算法处理wine数据集的Python代码:
```python
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_wine
import numpy as np
# 加载数据集
wine = load_wine()
# 将数据集划分为训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(wine.data, wine.target, test_size=0.3, random_state=42)
# 构建逻辑回归模型
lr = LogisticRegression()
# 训练模型
lr.fit(X_train, y_train)
# 预测测试集
y_pred = lr.predict(X_test)
# 输出准确率
accuracy = np.mean(y_test == y_pred)
print("Accuracy: ", accuracy)
```
希望对您有所帮助!
阅读全文