4.4.2 Binning : Binning/Converting Numerical Age to Categorical Variable

  • feature vector map:
  • child: 0
  • young: 1
  • adult: 2
  • mid-age: 3
  • senior: 4

4.5 Embarked

4.5.1 filling missing values

>>more than 50% of 1st class are from S embark
>>more than 50% of 2nd class are from S embark
>>more than 50% of 3rd class are from S embark

 

fill out missing embark with S embark

4.6 Fare

4.7 Cabin

4.8 FamilySize

5. Modelling

6.2 Cross Validation (K-fold)

6.2.1 kNN

6.2.2 Decision Tree

6.2.3 Ramdom Forest

6.2.4 Naive Bayes

6.2.5 SVM

7. Testing

References

This notebook is created by learning from the following notebooks:

출처 : https://github.com/minsuk-heo/kaggle-titanic/blob/master/titanic-solution.ipynb

'Kaggle' 카테고리의 다른 글

Kaggle - Titanic(3)  (0) 2020.03.02
Kaggle - Titanic(2)  (0) 2020.03.02
Kaggle - Titanic(1)  (0) 2020.03.02

이번에는 Titanic에서 Feature Engineering을 해보도록 하겠습니다~

4.Feature Engineering

Feature engineering is the process of using domain knowledge of the data to create features (feature vectors) that make machine learning algorithms work. 

feature vector is an n-dimensional vector of numerical features that represent some object.
Many algorithms in machine learning require a numerical representation of objects, since such representations facilitate processing and statistical analysis.

 

 >> 머신러닝을 작동시키는 feature vector를 생성하자~

>>특징 벡터는 일부 객체를 숫자 특징으로 표현한 n 차원 벡터이며, 이는 처리 및 통계 분석을 용이하게하기 때문입니다.

 

4.1 how titanic sank?

sank from the bow of the ship where third class rooms located. conclusion, Pclass is key feature for classifier

4.2 Name

다음처럼 Mr, Miss, Mrs, Others로 4개로 나뉘어 feature vector를 만들어 비교를 설정합니다. 이를 위해서 모든 이름을 분류한 것입니다.

4.3 Sex

4.4 Age

4.4.1 some age is missing. Let's use Title's median age for missing Age

위처럼 나이에 따른 분포를 잘 볼수 있습니다.~^0^

 

Kaggle : https://www.kaggle.com/c/titanic

출처 : https://www.youtube.com/watch?v=FAP7JOECfEE

'Kaggle' 카테고리의 다른 글

Kaggle - Titanic(4)  (0) 2020.04.01
Kaggle - Titanic(2)  (0) 2020.03.02
Kaggle - Titanic(1)  (0) 2020.03.02

두번째는 Visualization을 통해서 자료를 해석해보도록 하겠습니다. ~

자료는 Kaggle의 Titanic Data Machine Learning 과정을 토대로 작성하고 있습니다.!! 

다음의 카테고리를 토대로 Data Feature를 분석하기 위해 bar_chart 함수를 만들어 사용합니다~

Python으로 처음 Data Featuring을 하는 과정을 상세히 설명해보도록 하겠습니다. 먼저 Titanic Disaster에서는 'Survived', 'Dead'로 나뉘기 때문에 특징 분류를 ['Survived','Dead']로 설정하여 진행합니다.

 

Survivied = train[train['Survived']==1][feature].value_counts() >> Survived==1 중에서 feature에 해당되는 counting을 진행.

Dead = train[train['Survived']==0][feature].value_counts() >> Survived==0 중에서 feature에 해당되는 counting을 진행.

 

df = pd.DataFrame([survived, dead]) >> DataFrame을 설정합니다 ['Survived','Dead']

df.index = ['Survived','Dead'] >> survived랑 dead로 인덱스를 설정한다.

df.plot(kind='bar',stacked=True,figsize=(10,5)) >> 종류는 bar , Stacked 방식을 사용 , Figure size는 가로 세로 (10,5)로 설정.

 

함수의 설정이 끝났으니~ 이제 부터 ['Survived','Dead']를 토대로 각 항목을 시각화 화여 의미를 도출할 것이다.

'Sex'에서 ['Survived','Dead']의 분포도 

>> the chart confirms women more likely survived than men

