<jupyter_start><jupyter_text>Step function<jupyter_code>import matplotlib.pylab as plt
import numpy as np
def binary_step(x):
    if x < 0:
        return 0
    else:
        return 1
x = list(np.linspace(-5, 5, 100))
y = list(map(lambda x: binary_step(x), x))
plt.plot(x, y,'b')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Binary step function')
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Пример sklearn<jupyter_code>from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Perceptron      #Single-layer perceptron
from sklearn.neural_network import MLPClassifier #Multilayer perceptron 
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load the mnist dataset
mnist = datasets.load_digits()
# Create our X and y data
n_samples = len(mnist.images)
X = mnist.images.reshape((n_samples, -1))
y = mnist.target
# Split the data into 70% training data and 30% test data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
# Train the scaler, which standarizes all the features to have mean=0 and unit variance
sc = StandardScaler()
sc.fit(X_train)
# Apply the scaler to the X training data
X_train_std = sc.transform(X_train)
# Apply the SAME scaler to the X test data
X_test_std = sc.transform(X_test)
# Create a single-layer perceptron object with the parameters: 40 iterations (epochs) over the data, and a learning rate of 0.1
ppn = Perceptron(n_iter=40, eta0=0.1, random_state=0)
# Create a multilayer perceptron object
mppn = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(256, 512, 128), random_state=1)
# Train the perceptrons
ppn.fit(X_train_std, y_train)
mppn.fit(X_train_std, y_train)
# Apply the trained perceptrons on the X data to make predicts for the y test data
y_pred = ppn.predict(X_test_std)
multi_y_pred = mppn.predict(X_test_std)
# View the accuracies of the model, which is: 1 - (observations predicted wrong / total observations)
print('Single-layer perceptron accuracy: %.4f' % accuracy_score(y_test, y_pred))
print('Multilayer perceptron accuracy: %.4f' % accuracy_score(y_test, multi_y_pred))<jupyter_output>Single-layer perceptron accuracy: 0.9444
Multilayer perceptron accuracy: 0.9537<jupyter_text>Анализ полученных данных<jupyter_code>import pandas as pd
import csv
import matplotlib.pyplot as plt
pd.set_option('max_colwidth', 500)
data = pd.read_csv("./analyse_step/step.csv")
data.head(11)
plt.plot(data['k'], data['E'],'b')
plt.xlabel('E')
plt.ylabel('k')
plt.title('E(k)')
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Логистическая ФА<jupyter_code>df = pd.read_csv("./analyse_step/step_tanh.csv")
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10945454545454546, 'fraction_numerical': 0.020363636363636365, 'mean_word_length': 6.126943005181347, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '320471', 'license': 'MIT', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1008, 'n_words': 264, 'path': 'release/Perceptron_sklearn.ipynb', 'repo_name': 'Dmitriy1594/simple_perceptron', 'size': '2750'}