
Dear Student , 📚📝✨
During this task, you will implement a classifier using the
ANN Class developed previously.
Objective: Use an ANN to classify the (Q) transistor's state from the TCLab kit.
Research: Dive deep into the theory behind the ANN as classifiers. Again, I'd like you to explore textbooks, online resources, and real-world examples to understand how these methods work and when to use them.
Data collection:
aaa:bbb
for the desired initial (aaa) and final (bbb) index to set ON the Q1
# 10 minute data collection
import tclab, time
import numpy as np
import pandas as pd
with tclab.TCLab() as lab:
n = 600; on=100; t = np.linspace(0,n-1,n)
Q1 = np.zeros(n); T1 = np.zeros(n) # to fill vectors with zeros
Q1[20:41]=on; Q1[60:91]=on; Q1[150:181]=on. # Adding the on state
Q1[aaa:bbb]=on; Q1[aaa:bbb]=on; Q1[aaa:bbb]=on
Q1[aaa:bbb]=on; Q1[aaa:bbb]=on; Q1[aaa:bbb]=on
Q1[aaa:bbb]=on; Q1[aaa:bbb]=on; Q1[aaa:bbb]=on
# Add more on states in the Q1 as you want
print('Time Q1 T1')
for i in range(n):
T1[i] = lab.T1
lab.Q1(Q1[i])
if i%5==0:
print(int(t[i]),Q1[i],T1[i])
time.sleep(1)
data = np.column_stack((t,Q1,T1))
DF = pd.DataFrame(data,columns=['Time','Q1','T1'])
DF.to_csv('data-classification.csv',index=False)
import matplotlib.pyplot as plt
time = data[:,0]
q = data[:,1]
temp = data[:,2]
plt.plot(time, temp,'.r')
plt.plot(time, q, ':g')
plt.show()
CSV
file to split the data into training and test sets :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
# Reading data from file:
try:
data = pd.read_csv('data-classification.csv')
print('The data has been load and is stored in the `data` variable')
except:
print('Warning: Unable to load data-classification.csv, try to run first `data-collect.ipynb`')
# Input Features: Temperature, 1st and 2nd Derivatives
# Add your propoussed code here ...
# Implement here your Supervised Classification
from sklearn.linear_model import LogisticRegression
# Your code here ...
Compare the model against your test data: Finally, you have to use the test data
XB
to compare your model against the real performance
yB. Make a plot of the real Vs the model performance and show the best model to your professor; please include in the plot the temperature, first derivative, and second derivative on a proper scale.
Deadlines 📅: This session's deadline is the 25th of May.
Delivering the task 📄: This lab session does not require a report; add basic information to your Jupyter notebook file to explain to the professor what you did to make your classifier work.
Happy coding!
Gerardo Marx,
Lecturer of the Artificial Intelligence and Automation Course,
gerardo.cc@morelia.tecnm.mx