티스토리 뷰
반응형
In [55]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
In [56]:
total_set = pd.read_pickle("total_set.pickle")
total_set.head()
Out[56]:
In [57]:
train_data_pre = pd.read_pickle("train_data.pickle")
train_data_pre.head()
Out[57]:
In [58]:
train_data = total_set.iloc[:891, :]
train_data.tail()
Out[58]:
In [59]:
train_data.loc[ : , 'Survived'] = train_data_pre.loc[ : , 'Survived']
train_data.tail()
Out[59]:
In [60]:
test_data = total_set.iloc[891:, :]
test_data.tail()
Out[60]:
In [61]:
train_data.drop('PassengerId', axis=1, inplace=True )
In [62]:
train_data.corr()
Out[62]:
In [63]:
sns.heatmap(train_data.corr(), annot=True, cmap='RdYlGn', linewidth = 0.2 )
fig = plt.gcf()
fig.set_size_inches(10,7)
plt.show()
In [64]:
train_data['Family_size'] = 0
train_data.loc[ : ,'Family_size'] = train_data['SibSp'] + train_data['Parch']
In [65]:
train_data.head()
Out[65]:
In [66]:
train_data['Alone'] = 0
train_data.loc[train_data['Family_size'] ==0 , 'Alone'] =1
In [67]:
train_data['BigFamily'] = 0
train_data.loc[ (train_data['SibSp'] >3 ) | (train_data['Parch'] > 3 ) , 'BigFamily'] = 1
In [68]:
train_data.drop(['SibSp', 'Parch'], axis=1, inplace=True)
In [69]:
train_data.drop(['Family_size'], axis=1, inplace=True)
In [70]:
#titanic_data.drop(['Sex'], axis=1, inplace=True)
In [71]:
sns.factorplot(x='Alone' , y='Survived', data=train_data)
plt.show()
In [72]:
sns.factorplot(x='Fare_value' , y='Survived', data=train_data)
plt.show()
In [73]:
sns.factorplot(x='Age_value' , y='Survived', data=train_data)
plt.show()
In [74]:
train_data.Age_value.replace(
{0:0, 1:1, 2:1, 3:1, 4:1, 5:1,
6:1, 7:1, 8:1, 9:1, 10:1, 11:1,
12:1, 13:2, 14:2, 15:2}, inplace = True
)
In [75]:
sns.factorplot(x='Age_value' , y='Survived', data=train_data)
plt.show()
In [76]:
sns.heatmap(train_data.corr(), annot=True, cmap='RdYlGn', linewidth = 0.2 )
fig = plt.gcf()
fig.set_size_inches(10,7)
plt.show()
In [77]:
train_data.head()
Out[77]:
In [88]:
train_data.to_pickle('final_train')
In [78]:
#titanic_data_test = pd.read_pickle("titanic_data_test.pickle")
test_data.head()
Out[78]:
In [79]:
test_data['Family_size'] = test_data['SibSp'] + test_data['Parch']
In [80]:
test_data['Alone'] = 0
test_data.loc[test_data['Family_size'] ==0 , 'Alone'] =1
In [81]:
test_data['BigFamily'] = 0
test_data.loc[ (test_data['SibSp'] >3 ) | (test_data['Parch'] > 3 ) , 'BigFamily'] =1
In [82]:
test_data.drop(['SibSp', 'Parch'], axis=1, inplace=True)
In [83]:
test_data.drop(['Family_size'], axis=1, inplace=True)
In [521]:
#titanic_data_test.drop(['Sex'], axis=1, inplace=True)
In [84]:
test_data.Age_value.replace(
{0:0, 1:1, 2:1, 3:1, 4:1, 5:1,
6:1, 7:1, 8:1, 9:1, 10:1, 11:1,
12:1, 13:2, 14:2, 15:2}, inplace = True
)
In [85]:
test_data.head()
Out[85]:
In [87]:
test_data.to_pickle('final_test')
In [ ]:
반응형
'머신러닝' 카테고리의 다른 글
[Geocoder] 주소를 위경도로 변환 (0) | 2023.02.27 |
---|---|
Gradient Descent(경사하강법) (0) | 2023.02.09 |
[Ensemble_2] RandomForest (랜덤포레스트) (0) | 2018.11.15 |
[Ensemble_1] Bagging (배깅) (0) | 2018.11.09 |
kaggle 타이타닉 EDA (0) | 2018.10.25 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- dash
- 리치고 주식
- pandas apply
- Dash.html
- 통화량 데이타
- ChatGPT
- 연금등록
- 원계열
- M1M2비율
- 계정조정계열
- 환율이평선
- 연금저축
- 리치고
- 경제주체별 M2
- 마연굴
- Forgiving
- 김성일 작가님
- 위경도변환
- 프로그래스바 표시
- 환매시점
- Dash 와 html 차이
- 블록해쉬구현
- 경제는 어떻게 움직이는가
- 주소를 위경도 변환
- M1/M2
- 객사오
- 환율데이터
- 말잔
- 내 연금조회
- 블록해쉬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함