<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

%load_ext autoreload
%autoreload 2

np.random.seed(1)


from glob import glob
#directories of normal audios
#norm_data_dir = ‘./audio-processing-files/normals/’
norm_data_dir = '/content/drive/My Drive/data/cats_dogs/train/cat/'
#'F:/sensez9/Audio_ML/data/cats_dogs/train/cat/'
norm_audio_files = glob(norm_data_dir + '*.wav')
#### Get Feature Vector #####

import librosa
from librosa import feature
import numpy as np
fn_list_i = [
 feature.chroma_stft,
 feature.spectral_centroid,
 feature.spectral_bandwidth,
 feature.spectral_rolloff
]


fn_list_ii = [
 feature.rmse,
 feature.zero_crossing_rate
]
def get_feature_vector(y,sr): 
    feat_vect_i = [ np.mean(funct(y,sr)) for funct in fn_list_i]
    feat_vect_ii = [ np.mean(funct(y)) for funct in fn_list_ii] 
    feature_vector = feat_vect_i + feat_vect_ii 
    return feature_vector
norm_audios_feat = []
for file in norm_audio_files:
    y , sr = librosa.load(file,sr=None)
    feature_vector = get_feature_vector(y, sr)
    norm_audios_feat.append(feature_vector)
cat = pd.DataFrame(norm_audios_feat)

cat.head()
#### Testing Data For Cats 



from glob import glob
#directories of normal audios
#norm_data_dir = ‘./audio-processing-files/normals/’
norm_data_dir2 = '/content/drive/My Drive/data/cats_dogs/test/cats/'
#'F:/sensez9/Audio_ML/data/cats_dogs/train/cat/'
norm_audio_files2 = glob(norm_data_dir2 + '*.wav')


norm_audios_feat2 = []
for file in norm_audio_files2:
    y2 , sr2 = librosa.load(file,sr=None)
    feature_vector2 = get_feature_vector(y2, sr2)
    norm_audios_feat2.append(feature_vector2)
    
    
## Dataframe #####


cat_test = pd.DataFrame(norm_audios_feat2)

print(cat_test.shape)
cat_test.head()
### Y train Data Generate #### 

import random
randomlist2 = []
for i in range(0,125):
    n = random.randint(0,1)
    randomlist2.append(n)
print(randomlist2)

Y_train = pd.DataFrame(randomlist2)

print(Y_train.shape)

print(Y_train.head())

#### Y test Data Generate #### 

import random
randomlist = []
for i in range(0,39):
    n = random.randint(0,1)
    randomlist.append(n)
print(randomlist)

Y_test = pd.DataFrame(randomlist)

print(Y_test.shape)

print(Y_test.head())<jupyter_output><empty_output><jupyter_text>Input of X and Y<jupyter_code>#X_train = cat.values
#Y_train = Y_train.values

##X_test = cat_test.values
#Y_test = Y_test.values

print(X_train.shape)
print(Y_train.shape)
print(X_test.shape)
print(Y_test.shape)<jupyter_output>(125, 6)
(125, 1)
(39, 6)
(39, 1)<jupyter_text>**Neural Network With Back Propagation and Update Parameters :**<jupyter_code>def neural_network(w,b,m):
  for i in range(0,1040):
    w, b = initialize_with_zeros(X_train.shape[0])
    m = X.shape[1]

    ### forward Propagation

    A_sig = sigmoid(np.dot(w.T, X_train) + b)
    cost_sig =  (-1 / m) * np.sum(Y_train*np.log(A_sig)+(1-Y_train)*np.log(1-A_sig))
    cost_sig =  cost_sig - 0.25 * i
    print("SigmoiD cost Function", cost_sig)

    ### Back_propagation 

    dw = (1 / m) * np.dot(X_train, (A_sig - Y_train).transpose())/400
    db = (1 / m) * np.sum(A_sig - Y_train)/400

    #### Update Parameter
    learning_rate = 0.025

    w = w + learning_rate * dw  # need to broadcast
    b = b + learning_rate * db
   #print(w,b)

  #### Y_prediction_test #### 

    m2 = X_test.shape[1]
    Y_prediction_test = np.zeros((1, m2))


    for i in range(A_sig.shape[1]):
      Y_prediction_test[0, i] = 1 if A_sig[0, i] >= 0.5 else 0
      print(Y_prediction_test)

     #### Y_prediction_train #### 

      m = X_train.shape[1]
      Y_prediction_train = np.zeros((1, m))


    for i in range(A_sig.shape[1]):
      Y_prediction_train[0, i] = 1 if A_sig[0, i] >= 0.5 else 0

      print(Y_prediction_train)


    # Print train/test Errors
  print("train accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_train - Y_train)) * 100))
  print("test accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_test - Y_test)) * 100))

  

 
neural_network(w,b,m)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14015858208955223, 'fraction_numerical': 0.024953358208955223, 'mean_word_length': 4.1862152357920195, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '426770', 'license': 'MIT', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1690, 'n_words': 325, 'path': 'first_scratch_NN_sesovera_data.ipynb', 'repo_name': 'Reet1992/Deep_learning_R', 'size': '4288'}