<jupyter_start><jupyter_text>両チームの最大レベルは？<jupyter_code>pd.concat([train_data['A1-level'], train_data['A2-level'], train_data['A3-level'], train_data['A4-level'], train_data['B1-level'], train_data['B2-level'], train_data['B3-level'], train_data['B4-level']]).max()
train_data['A1-level']
train_data.sort_values('A1-level', ascending=False)['A1-level'][:10]
from sklearn.preprocessing import MultiLabelBinarizer
mlb = MultiLabelBinarizer()
mlb.fit([set(train_data['A1-weapon'].unique())])
MultiLabelBinarizer(classes=None, sparse_output=False)
def trans_weapon(df, columns=['A1-weapon', 'A2-weapon', 'A3-weapon', 'A4-weapon']):
    weapon = df.fillna('none') 
    weapon_binarized = mlb.transform(weapon[columns].values)
    return pd.DataFrame(weapon_binarized, columns=mlb.classes_)

def make_input_output(df, with_y=False):
    a_weapon = trans_weapon(df, ['A1-weapon', 'A2-weapon', 'A3-weapon', 'A4-weapon'])
    b_weapon = trans_weapon(df, ['B1-weapon', 'B2-weapon', 'B3-weapon', 'B4-weapon'])
    X = pd.concat([a_weapon, b_weapon], axis=1)
    if with_y:
        y = df['y']
        return X, y, a_weapon, b_weapon
    return X, a_weapon, b_weapon
X, y, a_weapon, b_weapon = make_input_output(train_data, with_y=True)
X
X.info()
a_weapon
b_weapon
X.shape
X['splatroller']
X['splatroller']
#scikit-learnライブラリをimport
import sklearn
from sklearn.ensemble import RandomForestClassifier

#線形回帰モデルのインスタンス化
model = RandomForestClassifier()

#予測モデルの作成
model.fit(X, y)
list(reversed(sorted(list(zip(model.feature_importances_, X.columns)))))[:10]

# accuracyの出力
from sklearn.metrics import accuracy_score
y_true = y
y_pred = model.predict(X)
print(accuracy_score(y_true, y_pred))
path_test = "data/test_data.csv"
test_data = pd.read_csv(path_test, index_col='id')
test_data.head()
test_X, _, _ = make_input_output(test_data)
#テスト結果の出力
test_predicted = model.predict(test_X)
submit_df = pd.DataFrame({'y': test_predicted})
submit_df.index.name = 'id'
submit_df.to_csv('tuto_submission.csv')
train_data['game-ver'].unique()
train_data['lobby-mode'].unique()
train_data['lobby'].unique()
train_data['mode'].unique()
train_data['stage'].unique()
pd.concat([train_data['A1-level'], train_data['A2-level'], train_data['A3-level'], train_data['A4-level'], train_data['B1-level'], train_data['B2-level'], train_data['B3-level'], train_data['B4-level']]).max()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1753574432296047, 'fraction_numerical': 0.015559293523969722, 'mean_word_length': 7.526881720430108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '492734', 'license': 'MIT', 'n_tokens_mistral': 981, 'n_tokens_neox': 978, 'n_words': 134, 'path': 'tutorial.ipynb', 'repo_name': 'abekoh/splatoon_game_winner', 'size': '2378'}