로지스틱 회귀 (데이터 전처리 관련)

조회수 661회

안녕하세요.! 지금 로지스틱 회귀 배우고 있는데, 모델을 만들기전 데이터 전처리를 어떻게 해야할지 감이 안잡혀서 글 남깁니다.

일단 코드는 아래와 같이 작성해 봤는데, 정확도를 더 높일 방법이 있을까요? 처음이라서 제가 지금 뭘 하고있는지 대충은 알겠는데 정확히는 또 모르겠네요... ㅠㅠ

  • 아래는 풀고있는 문제 내용입니다... An automated answer-rating site marks each post in a community forum website as “good” or “bad” based on the quality of the post. The CSV file, which you can download from OA 9.14, contains the various types of quality as measured by the tool. Following are the type of qualities that the dataset contains: i. num_words: number of words in the post ii. num_characters: number of characters in the post iii. num_misspelled: number of misspelled words iv. bin_end_qmark: if the post ends with a question mark v. num_interrogative: number of interrogative words in the post vi. bin_start_small: if the answer starts with a lowercase letter (“1” means yes, otherwise no) vii. num_sentences: number of sentences per post viii. num_punctuations: number of punctuation symbols in the post ix. label: the label of the post (“G” for good and “B” for bad) as determined by the tool. Create a logistics regression model to predict the class label from the first eight attributes of the question set. Evaluate the accuracy of your model.

이건 quality.csv 파일 이고요 https://github.com/nam14d/imt574_conglomorate/blob/806fd329af1672e08827367ba044263703bcee49/Assignment3_wine_quality/quality.csv

이건 제가 지금까지 작성한 코드입니다,,!

import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt

qual = pd.read_csv("./quality.csv")
## Log Regression Model - X: First Eight
qual['label'] = np.where(qual['label'] == 'B', 0, 1)
X = qual.drop(['S.No.','label'], axis=1)
X_normalized = X.apply(lambda x: (x-min(x))/max(x)-min(x))
y = qual['label']
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,test_size = 0.2)

logmod = LogisticRegression()
logmod.fit(Xtrain, ytrain)

predictions = logmod.predict(Xtest)

print(accuracy_score(ytest, predictions))

1 답변

  • augmentation 이라는 게 있는데요,

    예를 들어 이미지 분류를 할 때, 그림에 노이즈/회전/대칭 연산을 해주는건 데이터 라벨을 바꾸지 않으면서 데이터 갯수를 늘릴 수 있어요.

    질문자님 데이터에서 생각해보면 num_characters 가 ±1~2 정도 살짝 바뀌어도 라벨 (G/B) 이 안바뀔거라 가정할 수 있겠습니다.

    그러면 num_characters 만 약간 변형시킨 데이터를 추가시켜서 데이터양을 2~3배 뻥튀기 할 수 있습니다.

    augmentation 에 대해선 https://www.tensorflow.org/tutorials/images/data_augmentation?hl=ko 여기를 더 참고하시면 좋을 것 같습니다.

    물론 위 가정이 잘 들어맞지 않으면 accuracy 에 도움이 안될 수 있습니다..

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)