Created
January 16, 2023 22:39
-
-
Save lundquist-ecology-lab/6e86a3f067eca8bb0f0df9342995fab9 to your computer and use it in GitHub Desktop.
Artificial neural network (ANN) example in Python
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
| from sklearn.neural_network import MLPClassifier | |
| from sklearn.datasets import load_iris | |
| from sklearn.model_selection import train_test_split | |
| # Load data | |
| iris = load_iris() | |
| X = iris.data | |
| y = iris.target | |
| # Split data into training and testing sets | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| # Build ANN model | |
| clf = MLPClassifier(hidden_layer_sizes=(10,),max_iter=1000) | |
| clf.fit(X_train, y_train) | |
| # Make predictions on the test set | |
| y_pred = clf.predict(X_test) | |
| # Evaluate the model's performance | |
| from sklearn.metrics import accuracy_score | |
| print(accuracy_score(y_test, y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment