From a20b9211b64ec54174278abc83a0162372980e5c Mon Sep 17 00:00:00 2001 From: Jahnvi Gupta <43217070+jahnvigupta@users.noreply.github.com> Date: Sun, 29 Nov 2020 18:35:55 +0530 Subject: [PATCH] Create Random_Forest.py --- Random_Forest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Random_Forest.py diff --git a/Random_Forest.py b/Random_Forest.py new file mode 100644 index 0000000..db25b0c --- /dev/null +++ b/Random_Forest.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np +import numpy as np +from sklearn.model_selection import train_test_split +from sklearn.ensemble import RandomForestClassifier + +data = pd.read_csv("train") #train is location of training data +data = data.dropna(axis='columns', thresh = int(0.5 * len(data))) +data.fillna(data.mean()) +col = data.columns +X = data[col[1:]] +y = data['LABEL'] +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) + +# Create the model with 100 trees +model = model = RandomForestClassifier(n_estimators=100, + bootstrap = True, + max_features = 'sqrt') +# Fit on training data +model.fit(X_train, y_train) +print(f'Model Accuracy: {model.score(X_test, y_test)}')