-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
67 lines (38 loc) · 1.4 KB
/
README
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Stacked Generalizer Classifier
Trains a series of base models using K-fold cross-validation, then combines
the predictions of each model into a set of features that are used to train
a high-level classifier model.
Usage
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import LinearSVC
from stacking import Stacking
from sklearn.model_selection import train_test_split
# In[2]:
df = pd.read_csv("train.csv")
# In[4]:
le = LabelEncoder()
le.fit(df.type)
y = le.transform(df.type)
# In[7]:
df.drop('id',1,inplace=True)
df.drop('color',1,inplace=True)
df.drop('type',1,inplace=True)
# In[11]:
# In[14]:
x = np.array(df,dtype=float)
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)
estimators = [LogisticRegression(C=0.8),RandomForestClassifier(n_estimators=500)]
stack_model = LogisticRegression()
stk = Stacking(estimators,stack_model,use_prob=False,n_splits=5,verbose=1)
stk.fit(X_train,y_train)
y_pred = stk.predict(X_test)
from sklearn.metrics import classification_report,f1_score,accuracy_score,confusion_matrix
print "class rep",classification_report(y_test,y_pred)
print "confusion_matrix",confusion_matrix(y_test,y_pred)
print "accuracy_score",accuracy_score(y_test,y_pred)