Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- from sklearn.tree import DecisionTreeClassifier
- data = pd.read_csv('titanic.csv', index_col = 'PassengerId')
- data = data.dropna()
- data['Sex'] = np.where(data['Sex'] == 'male', 1, 0)
- features = data[['Pclass', 'Fare', 'Age', 'Sex']]
- target = data['Survived']
- clf = DecisionTreeClassifier(random_state = 241)
- clf.fit(features, target)
- clf.feature_importances_
- Out: array([ 0.01793336, 0.29549222, 0.40310552, 0.2834689 ])
Advertisement
Add Comment
Please, Sign In to add comment