from sklearn.linear_model import LogisticRegression
时间: 2023-11-20 15:04:53 浏览: 143
Logistic regression
4星 · 用户满意度95%
Logistic Regression is a statistical method used for binary classification problems (classifying data into two categories). It uses a logistic function to model the probability of a certain input belonging to a certain category. In Python, you can use the scikit-learn library to implement Logistic Regression using the `LogisticRegression` class from the `linear_model` module. Here's an example of how to use it:
```
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
# Load iris dataset
iris = load_iris()
# Create logistic regression object
lr = LogisticRegression()
# Fit the model to the data
lr.fit(iris.data, iris.target)
# Predict new data
new_data = [[5.0, 3.6, 1.3, 0.25], [6.5, 3.0, 5.2, 2.0]]
predictions = lr.predict(new_data)
print(predictions)
```
In this example, we load the iris dataset and create a `LogisticRegression` object. We then fit the model to the data and predict the class of two new data points. The output should be an array with the predicted classes (0, 2) for the two new data points.
阅读全文