Git Product home page Git Product logo

patsylearn's Introduction

Patsy-Learn

A simple patsy to scikit-learn adaptor. Be aware that the content of this package is pretty experimental. Feedback welcome.

This package provides two classes:

  • A scikit-learn meta-estimator PatsyModel, that feeds the design matrix created by patsy into a scikit-learn estimator.
  • A scikit-learn transformer, that uses a patsy formula to transform and select features.

Both classes work on pandas DataFrames. If you want to use PatsyModel for a supervised estimator, the input dataframe is expected to contain both the data and the target.

Example

# put the iris dataset into a pandas dataframe
from sklearn.datasets import load_iris
import pandas as pd

iris = load_iris()
names = [f_name.replace(" ", "_").strip("_(cm)") for f_name in iris.feature_names]
iris_df = pd.DataFrame(iris.data, columns=names)
iris_df['species'] = iris.target

# create logistic regression with two features
from patsylearn import PatsyModel
from sklearn.linear_model import LogisticRegression
model = PatsyModel(LogisticRegression(), "species ~ sepal_length + petal_length")
# model is an sklearn estimator.

from sklearn.cross_validation import train_test_split
data_train, data_test = train_test_split(iris_df)
model.fit(data_train)
print(model.score(data_test))

# use PatsyTransformer to just select and transform features
transformer = PatsyTransformer("sepal_length + np.log(petal_length) + petal_length:sepal_width")
# transformer is a scikit-learn transformer

transformer.fit(data)
print(transformer.transform(data).shape)

patsylearn's People

Contributors

amueller avatar pnavaro avatar sashaostr avatar scls19fr 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.