Last active
June 10, 2021 17:25
-
-
Save audhiaprilliant/ecb7197699f8933a17f51c897b1a6f24 to your computer and use it in GitHub Desktop.
Simple classification model for iris data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def irisDataClassification(): | |
| # Import modules | |
| from sklearn import datasets | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.linear_model import LogisticRegression | |
| from sklearn.metrics import accuracy_score | |
| # Import some data to play with | |
| iris = datasets.load_iris() | |
| X, y = iris.data, iris.target | |
| # Data splitting | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1, stratify = y) | |
| # Create logistic regression object | |
| model = LogisticRegression() | |
| # Data modelling with logistic regression | |
| model.fit(X_train, y_train) | |
| # Create prediction using testing data | |
| y_pred = model.predict(X_test) | |
| # Print out the accuracy | |
| accuracy = accuracy_score(y_test, y_pred) | |
| print(accuracy) | |
| if __name__ == '__main__': | |
| irisDataClassification() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment