Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- # Create a DataFrame
- X1 = [0, 0, 1, 1]
- X2 = [0, 1, 0, 1]
- Y = [1, 1, -1, -1]
- anndata = pd.DataFrame({"X1": X1, "X2": X2, "Y": Y})
- X = anndata.loc[:, ["X1", "X2"]]
- y = anndata.loc[:, "Y"]
- print("DataFrame: ")
- print(anndata)
- print()
- # Perceptron - Scatter for visualizing
- plt.scatter(anndata[(anndata.Y == -1)].X1, anndata[(anndata.Y == -1)].X2, c="red", marker="+", label="-1")
- plt.scatter(anndata[(anndata.Y == 1)].X1, anndata[(anndata.Y == 1)].X2, c="blue", marker="o", label="1")
- plt.title("Initial points")
- plt.legend()
- plt.show()
- # Perceptron Classifier - ANN
- from sklearn.neural_network import MLPRegressor
- clf = MLPRegressor(hidden_layer_sizes=(), learning_rate_init=1)
- clf = clf.fit(X, y)
- # Predictions
- print(clf.predict([[0.1, 0.1]]))
- print(clf.predict([[0.9, 0.75]]))
- print(clf.predict([[0.5, 0.2]]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement