1from sklearn.ensemble import RandomForestClassifier
2
3
4clf = RandomForestClassifier(max_depth=2, random_state=0)
5
6clf.fit(X, y)
7
8print(clf.predict([[0, 0, 0, 0]]))
1from sklearn.ensemble import RandomForestClassifier
2
3y = train_data["Survived"]
4
5features = ["Pclass", "Sex", "SibSp", "Parch","Fare","Age"]
6X = pd.get_dummies(train_data[features])
7X_test = pd.get_dummies(test_data[features])
8
9model = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
10model.fit(X, y)
11predictions = model.predict(X_test)
1from sklearn.ensemble import RandomForestClassifier
2from sklearn.datasets import make_classification
3X, y = make_classification(n_samples=1000, n_features=4,
4 n_informative=2, n_redundant=0,
5 random_state=0, shuffle=False)
6clf = RandomForestClassifier(max_depth=2, random_state=0)
7clf.fit(X, y)
8
9print(clf.predict([[0, 0, 0, 0]]))
1from sklearn.ensemble import RandomForestClassifier
2from sklearn.datasets import make_classification
3
4
5X, y = make_classification(n_samples=1000, n_features=4,
6 n_informative=2, n_redundant=0,
7 random_state=0, shuffle=False)
8clf = RandomForestClassifier(max_depth=2, random_state=0)
9
10clf.fit(X, y)
11
12print(clf.predict([[0, 0, 0, 0]]))
1import matplotlib.pyplot as plt
2import seaborn as sns
3%matplotlib inline
4# Creating a bar plot
5sns.barplot(x=feature_imp, y=feature_imp.index)
6# Add labels to your graph
7plt.xlabel('Feature Importance Score')
8plt.ylabel('Features')
9plt.title("Visualizing Important Features")
10plt.legend()
11plt.show()
12