Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
scikit-learn Cookbook - Second Edition

You're reading from  scikit-learn Cookbook - Second Edition

Product type Book
Published in Nov 2017
Publisher Packt
ISBN-13 9781787286382
Pages 374 pages
Edition 2nd Edition
Languages
Author (1):
Trent Hauck Trent Hauck
Profile icon Trent Hauck

Table of Contents (13) Chapters

Preface 1. High-Performance Machine Learning – NumPy 2. Pre-Model Workflow and Pre-Processing 3. Dimensionality Reduction 4. Linear Models with scikit-learn 5. Linear Models – Logistic Regression 6. Building Models with Distance Metrics 7. Cross-Validation and Post-Model Workflow 8. Support Vector Machines 9. Tree Algorithms and Ensembles 10. Text and Multiclass Classification with scikit-learn 11. Neural Networks 12. Create a Simple Estimator

Create a Simple Estimator

In this chapter we will cover the following recipes:

  • Creating a simple estimator

Introduction

We are going to make a custom estimator with scikit-learn. We will take traditional statistical math and programming and turn it into machine learning. You are able to turn any statistics into machine learning by using scikit-learn's powerful cross-validation capabilities.

Create a simple estimator

We are going to do some work towards building our own scikit-learn estimator. The custom scikit-learn estimator consists of at least three methods:

  • An __init__ initialization method: This method takes as input the estimator's parameters
  • A fit method: This trains the estimator
  • A predict method: This method performs a prediction on unseen data

Schematically, the class looks like this:

#Inherit from the classes BaseEstimator, ClassifierMixin
class RidgeClassifier(BaseEstimator, ClassifierMixin):

def __init__(self,param1,param2):
self.param1 = param1
self.param2 = param2

def fit(self, X, y = None):
#do as much work as possible in this method
return self

def predict(self, X_test):
#do some work here and return the predictions, y_pred
return y_pred
...
lock icon The rest of the chapter is locked
arrow left Previous Chapter
You have been reading a chapter from
scikit-learn Cookbook - Second Edition
Published in: Nov 2017 Publisher: Packt ISBN-13: 9781787286382
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}