Decision Tree
Like SVMs, Decision Trees are versatile Machine Learning algorithms that can per‐ form both classification and regression tasks, and even multioutput tasks. They are very powerful algorithms, capable of fitting complex datasets.
With the help of the Titanic Data set, we will find predictions of person will survive or not
Titanic Dataset Downloadable link:
https://drive.google.com/file/d/1-Wxaj1pxeBS3jvUifN4N0KXT8Q54OkuD/view?usp=sharing
import pandas as pd
import numpy as np
df = pd.read_csv('titanic.csv')
df.head()
inputs = df.drop(['PassengerId','Name','Ticket','Cabin','Embarked','SibSp','Parch','Survived'], axis =1)
target = df[ 'Survived']
inputs['Age'] = df['Age'].astype(int)
inputs.head()
from sklearn.preprocessing import LabelEncoder
encoded_Sex = LabelEncoder()
inputs['Sex'] = encoded_Sex.fit_transform(inputs['Sex'])
inputs.head()
from sklearn import tree
model = tree.DecisionTreeClassifier()
model.fit(inputs, target)
model.score(inputs, target)
model.predict([[3,0,35,2.2500]])
Our Titanic DataSet


Comments
Post a Comment