In this article we will see how can we implement the Logistic Regression model on iris dataset . As we know that Logistic Regression is a mostly used machine learning algorithm for discrete classes. Suppose you have given the data about the flowers and you have to find which category the flower belongs then you can use this algorithm.
So today we are going to implement this Logistic Regression on iris dataset.
1. First of all we will import all the necessary libraries for this.
2. Now we create a variable to assign the data.
3. Now we create 2 other variables for training purpose X which has all the input values and Y which has target data.
4. Now we will be splitting our data in four parts (X_train,X_test,Y_train,Y_test)
5. Now we will import Logistic Regression from Sklearn library and create a variable model and assign value of it.
6. Now we will fit our model with the data. In this process our model is trained.
7. Now we can use our test data and predict the values. FOr that we will create a variable y_pred and our model will mae prediction for each tuple of x_test.
8. To calculate the accuracy we will import accuracy score from sklearn library.
9. We will print the accuracy.
So in this way we can implement the logistic regression using iris dataset.