0% found this document useful (0 votes)
30 views2 pages

Lab 03

Uploaded by

Wilson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Lab 03

Uploaded by

Wilson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Arusha Technical College (ATC) Nicodemus M. M.

Lab 03
Instructions
1. In this lab you will use Scikit-Learn for machine learning to train and test Perceptron
using the Perceptron class.

2. To do so, on your mlPractice project create a directory named sklearn.


3. Inside the directory create a python le called skPerceptron.py.

4. In skPerceptron.py write the following code: Do not copy and paste, you should
write line by line.

from sklearn import datasets


from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Perceptron

iris = datasets.load_iris()
X = iris.data[:, [2, 3]]
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y,


test_size=0.3, random_state=0)
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)

# training
ppn = Perceptron(alpha=40, eta0=0.1, random_state=0)
ppn.fit(X_train_std, y_train)

# predict
y_pred = ppn.predict(X_test_std)
print('misclassified: %d' %(y_pred != y_test).sum())
print('accuracy is: %.2f' % accuracy_score(y_test, y_pred))

5. Now that you have completed the code, create a running con guration, name it
skPerceptron.
6. Run to see the results.
fi
fi
Arusha Technical College (ATC) Nicodemus M. M.

7. Study and understand what the code is doing, you will present your understanding
infant of me.
8. This lab is worthy 30 points earned during the interview.
9. The interviews will start on the 27th December 2024

You might also like