aux = [] for i in x[0]: a['aux_{}'.format(contador)].append(i) contador += 1 for i in x[1]: a['aux_{}'.format(contador)].append(i) contador += 1 Y_train.append(x[2]) df = pd.DataFrame( (zip(a['aux_0'], a['aux_1'], a['aux_2'], a['aux_3'], a['aux_4'], a['aux_5'], a['aux_6'], a['aux_7'], a['aux_8'], a['aux_9'], a['aux_10'], a['aux_11'], a['aux_12'], a['aux_13'], a['aux_14'], a['aux_15'], a['aux_16'], a['aux_17'], Y_train)), columns=[ 'Eyebrow Distribution 1', 'Eyebrow Shape 1', 'Eyebrow Size 1', 'Eyelashes Size 1', 'Eyelids Shape 1', 'Iris Color 1', 'Skin Texture 1', 'Skin Color 1', 'Spots 1', 'Eyebrow Distribution 2', 'Eyebrow Shape 2', 'Eyebrow Size 3', 'Eyelashes Size 2', 'Eyelids Shape 2', 'Iris Color 2', 'Skin Texture 2', 'Skin Color 2', 'Spots 2', 'Decision' ]) if __name__ == '__main__': config = {'algorithm': 'C4.5'} model = chef.fit(df, config) chef.save_model(model, "model.pkl")
print("enableParallelism is set to ", enableParallelism) print("*************************") print("-------------------------") print("ID3 for label encoded features and nominal target:") config = {'algorithm': 'ID3', 'enableParallelism': enableParallelism} model = cb.fit(pd.read_csv("dataset/golf_le.txt"), config) print("-------------------------") print("ID3 for nominal features and nominal target:") config = {'algorithm': 'ID3', 'enableParallelism': enableParallelism} model = cb.fit(pd.read_csv("dataset/golf.txt"), config) cb.save_model(model) print("built model is saved to model.pkl") restored_model = cb.load_model("model.pkl") print("built model is restored from model.pkl") instance = ['Sunny', 'Hot', 'High', 'Weak'] prediction = cb.predict(restored_model, instance) print("prediction for ", instance, "is ", prediction) print("-------------------------") print("ID3 for nominal/numeric features and nominal target:") config = {'algorithm': 'ID3', 'enableParallelism': enableParallelism} model = cb.fit(pd.read_csv("dataset/golf2.txt"), config)
""" 알려진 공격에 대한 attack tree 생성 CART를 이용 1)C4.5로 하고 차후 C5를 사용하여 생성 및 예정 라이브러리 링크 : https://github.com/serengil/chefboost (['ID3', 'C4.5', 'CART', 'CHAID', 'Regression']) """ import pandas as pd from chefboost import Chefboost as chef train_data = pd.read_csv('dataset/pre_train.csv') train_data.rename(columns={'Label': 'Decision'}, inplace=True) #train_data = train_data[(train_data['Decision'] != 'dos') == True] # model 생성 config = {'algorithm': 'C4.5'} model = chef.fit(train_data, config) #모델 저장 chef.save_model(model, "dataset/c45_model.pkl")