text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import accuracy_score

from sklearn.metrics import log_loss

from sklearn.metrics import roc_auc_score

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.tree import  DecisionTreeClassifier

import lightgbm as lgb

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')

train.isnull().sum()

test.isnull().sum()

train.replace({'Sex': {'male': 0, 'female': 1}}, inplace=True)
test.replace({'Sex': {'male': 0, 'female': 1}}, inplace=True)

#先ほどの五段階の評価をビジュアライズ
f ,ax = plt.subplots()
train['Age'].value_counts().plot.bar()

train.groupby('Embarked').size()

test.groupby('Embarked').size()

train.replace({'Embarked': {'C': 0, 'Q': 1, 'S': 2}}, inplace=True)
test.replace({'Embarked': {'C': 0, 'Q': 1, 'S': 2}}, inplace=True)

train = train.drop(columns=['PassengerId', 'Name', 'Ticket', 'Cabin'])
test = test.drop(columns=['PassengerId', 'Name', 'Ticket', 'Cabin'])

train = train.astype(float)
test = test.astype(float)
train.dtypes
test.dtypes

colormap = plt.cm.RdBu

X = train.drop(columns=['Survived'])
y = train['Survived']
X_test = test
from sklearn.model_selection import train_test_split
X_train, X_val, y_train, y_val = train_test_split(X, y, train_size=0.8, random_state=0)

import sklearn
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train)

from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier(criterion='entropy', max_depth=5, random_state=0)
model.fit(X_train, y_train)

from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)

import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import log_loss
from sklearn.metrics import roc_auc_score
model = lgb.LGBMClassifier()
model.fit(X_train, y_train)
y_pred = model.predict(X_val)
y_pred_prob = model.predict_proba(X_val)
acc = accuracy_score(y_val, y_pred)
logloss = log_loss(y_val, y_pred_prob)
auc = roc_auc_score(y_val, y_pred_prob[:, 1])

y_pred_1 = model.predict(X_test)
print(y_pred_1.shape)