'Pclass'에서 ['Survived','Dead']의 분포도 >>'Sex'에서 ['Survived','Dead']의 분포도

>> The chart confirms 1st class more likely survived than other classes
>> The chart comfirms 3st class more likelt deaded than other classes

'SibSp'에서 ['Survived','Dead']의 분포도 >>'Sex'에서 ['Survived','Dead']의 분포도

>>The Chart confirms a person aboarded with more than 2 siblings or spouse more likely survived
>>The Chart confirms a person aboarded without siblings or spouse more likely dead

'Parch'에서 ['Survived','Dead']의 분포도 >>'Sex'에서 ['Survived','Dead']의 분포도

>>The Chart confirms a person aboarded with more than 2 parents or children more likely survived
>>The Chart confirms a person aboarded alone more likely dead

'Embarked'에서 ['Survived','Dead']의 분포도 >>'Sex'에서 ['Survived','Dead']의 분포도

>>The Chart confirms a person aboarded from C slightly more likely survived
>>The Chart confirms a person aboarded from Q more likely dead
>>The Chart confirms a person aboarded from S more likely dead

 

이처럼 차트를 통해 각 항목에 대해 의미있는 결과를 도출해보도록 했습니다~

Kaggle : https://www.kaggle.com/c/titanic

출처: https://www.youtube.com/watch?v=FAP7JOECfEE

'Kaggle' 카테고리의 다른 글

Kaggle - Titanic(4)  (0) 2020.04.01
Kaggle - Titanic(3)  (0) 2020.03.02
Kaggle - Titanic(1)  (0) 2020.03.02

python에서 데이터를 분석을 하기 위해서 가장 먼저 Data set을 CSV파일 등으로 가지고 와야 한다.

여기서 첫 번째 문법을 알려드리겠습니다.~

Pandas를 이용한 CSV File Read

이렇게 불러온 train, test 파일을 토대로 데이터가 어떠한 정보를 담고 있는지 확인해야겠죠? 그럼 확인해보도록 할게요. 여기서는 head 등의 파일의 구성에 대해 엿볼겁니다.

 

pd_name(Pandas_name).head(number) >>head(self, n=5)

DataFrame 내의 처음 n줄의 데이터를 출력합니다. 이 메서드(method)는 객체 안에 제대로된 데이터 타입이 입력되어있는지 빠르게 확인할 경우 사용하면 매우 유용하다. n의 값의 기본값은 5이며 아무 입력이 없을 경우 5줄을 기본으로 출력한다. 

 

pd_name(Pandas_name).tail() >> tail(self, n=5)

DataFrame 내의 마지막 n줄의 데이터를 출력한다.

이 메서드(method) head와 마찬가지로 객체 내에 데이터 타입 확인하는데 유용하다.

또한 데이터를 정렬 하거나 혹은 데이터를 추가했을 경우 결과를 확인하는데에도 매우 유용하다.

n의 값은 마찬가지로 5이며 아무 입력이 없을 경우 5줄을 기본으로 출력한다. 

 

print(pd_name(Pandas_name)) 

위에서 언급한 head, tail 메서드 말고도 파이썬에서 제공하는 print함수를 사용하는 방법 역시 존재한다.

하지만 광대한 데이터를 취급할 수 있는 pandas의 특성상 취급하는 데이터의 수가 많아지면 데이터를 출력할때 요약하여 출력하게 된다.

 

pd_name(Pandas_name).info()

pd_name(Pandas_name).shape 

pd_name(Pandas_name).index

그 다음으로 중요한 점은 NULL이 포함되어 있는 자료를 확인하는 것입니다. 따라서 우리는 isnull()에 sum() 함수를 추가하여 얼만큼의 null이 있는지 확인할 것입니다.

 

pd_name(Pandas_name).isnull().sum()

이처럼 자료에 대한 정보를 살펴볼 수 있습니다~ 해당 과정은 Kaggle의 Titanic을 토대로 작성하고 있습니다~

Kaggle Titanic : https://www.kaggle.com/c/titanic

참고 : https://www.youtube.com/watch?v=FAP7JOECfEE

'Kaggle' 카테고리의 다른 글

Kaggle - Titanic(4)  (0) 2020.04.01
Kaggle - Titanic(3)  (0) 2020.03.02
Kaggle - Titanic(2)  (0) 2020.03.02

+ Recent posts