# -*- coding: utf-8 -*-
"""3-4_생각해보기_코드.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1yroosfkhzg7IJL3kBBhb5tCU5T99ZVNU

# Scikit-learn을 활용한 모델 구현

## 데이터 불러오기
"""

import numpy as np
import librosa

X_train=np.zeros((40,20))
y_train=np.zeros(40)
y_train[0:20] = 1

#hungry_특징추출 for문
for i in range(20):
  audio_path = '/content/hungry_'+str(i+1)+'.wav'
  y, sr = librosa.load(audio_path)
  mfcc= librosa.feature.mfcc(y=y, sr=sr)
  temp=mfcc.mean(axis=1)
  #인덱스번호 0~19번까지 
  X_train[i]=temp

#laugh_특징추출 for문
for i in range(20):
  audio_path = '/content/laugh_'+str(i+1)+'.wav'
  y, sr = librosa.load(audio_path)
  mfcc= librosa.feature.mfcc(y=y, sr=sr)
  temp=mfcc.mean(axis=1)
  #인덱스번호 20~39번까지 
  X_train[i+20]=temp

#데이터 셋
data_sets=np.zeros((40,21))
data_sets[:,0:20]=X_train
data_sets[:,20]=y_train

from sklearn.model_selection import train_test_split
from sklearn import preprocessing

df_train, df_test = train_test_split(data_sets, test_size=0.2, random_state=1)

#학습(train) 데이터를 입력변수와 출력변수로 나누기
data_train = np.array(df_train)

X_train= data_train[:,0:20] 
X_ntrain = preprocessing.normalize(X_train, norm='l2')
y_train = data_train[:,20]

#테스트(test)데이터 준비하기
data_test = np.array(df_test)

X_test= data_test[:,0:20] 
X_ntest = preprocessing.normalize(X_test, norm='l2')
y_test = data_test[:,20]

"""# 학습하기"""

from sklearn.linear_model import LogisticRegression

my_model = LogisticRegression(solver='saga',max_iter=10000).fit(X_train,y_train)

"""# 성능 테스트하기"""

print(my_model.score(X_train,y_train))
print(my_model.score(X_test,y_test))