Here is my Baseline Model. 
def create\_dataset(data):
 down\_N = 25
 Num\_els = 13
 #iterate through all files and downsample
 for i in range(len(data)):
 #get the signal and extract mel
 x, sr = librosa.load(data.iloc[i]["file"], sr=SAMPLING\_RATE)
 melspectrogram = extract\_melspectrogram(x, sr, num\_mels=Num\_els)

 #handle cases with less than N by padding
 if(melspectrogram.shape[1] < down\_N):
 #need to pad, get padding width
 pad\_width = down\_N - melspectrogram.shape[1]
 if(pad\_width%2==0):
 left\_pad = pad\_width//2
 right\_pad = pad\_width//2
 else:
 left\_pad = pad\_width//2 + 1 
 right\_pad = pad\_width//2

 #perform padding
 melspectrogram = np.pad( melspectrogram, ((0,0), (left\_pad,right\_pad)), mode='symmetric')

 #downsample the mel spectrogram
 downsample\_mel = downsample\_spectrogram(melspectrogram, down\_N)
 downsample\_mel = downsample\_mel.flatten()
 downsample\_mel = np.expand\_dims(downsample\_mel, axis=0)
 
 if i==0:
 inputs = downsample\_mel
 labels = data.iloc[i]["label"]
 else:
 inputs = np.concatenate( (inputs, downsample\_mel) )
 labels = np.append(labels, data.iloc[i]["label"])
 
 return (inputs, labels)

# prepare data and split 
train\_filt = (sdr\_df["split"] == "TRAIN")
dev\_filt = (sdr\_df["split"] == "DEV")
test\_filt = (sdr\_df["split"] == "TEST")

#datasets
X\_train, y\_train = create\_dataset(sdr\_df[train\_filt])
X\_dev, y\_dev = create\_dataset(sdr\_df[dev\_filt])
X\_test, y\_test = create\_dataset(sdr\_df[test\_filt])

from sklearn.pipeline import make\_pipeline
from sklearn.linear\_model import LogisticRegression

def fit\_(loss, data, label, alpha=0.0001, classifier='sgd', normalise=False):
 if classifier=='sgd':
 lin\_clf = SGDClassifier(loss=loss, alpha=alpha, tol=1e-5)
 elif classifier =='logistic':
 lin\_clf = LogisticRegression(penalty='elasticnet', C=alpha, tol=1e-5, solver='saga', l1\_ratio=0.2)
 else:
 raise NotImplemented
 
 if normalise:
 clf = make\_pipeline(StandardScaler(), lin\_clf)
 else:
 clf = make\_pipeline(lin\_clf)
 
 clf.fit(data, label)
 return clf

def predict\_(model, data, label, dttype):
 pred = model.predict(data)
 acc = accuracy\_score(label, pred)
 
 print(f"{dttype} accuracy is {acc\*100:.4f}%")
 return acc

# train a linear model - sgd 
svm\_hinge = fit\_("hinge", X\_train, y\_train, alpha=0.1, classifier='sgd', normalise=False) # log 0.03/hinge 0.1
train\_acc = predict\_(svm\_hinge, X\_train, y\_train,"Train") # normalisation was surprisingly not that useful
 # most data features have similar range
test\_acc = predict\_(svm\_hinge, X\_dev, y\_dev,"Dev")
test\_acc = predict\_(svm\_hinge, X\_test, y\_test,"Test")

#train a linear model - logistic
# train a linear model - sgd 
logisitic = fit\_("hinge", X\_train, y\_train, alpha=0.1, classifier='logistic', normalise=True)
train\_acc = predict\_(logisitic, X\_train, y\_train,"Train")
test\_acc = predict\_(logisitic, X\_dev, y\_dev,"Dev")
test\_acc = predict\_(logisitic, X\_test, y\_test,"Test")

def get\_confusion(model, data, label):
 pred = model.predict(data)
 mat = confusion\_matrix(label, pred)
 return mat

from sklearn.metrics import ConfusionMatrixDisplay

def plot\_confusion(model):
 fig = plt.figure()
 fig.set\_size\_inches(20,6)
 ax1 = fig.add\_subplot(131)
 disp1 = ConfusionMatrixDisplay(get\_confusion(model, X\_train, y\_train))
 disp1.plot(ax=ax1)
 disp1.ax\_.set\_title("Train Confusion Matrix")

 ax2 = fig.add\_subplot(132)
 disp2 = ConfusionMatrixDisplay(get\_confusion(model, X\_dev, y\_dev))
 disp2.plot(ax=ax2)
 disp2.ax\_.set\_title("Dev Confusion Matrix")

 ax3 = fig.add\_subplot(133)
 disp3 = ConfusionMatrixDisplay(get\_confusion(model, X\_test, y\_test))
 disp3.plot(ax=ax3)
 disp3.ax\_.set\_title("Test Confusion Matrix")

plot\_confusion(svm\_hinge)
"""
Confusion matrix for SGD classifier with hinge loss
"""

plot\_confusion(logisitic)
"""
Confusion matrix for logistic regression
"""

