728x90

Machine Learning 6

[Machine Learning] SMOTETomek

- SMOTETomek? Combination of over - and under - sampling method SMOTE의 방법과 TomekLink를 복합하여 진행하는 것 SMOTE로 over sampling 진행 후 경계선에 있는 major sample을 제거 분류 경계면을 뚜렷하게하여 분류가 잘 될 수 있도록 한다. - Import import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.datasets import make_classification from imblearn.under_sampling import TomekLinks from imblearn.combine import SMOTETom..

Machine Learning 2022.11.23

[Machine Learning] imblearn 라이브러리 undersampling

imblearn라이브러리의 under_sampling 비교 - Import import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.datasets import make_classification from imblearn.under_sampling import * - Data 생성 X, y = make_classification(n_samples=5000, n_features=2, n_informative=2, n_redundant=0, n_repeated=0, n_classes=3, n_clusters_per_class=1, weights=[0.2, 0.3, 0.5], class_sep=0.8, rando..

Machine Learning 2022.11.21

[Machine Learning] imblearn 라이브러리 oversampling

imblearn라이브러리의 over_sampling 비교 - Import import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.datasets import make_classification from imblearn.over_sampling import * - Data 생성 X, y = make_classification(n_samples=5000, n_features=2, n_informative=2, n_redundant=0, n_repeated=0, n_classes=3, n_clusters_per_class=1, weights=[0.01, 0.05, 0.94], class_sep=0.8, rand..

Machine Learning 2022.11.18

[Machine Learning]PCA로 cluster 그래프 그리기

다차원의 변수를 2차원의 그래프로 나타내기 위해서는 PCA를 사용해야 합니다. 오늘은 PCA로 변수를 압축 후 target이 잘 분리되어 있는지 그래프로 나타내겠습니다. - Data Load 및 Import iris data를 사용하여 진행하겠습니다. import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.datasets import load_iris from sklearn.decomposition import PCA data = load_iris() 이 data는 dictionary 형태로 되어 있으며, keys를 통해 어떤 데이터 항목이 있는지 알 수 있습니다. data.keys() >>> dict_k..

Machine Learning 2022.11.11

[Machin Learning]변수 중요도를 기준으로 Kfold 교차검증 진행하기

변수 중요도를 기준으로 변수를 하나씩 늘려가며 Kfold 교차검증을 진행하는 코드입니다. 모듈 import 및 data load from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split, StratifiedKFold import pandas as pd # data load df = pd.read_csv('train.csv') trian set 설정 # object column 제외 df = df.select_dtypes(exclude= 'object') # Nan 값 평균 값으로 처리 df.filln..

Machine Learning 2022.11.01

[Machine Learning]변수 중요도 출력(feature importance)

학습 데이터 중 모든 변수를 사용하면 노이즈 데이터가 섞여서 모델 성능이 잘 나오지 않을 수 있습니다. 모델 성능을 높이기 위해 변수를 선택하는 과정을 거쳐야 하는데, 변수 중요도를 활용하여 선택하는 방법이 있습니다. RandomForest를 이용하여 titanic데이터를 학습한 후 변수 중요도를 출력하겠습니다. 먼저, titanic 데이터를 불러와줍니다. import pandas as pd df = pd.read_csv('train.csv') df.head() RandomForest를 이용하여 학습을 진행합니다. 학습을 위해 object column은 사용하지 않습니다. Nan 값은 평균값으로 처리해줍니다. # object column 제외 df = df.select_dtypes(exclude= 'ob..

Machine Learning 2022.11.01
728x90