Coder Social home page Coder Social logo

kaushalshetty / stacking Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 4.0 3 KB

Multiple Model Ensembling

Python 100.00%
machine-learning artificial-intelligence scikitlearn-machine-learning stacking ensemble-model ensemble-classifier ensemble-stacking

stacking's Introduction


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)


stacking's People

Contributors

kaushalshetty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.