<jupyter_start><jupyter_text>kaggle kernel  日本語用パッケージ<jupyter_code>!pip install japanize-matplotlib<jupyter_output>Requirement already satisfied: japanize-matplotlib in /opt/conda/lib/python3.6/site-packages (1.0.4)
[33mYou are using pip version 19.0.3, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.[0m<jupyter_text>可視化用<jupyter_code># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python

import numpy as np
import pandas as pd
import pandas_profiling
import matplotlib.pyplot as plt
import seaborn as sns
import japanize_matplotlib

%matplotlib inline<jupyter_output><empty_output><jupyter_text>確認<jupyter_code>plt.bar(list("あいう"), [1,2,3])<jupyter_output><empty_output><jupyter_text>logging<jupyter_code>from logging import getLogger, DEBUG, INFO, FileHandler, StreamHandler, Formatter

def get_logger(module_name, log_path, level=DEBUG):
    logger = getLogger(module_name)
    fmt = '%(asctime)s %(name)s %(lineno)04d [%(levelname)s][%(funcName)s] %(message)s'
    formatter = Formatter(fmt)

    fh = FileHandler(log_path, mode='a')
    fh.setLevel(level)
    fh.setFormatter(formatter)

    sh = StreamHandler()
    sh.setLevel(INFO)
    sh.setFormatter(formatter)

    logger.setLevel(DEBUG)
    logger.addHandler(fh)
    logger.addHandler(sh)
    
    return logger

log_path = 'test1.log'
logger = get_logger(__name__, log_path)
logger.info('aaa')<jupyter_output>2019-05-01 11:46:59,509 __main__ 0024 [INFO][<module>] aaa<jupyter_text>load data<jupyter_code>ls ../input/
train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')
sample_submission = pd.read_csv('../input/gender_submission.csv')<jupyter_output><empty_output><jupyter_text>EDA<jupyter_code>report_train = pandas_profiling.ProfileReport(train)
report_test = pandas_profiling.ProfileReport(test)

report_train
report_test<jupyter_output><empty_output><jupyter_text>preprocessing<jupyter_code>xy_train = train.drop('PassengerId', axis=1).select_dtypes(include=[np.number])
null_cols = xy_train.isnull().sum().rename('n_null').to_frame().query('n_null > 0').index.tolist()
X_train = xy_train.drop(null_cols + ['Survived'], axis=1)
y_train = xy_train.loc[:, 'Survived']

X_test = test.loc[:, X_train.columns]

X_train.columns
X_test.isnull().sum()
X_test.fillna(X_test.mean(), inplace=True)<jupyter_output><empty_output><jupyter_text>training<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, GridSearchCV, ParameterGrid
from sklearn.metrics import accuracy_score, log_loss, roc_auc_score

clf = LogisticRegression(random_state=0)
clf.get_params()
params = {
    'C': [0.01, 0.1, 1, 10],
    'random_state': [0,1,2],
    'penalty': ['l1', 'l2'],
}
fold = StratifiedKFold(n_splits=5, random_state=0)
gcv = GridSearchCV(clf, params, scoring='accuracy', cv=fold)
gcv.fit(X_train, y_train)
gcv.best_score_, gcv.best_estimator_
pd.DataFrame(gcv.cv_results_)<jupyter_output>/opt/conda/lib/python3.6/site-packages/sklearn/utils/deprecation.py:125: FutureWarning: You are accessing a training score ('split0_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True
  warnings.warn(*warn_args, **warn_kwargs)
/opt/conda/lib/python3.6/site-packages/sklearn/utils/deprecation.py:125: FutureWarning: You are accessing a training score ('split1_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True
  warnings.warn(*warn_args, **warn_kwargs)
/opt/conda/lib/python3.6/site-packages/sklearn/utils/deprecation.py:125: FutureWarning: You are accessing a training score ('split2_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True
  warnings.warn(*warn_args, **warn_kwargs)
/opt/conda/lib/python3.6/site-packages/sklearn/utils/deprecation.py[...]<jupyter_text>submission<jupyter_code>sample_submission.columns
pred = gcv.best_estimator_.predict(X_test)
pd.DataFrame({
    'PassengerId': test.PassengerId,
    'Survived': pred,
}).to_csv('notnull_features.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12855146716348392, 'fraction_numerical': 0.02095947834187238, 'mean_word_length': 6.6559714795008915, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 36, 'https://': 1, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '68513', 'license': 'MIT', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1555, 'n_words': 285, 'path': 'example_projects/kaggle-titanic/notebooks/kernel-notnull-features-logistic-regression.ipynb', 'repo_name': 'ksomemo/kaggle-template', 'size': '4294'}