This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.utils import shuffle | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.preprocessing import OneHotEncoder | |
| enc = OneHotEncoder() | |
| y_data = enc.fit_transform(y_data).toarray() | |
| x_data, y_data = shuffle(x_data, y_data) | |
| X_train, X_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.2,stratify=y_data,random_state=42) | |
| X_train = X_train.reshape((-1,1025,87,1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import librosa | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import librosa.display | |
| data, sr = librosa.load('Dataset/decrease_volume/1.wav') | |
| D = np.abs(librosa.stft(data)) | |
| plt.figure(figsize=(20,8)) | |
| librosa.display.specshow(librosa.amplitude_to_db(D,ref=np.max),y_axis='log', x_axis='time') | |
| plt.title('Spectrogram') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import librosa | |
| import os | |
| peak_features = [] | |
| peak_labels = [] | |
| count = 0 | |
| for dirc in sorted(os.listdir('./Dataset')): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import librosa | |
| import random | |
| for files in os.listdir('./Dataset'): | |
| count = 21 | |
| for comm in os.listdir('./Dataset/'+str(files)): | |
| sound = AudioSegment.from_file('./Dataset/'+str(files)+'/'+str(comm)) | |
| halfway_point = len(sound) // 2 | |
| for _ in range(10): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyaudio | |
| import wave | |
| import warnings | |
| warnings.filterwarnings(action='ignore',category=FutureWarning) | |
| CHUNK = 256 | |
| FORMAT = pyaudio.paInt16 | |
| CHANNELS = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from google.colab import drive | |
| drive.mount('/content/drive') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## K Nearest Neighbors | |
| y_pred_knn = [] | |
| ## Iterate through each value in test data | |
| for val in x_test: | |
| euc_dis = [] | |
| ## Finding eucledian distance for all points in training data | |
| for point in x_train: | |
| euc_dis.append(((val[0]-point[0])**2+(val[1]-point[1])**2)**0.5) | |
| temp_target = y_train.tolist() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.neighbors import KNeighborsClassifier | |
| from sklearn.metrics import accuracy_score | |
| ## We take a range of values for K(1 to 20) and find the accuracy | |
| ## so that we can visualize how accuracy changes based on value of K | |
| accuracy = [] | |
| for n in range(1,21): | |
| clf = KNeighborsClassifier(n_neighbors = n) | |
| clf.fit(x_train,y_train) | |
| y_pred = clf.predict(x_test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from sklearn.cross_validation import train_test_split | |
| ## Retrieve features | |
| X = df.values.tolist() | |
| Y = [] | |
| ## Convert classes in Strings to Integers | |
| for val in target: | |
| if(val == 'Iris-setosa'): | |
| Y.append(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| points_1 = df[0:50].values.tolist() | |
| points_2 = df[50:100].values.tolist() | |
| points_3 = df[100:].values.tolist() | |
| points_1 = np.array(points_1) | |
| points_2 = np.array(points_2) | |
| points_3 = np.array(points_3) |