<jupyter_start><jupyter_text>パッケージの読み込み<jupyter_code>import os
# 数値処理
import numpy as np
import pandas as pd
from sklearn.preprocessing import PolynomialFeatures

# グラフ描画
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Meiryo'<jupyter_output><empty_output><jupyter_text>前処理 データの読み込み<jupyter_code># データの配置場所
input_dir = 'C:/Users/rhira/Documents/GitHub'\
            '/signate-competition-Liver-disease-beginner/data/input'
# トレーニングデータ
train = pd.read_csv(os.path.join(input_dir[:], 'train.csv'))
# テストデータ
test = pd.read_csv(os.path.join(input_dir[:], 'test.csv'))<jupyter_output><empty_output><jupyter_text>特徴量とターゲットに分離<jupyter_code># トレーニングデータからターゲットをドロップ
train_feature = train.drop(['disease'], axis=1)
# トレーニングデータからターゲットを抽出
train_target = train['disease']<jupyter_output><empty_output><jupyter_text>特徴量の結合<jupyter_code># 縦方向に結合
feature = pd.concat([train_feature, test], axis=0)<jupyter_output><empty_output><jupyter_text>ダミー変数化<jupyter_code>feature_dummy = pd.get_dummies(feature, drop_first=True)<jupyter_output><empty_output><jupyter_text>交互作用項の追加<jupyter_code># 2次の交互作用
quadratic = PolynomialFeatures(degree = 2, include_bias = False)
feature_quadratic = pd.DataFrame(quadratic.fit_transform(feature_dummy),
                                 columns=quadratic.get_feature_names(feature_dummy.columns))
# 3次の交互作用
cubic = PolynomialFeatures(degree = 3, include_bias = False)
feature_cubic = pd.DataFrame(cubic.fit_transform(feature_dummy),
                             columns=cubic.get_feature_names(feature_dummy.columns))<jupyter_output><empty_output><jupyter_text>データの保存  特徴量の分割<jupyter_code># 交互作用無
train_dummied = feature_dummy[:len(train)].reset_index(drop=True)
test_dummied = feature_dummy[len(train):].reset_index(drop=True)
# 2次交互作用
train_quadratic = feature_quadratic[:len(train)] .reset_index(drop=True)
test_quadratic = feature_quadratic[len(train):].reset_index(drop=True)
# 3次交互作用
train_cubic = feature_cubic[:len(train)].reset_index(drop=True)
test_cubic = feature_cubic[len(train):].reset_index(drop=True)<jupyter_output><empty_output><jupyter_text>保存<jupyter_code># データの配置場所
output_dir = 'C:/Users/rhira/Documents/GitHub'\
             '/signate-competition-Liver-disease-beginner/features'

# 出力
# 交互作用無
train_dummied.to_feather(os.path.join(output_dir, 'train_dummied_feature.feather'))
test_dummied.to_feather(os.path.join(output_dir, 'test_dummied_feature.feather'))
# 2次交互作用
feature_quadratic.to_feather(os.path.join(output_dir, 'train_qiadratic_feature.feather'))
test_quadratic.to_feather(os.path.join(output_dir, 'test_quadratic_feature.feather'))
# 3次交互作用
train_cubic.to_feather(os.path.join(output_dir, 'train_cubic_feature.feather'))
test_cubic.to_feather(os.path.join(output_dir, 'test_cubic_feature.feather'))
# ターゲット
pd.DataFrame(train_target).to_feather(os.path.join(output_dir, 'train_target.feather'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12640929279125385, 'fraction_numerical': 0.0034164673727365906, 'mean_word_length': 8.15, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '158493', 'license': 'MIT', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1273, 'n_words': 113, 'path': 'notebooks/.ipynb_checkpoints/preprocess-checkpoint.ipynb', 'repo_name': 'Data-Anal-Ojisan/signate-competition-Liver-disease-beginner', 'size': '2927'}