본문 바로가기
자격증/AICE🎓

[AICE] 머신러닝 분류

by 무명오리 2023. 9. 22.
pip install bs4
pip install openpyxl

 

데이터 수집 : 악성/정상 URI dataset 수집을 통한 raw data 구성

데이터 라벨링 : 외부 API를 이용한 raw data 라벨링

Feature 추출 : 악성/정상 사이트 데이터 정제를 통한 feaure 추출

 

 

중복 데이터 제거

df = df.drop_duplicates()
또는
df.drop_duplicates(inplace=True)

텍스트 범주형 특성 처리

df['class'].unique()
df['class'].replace({'A':1,'B':2}, inplace=True)

결측치 제거

df = df.dropna(axis=0)

불필요한 컬럼 제거

# 기준1 corr()
from sklearn.datasets
import load_iris import pandas as pd

df.corr()
df.corr()["기준컬럼"].sort_values(ascending=False)
# 기준2 scatter 그래프
import matplotlib.pyplot as plt

df['color'] = df['기준컬럼'].map({ 1 :"blue", -1 :"red"})

y_list = df.columns

for i in range(0, len(y_list)):
     df.plot(kind='scatter',x='기준컬럼',y=y_list[i],s=30, c=df['color'])
     plt.title('Scatter Benign Malicious', fontsize=20)
     plt.xlabel('Result_v1')
     plt.ylabel(y_list[i])
     plt.show()
df.drop(columns=["버릴컬럼1", "버릴컬럼2"], inplace=True)
df.info()

train_test_split

from sklearn.model_selection import train_test_split

X = df.iloc[:,0:len(df.columns)-1].values
y = df.iloc[:,len(df.columns)-1].values

train_x, val_x, train_y, val_y = train_test_split(X, y,test_size= 0.3 ,random_state= 42)

train_x.shape, val_x.shape, train_y.shape, val_y.shape

 


confusion matrix
from sklearn.metrics import classification_report as creport
from sklearn.metrics import confusion_matrix, accuracy_score, precision_score, recall_score
 > confusion = confusion_matrix(test_y, dt_pred)
> fig, ax = plt.subplots(figsize=(10,3))
> plot_confusion_matrix(ax, confusion, fontsize=30)

 


모델링 최적화
from sklearn.model_selection import GridSearchCV

rfc_grid.best_score_ : 최고 점수
rfc_grid.best_params_ : 최고 점수를 낸 파라미터
rfc_grid.best_estimator_ : 최고 점수를 낸 파라미터를 가진 모델

 

 

 

 

 

 

 

 

'자격증 > AICE🎓' 카테고리의 다른 글

[AICE] 따끈따끈한 AICE ASSOCIATE 시험 후기 (+소소한 팁)  (1) 2023.10.11
[AICE] 시계열  (1) 2023.10.05
[AICE] 딥러닝  (0) 2023.09.20
[AICE] 머신러닝  (0) 2023.09.19
[AICE] 데이터 전처리  (0) 2023.09.17