Advertisement
makispaiktis

ML - Lab 4 - Perceptron ANN

Oct 19th, 2022 (edited)
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. # Create a DataFrame
  5. X1 = [0, 0, 1, 1]
  6. X2 = [0, 1, 0, 1]
  7. Y = [1, 1, -1, -1]
  8. anndata = pd.DataFrame({"X1": X1, "X2": X2, "Y": Y})
  9. X = anndata.loc[:, ["X1", "X2"]]
  10. y = anndata.loc[:, "Y"]
  11. print("DataFrame: ")
  12. print(anndata)
  13. print()
  14.  
  15. # Perceptron - Scatter for visualizing
  16. plt.scatter(anndata[(anndata.Y == -1)].X1, anndata[(anndata.Y == -1)].X2, c="red", marker="+", label="-1")
  17. plt.scatter(anndata[(anndata.Y == 1)].X1, anndata[(anndata.Y == 1)].X2, c="blue", marker="o", label="1")
  18. plt.title("Initial points")
  19. plt.legend()
  20. plt.show()
  21.  
  22. # Perceptron Classifier - ANN
  23. from sklearn.neural_network import MLPRegressor
  24. clf = MLPRegressor(hidden_layer_sizes=(), learning_rate_init=1)
  25. clf = clf.fit(X, y)
  26. # Predictions
  27. print(clf.predict([[0.1, 0.1]]))
  28. print(clf.predict([[0.9, 0.75]]))
  29. print(clf.predict([[0.5, 0.2]]))
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement