Skip to content

Commit

Permalink
Create Random_Forest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnvigupta authored Nov 29, 2020
1 parent c0ff318 commit a20b921
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Random_Forest.py
Original file line number Diff line number Diff line change
@@ -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)}')

0 comments on commit a20b921

Please sign in to comment.