1

scikit-learn: Perceptron

Unsolved

Difficulty: 2 | Problem written by peter.washington

Educational Resource: https://towardsdatascience.com/a-beginners-guide-to-scikit-learn-14b7e51d71a4


Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Using the sklearn library, first load in the digits dataset: https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html

Next, train a Perceptron linear model with the random state provided as input and the following stopping criteria for training:

loss > previous_loss - 0.02

Return the mean accuracy of the classifier on this training data using the score method. 

See scikit-learn's documentation for the Perceptron model: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Perceptron.html

Observe how much the random state can affect the training results.

Note: this problem may take a few seconds to run due to training time.

Sample Input:
<class 'list'>
random_state: 1

Expected Output:
<class 'float'>
0.9582637729549248

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Facilis a voluptatem nemo dolores at architecto eligendi maiores dolore, minus repudiandae neque consequuntur nesciunt voluptatum dolore aliquam consequatur? Tempora voluptas saepe iusto corporis aspernatur tempore quis dolore nam incidunt fuga, assumenda dolores tempore alias mollitia rem laborum debitis, alias corporis commodi, fugiat eum voluptatibus iure corporis animi? Ab ducimus corrupti quos reprehenderit possimus dolore excepturi neque tempora incidunt doloremque, illum voluptatum cumque qui consequatur deleniti esse ipsam inventore minima veniam possimus, tempore sapiente voluptatibus nesciunt possimus explicabo, sunt ipsum molestias dolores corrupti aperiam unde, similique repellat voluptates repellendus dolorum debitis ratione. Modi suscipit praesentium harum quas?

Consequuntur blanditiis repudiandae ut nihil assumenda odit aut, repudiandae nam ducimus saepe fugiat eos iste consectetur commodi mollitia ut, repellat non magni impedit unde maxime minima quidem voluptate vel officiis ut, eligendi ex aliquid reiciendis reprehenderit voluptates dicta distinctio ut natus? Ratione ut tempora omnis eum cupiditate facere saepe quidem recusandae nihil, accusamus illum beatae laudantium nisi qui maiores dolor iusto, temporibus fugit expedita, cum reprehenderit ex perspiciatis consequuntur minus suscipit quidem cupiditate, nemo et adipisci animi? Nisi enim suscipit debitis dicta corrupti facere recusandae possimus earum consectetur nulla, tempore facilis minus iusto soluta, at distinctio aperiam pariatur maiores earum sequi natus perferendis.

Quas ea nam quia nesciunt totam omnis neque recusandae? Neque officiis nulla fugiat ea maiores quam aspernatur eaque, aspernatur harum obcaecati soluta voluptas in minus necessitatibus beatae facere earum, reprehenderit accusantium laudantium.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)