Skip to content

Instantly share code, notes, and snippets.

@yumaueno
Last active August 15, 2020 00:04
Show Gist options
  • Save yumaueno/95e9c9b095f56674652a257cd2d2b6f5 to your computer and use it in GitHub Desktop.
Save yumaueno/95e9c9b095f56674652a257cd2d2b6f5 to your computer and use it in GitHub Desktop.
### 1.データ集計・加工・描画
# ライブラリの読み込み
from sklearn import datasets
import pandas as pd
# irisデータの読み込み
iris = datasets.load_iris()
iris
##irisデータの可視化
data_df = pd.DataFrame(iris.data,columns=iris.feature_names)
target_df = pd.DataFrame(iris.target).rename(columns={0:'target'})
data_df.head()
##data_dfの上部5行が表示
data_df.shape
##行列構造が表示される (150,4)
target_df.head()
##target_dfの上部5行が表示
target_df.shape
##行列構造が表示される (150,1)
data_df.describe()
##統計量がカラムごとに表示される
data_df.columns
##カラム名が表示される
target_df['target'].unique()
##目的変数のカテゴリが表示
target_df['target'].value_counts()
##カテゴリごとのデータ数を集計
df = pd.concat([target_df,data_df],axis=1)
df.head()
##目的変数と説明変数を結合して可視化
df.groupby('target')['sepal length (cm)'].mean()
##目的変数でグルーピングして説明変数の平均を取る
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment