-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.py
More file actions
38 lines (23 loc) · 960 Bytes
/
Random.py
File metadata and controls
38 lines (23 loc) · 960 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn import metrics
df = pd.read_csv("emails.csv")
df.head()
with pd.option_context('display.max_rows', 5728):
print (df)
X, y = make_classification(n_samples=2736, n_features=2, n_informative=2, n_redundant=0, random_state=5)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
classifier = RandomForestClassifier(n_estimators=20, random_state=5)
classifier.fit(X, y)
print(classifier.feature_importances_)
print(classifier.predict([[0, 0]]))
y_prediction = classifier.predict(X_test)
print(metrics.accuracy_score(y_test, y_prediction))
classifier.apply(X)
classifier.decision_path(X)
classifier.get_params(deep=True)
classifier.predict_log_proba(X)
classifier.predict_proba(X)
classifier.score(X, y)