<jupyter_start><jupyter_text>Now we look into the dataset, first we will consider sample a and b<jupyter_code>data_raw_a = np.array([list(map(lambda x: float(x),(i.split(" ")[1:-1]))) for i in open(a_sample_0)])
data_raw_b = np.array([list(map(lambda x: float(x),(i.split(" ")[1:-1]))) for i in open(b_sample_0)])
data_raw_a[0:5]
data_raw_a.shape
data_raw_b.shape<jupyter_output><empty_output><jupyter_text>The shape of the sample depends on the readings from the acc + gyro (MPU6050). So we need make this same for all type of samples<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(15,4))
plt.subplot(1,1,1)
plt.plot(range(0,len(data_raw_a)),data_raw_a)
plt.title("smaple a (gyro+acc)")
plt.show()
plt.figure(figsize=(15,4))
plt.subplot(1,2,1)
plt.plot(range(0,len(data_raw_a)),data_raw_a[:,0:3])
plt.title("Accleration of smaple a ")
plt.legend("XYZ")
plt.subplot(1,2,2)
plt.plot(range(0,len(data_raw_a)),data_raw_a[:,3:])
plt.title("Gyroscope of smaple a ")
plt.legend("XYZ")
plt.show()
plt.figure(figsize=(15,4))
plt.subplot(1,2,1)
plt.plot(range(0,len(data_raw_a)),data_raw_a)
plt.title("plot of sample a ")
plt.subplot(1,2,2)
plt.plot(range(0,len(data_raw_b)),data_raw_b)
plt.title("plot of sample b ")

plt.show()<jupyter_output><empty_output><jupyter_text>we can clearly see there is a difference between sample a and sample b<jupyter_code>data_norm = scale(data_raw_a)
plt.figure(figsize=(15,4))
plt.subplot(1,2,1)
plt.plot(range(0,len(data_raw_a)),data_raw_a)
plt.title("plot of sample a without normalization")
plt.subplot(1,2,2)
plt.plot(range(0,len(data_raw_a)),data_norm)
plt.title("plot of sample a after normalization")
plt.show()
def load(filename,size_fit = 50):
    data_raw = [list(map(lambda x: int(x), i.split(" ")[1:-1])) for i in open(filename)]
    data = np.array(data_raw).astype(float)
    data_norm = scale(data)
    acx = data_norm[:,0]
    acy = data_norm[:,1]
    acz = data_norm[:,2]
    gx = data_norm[:,3]
    gy = data_norm[:,4]
    gz = data_norm[:,5]
    x = np.linspace(0, data.shape[0], data.shape[0])
    f_acx = interp1d(x, acx)
    f_acy = interp1d(x, acy)
    f_acz = interp1d(x, acz)
    f_gx = interp1d(x, gx)
    f_gy = interp1d(x, gy)
    f_gz = interp1d(x, gz)
    xnew = np.linspace(0, data.shape[0], size_fit)
    acx_stretch = f_acx(xnew)
    acy_stretch = f_acy(xnew)
    acz_stretch = f_acz(xnew)
    gx_stretch = f_gx(xnew)
    gy_stretch = f_gy(xnew)
    gz_stretch = f_gz(xnew)

    return np.concatenate((acx_stretch, acy_stretch, acz_stretch, gx_stretch, gy_stretch, gz_stretch))
data_inter = load(a_sample_0,50).reshape(6,50)
data_inter = data_inter.transpose()
plt.figure(figsize=(15,4))
plt.subplot(1,2,1)
plt.title("plot of sample a without interpolation")
plt.plot(range(0,len(data_raw_a)),data_norm)
plt.subplot(1,2,2)
plt.plot(range(0,50),data_inter)
plt.title("plot of sample a after interpolation")
plt.show()<jupyter_output><empty_output><jupyter_text>The shape of different sample of same letter is different, it dependes on how many seconds you take to draw. Hence we need to make it a standard size. Here I am considering a (50,6) as a standerd size using interpolation<jupyter_code>for path, subdirs, files in os.walk(root):
    for name in files:
        filename = os.path.join(path, name)

        x_data.append(load(filename))
        category = name.split("_")[0]
        if category=="":
            category = " "
        number = ord(category) - ord("a")
        y_data.append(number)
        classes[number] = category
params = {'C':[0.001,0.01,0.1,1], 'kernel':['linear']}
svc = svm.SVC(probability = True)
clf = GridSearchCV(svc, params,verbose =10, n_jobs=8)
X_train, X_test, Y_train, Y_test = train_test_split(x_data, y_data, test_size=0.30, random_state=0)
clf.fit(X_train, Y_train)
print(clf.best_estimator_)
score = clf.score(X_test, Y_test)
print("score: {score}".format(score=score))<jupyter_output>score: 0.9827882960413081<jupyter_text>No lets test on the x_test[1] sample<jupyter_code>plt.plot(range(0,50),X_test[1].reshape(6,50).transpose())
plt.show()
ans = clf.predict(X_test[1].reshape(1,-1))[0]
classes[ans]
classes[Y_test[1]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15958969465648856, 'fraction_numerical': 0.03482824427480916, 'mean_word_length': 5.572100313479623, 'pattern_counts': {'":': 1, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '208006', 'license': 'MIT', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1739, 'n_words': 331, 'path': 'docs/demo.ipynb', 'repo_name': 'apthagowda97/gesture-keyboard', 'size': '4192'}