a = classification\_report(y\_test, svm\_hinge.predict(X\_test), output\_dict=True)
pd.DataFrame.from\_dict(a).transpose()
제 기준 모델은 다음과 같습니다. def create\_dataset(data): down\_N = 25 Num\_els = 13 #모든 파일과 다운샘플링을 반복합니다. for i in range(len(data)): #신호 가져와 멜 추출 x, sr = librosa.load(data.iloc[i]["file"], sr=SAMPLING\_RATE) 멜스펙트로그램 = extract\_melspectrogram(x, sr, num\_mels=Num\_els) #패딩으로 N보다 작은 경우 처리하기 if(melspectrogram.shape[1] < down\_N): #패딩 필요, 패딩 너비 구하기 pad\_width = down\_N - melspectrogram.shape[1] if(pad\_width%2==0): left\_pad = pad\_width//2 오른쪽\_pad = pad\_width//2 else: 좌측\_패드 = 패드\_폭//2 + 1  오른쪽\_패드 = 패드\_폭//2 #패딩 수행 melspectrogram = np.pad( melspectrogram, ((0,0), (left\_pad,right\_pad)), mode='symmetric') 멜 스펙트로그램을 #다운샘플링합니다. downsample\_mel = downsample\_spectrogram(melspectrogram, down\_N) downsample\_mel = downsample\_mel.flatten() downsample\_mel = np.expand\_dims(downsample\_mel, axis=0)  if i==0: 입력 = 다운샘플\_mel labels = data.iloc[i]["label"] else: 입력 = np.concatenate( (입력, 다운샘플\_mel) ) labels = np.append(labels, data.iloc[i]["label"])  반환 (입력, 레이블)# 데이터 준비 및 분할 train\_filt = (sdr\_df["split"] == "TRAIN")dev\_filt = (sdr\_df["split"] == "DEV")test\_filt = (sdr\_df["split"] == "TEST")#데이터 세트X\_train, y\_train = create\_dataset(sdr\_df[train\_filt])X\_dev, y\_dev = create\_dataset(sdr\_df[dev\_filt])X\_test, y\_test = create\_dataset(sdr\_df[test\_filt])sklearn.pipeline에서 make\_pipeline 가져오기sklearn.linear\_model에서 LogisticRegression을 가져옵니다.def fit\_(손실, 데이터, 레이블, 알파=0.0001, 분류자='sgd', 정규화=False): IF CLASSIFIER=='SGD': lin\_clf = SGDClassifier(손실=손실, 알파=알파, 톨=1e-5) elif classifier =='logistic': lin\_clf = LogisticRegression(penalty='elasticnet', C=alpha, tol=1e-5, solver='saga', l1\_ratio=0.2) else: NotImplemented 제기  를 반환합니다: clf = make\_pipeline(StandardScaler(), lin\_clf) else: clf = make\_pipeline(lin\_clf)  clf.fit(데이터, 레이블) return clfdef predict\_(모델, 데이터, 레이블, dttype): pred = model.predict(data) acc = 정확도\_score(label, pred)  print(f"{dttype} 정확도는 {acc\*100:.4f}%입니다.") 반환 acc# 선형 모델 훈련 - sgd svm\_hinge = fit\_("hinge", X\_train, y\_train, alpha=0.1, classifier='sgd', normalise=False) # log 0.03/hinge 0.1train\_acc = predict\_(svm\_hinge, X\_train, y\_train,"Train") # 정규화는 의외로 그다지 유용하지 않았습니다. # 대부분의 데이터 특징은 비슷한 범위를 가집니다.test\_acc = predict\_(svm\_hinge, X\_dev, y\_dev,"Dev")test\_acc = predict\_(svm\_hinge, X\_test, y\_test,"Test")#선형 모델 훈련 - 로지스틱# 선형 모델 훈련 - sgd logisitic = fit\_("hinge", X\_train, y\_train, alpha=0.1, classifier='logistic', normalise=True)train\_acc = predict\_(로지스틱, X\_train, y\_train,"Train")test\_acc = predict\_(logisitic, X\_dev, y\_dev,"Dev")test\_acc = predict\_(logisitic, X\_test, y\_test,"Test")def get\_confusion(모델, 데이터, 레이블): pred = model.predict(data) mat = confusion\_matrix(label, pred) 반환 matsklearn.metrics에서 ConfusionMatrixDisplay 가져오기def plot\_confusion(model): fig = plt.figure() fig.set\_size\_inches(20,6) ax1 = fig.add\_subplot(131) disp1 = ConfusionMatrixDisplay(get\_confusion(model, X\_train, y\_train)) disp1.plot(ax=ax1) disp1.ax\_.set\_title("기차 혼동 행렬") ax2 = fig.add\_subplot(132) disp2 = ConfusionMatrixDisplay(get\_confusion(model, X\_dev, y\_dev)) disp2.plot(ax=ax2) disp2.ax\_.set\_title("개발 혼동 행렬") ax3 = fig.add\_subplot(133) disp3 = ConfusionMatrixDisplay(get\_confusion(model, X\_test, y\_test)) disp3.plot(ax=ax3) disp3.ax\_.set\_title("혼동 행렬 테스트")plot\_confusion(svm\_hinge)"""힌지 손실이 있는 SGD 분류기에 대한 혼동 행렬"""plot\_confusion(logisitic)"""로지스틱 회귀를 위한 혼동 행렬"""a = classification\_report(y\_test, svm\_hinge.predict(X\_test), output\_dict=True)pd.DataFrame.from\_dict(a).transpose()