-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom_forest.py
26 lines (19 loc) · 932 Bytes
/
Random_forest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import csv
dataset = pd.read_csv(r'C:\Users\Robin\Desktop\ELEC301\TrainingMetadata.csv')
unlabeled_dataset = pd.read_csv(r'C:\Users\Robin\Desktop\ELEC301\UnlabeledTestMetadata.csv')
X = dataset.drop(['Type','Number'],axis = 1)
y = dataset.iloc[:,1].values
X_unlabeled = unlabeled_dataset.drop(["Number"],axis = 1)
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(max_depth = 3, random_state = 0)
classifier.fit(X, y)
from sklearn.model_selection import cross_val_score
accuracies = cross_val_score(estimator = classifier, X = X, \
y = y, cv = 10)
print('Mean accuracy for random forest is', accuracies.mean())
print('Standard deviation for random forest is', accuracies.std())
y_submission = classifier.predict(X_unlabeled)
np.savetxt("submission_2.csv", y_submission,delimiter=",")