Professional Documents
Culture Documents
Importing Libraries
In [50]:
1 import numpy as np
2 import pandas as pd
3 from sklearn.linear_model import Perceptron
Dataset
In [51]:
1 %%html
2 <img src="I_and_F_pattern.png" width="40%">
In [52]:
In [53]:
1 x = [I, F]
2 print(x)
In [54]:
1 y = [1, -1]
In [55]:
Out[55]:
Perceptron(tol=0.1)
In [56]:
1 # Getting the mean accuracy on the given test data and labels
2 model.score(x, y)
Out[56]:
1.0
In [57]:
Out[57]:
array([ 1, -1])
In [58]:
1 ycal = model.predict(x[0:1])
2 print('Predicted Class:', ycal)
In [59]:
Out[59]:
In [60]:
1 model.densify()
2 # model.densify() function converts coefficient matrix to dense array format.
Out[60]:
Perceptron(tol=0.1)
1 model.get_params()
Out[61]:
{'alpha': 0.0001,
'class_weight': None,
'early_stopping': False,
'eta0': 1.0,
'fit_intercept': True,
'l1_ratio': 0.15,
'max_iter': 1000,
'n_iter_no_change': 5,
'n_jobs': None,
'penalty': None,
'random_state': 0,
'shuffle': True,
'tol': 0.1,
'validation_fraction': 0.1,
'verbose': 0,
'warm_start': False}