1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# url mush_data_url = "http://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data" s = requests.get(mush_data_url).content # データの形式変換 mush_data = pd.read_csv(io.StringIO(s.decode('utf-8')), header=None) # データに名前をつける(データを扱いやすくするため) mush_data.columns = ["classes", "cap_shape", "cap_surface", "cap_color", "odor", "bruises", "gill_attachment", "gill_spacing", "gill_size", "gill_color", "stalk_shape", "stalk_root", "stalk_surface_above_ring", "stalk_surface_below_ring", "stalk_color_above_ring", "stalk_color_below_ring", "veil_type", "veil_color", "ring_number", "ring_type", "spore_print_color", "population", "habitat"] # カテゴリー変数(色の種類など数字の大小が決められないもの)をダミー特徴量(yes or no)として変換する mush_data_dummy = pd.get_dummies( mush_data[['gill_color', 'gill_attachment', 'odor', 'cap_color']]) print(mush_data) # 目的変数:flg立てをする mush_data_dummy["flg"] = mush_data["classes"].map( lambda x: 1 if x == 'p' else 0) # 説明変数と目的変数 X = mush_data_dummy.drop("flg", axis=1) Y = mush_data_dummy['flg'] |
コメントを残す