Spaces:
Sleeping
Sleeping
| import seaborn as sns | |
| from sklearn.linear_model import LogisticRegression | |
| # Load iris dataset | |
| iris = sns.load_dataset("iris") | |
| # Prepare features and labels | |
| X = iris.iloc[:, 0:4].values | |
| y = iris.iloc[:, 4].values | |
| # Train logistic regression | |
| modlog = LogisticRegression(max_iter=300) | |
| modlog.fit(X, y) | |
| # Example flower measurements (setosa) | |
| sl = 5.1 | |
| sw = 3.5 | |
| pl = 1.4 | |
| pw = 0.2 | |
| # Predict | |
| res = modlog.predict([[sl, sw, pl, pw]]) | |
| print("The predicted flower species is " + str(res[0])) | |