Using Sckit-Learn

1. Install scikit-learn

  • conda install scikit-learn

2. General Form

  • every algorithm is exposed in scikit-learn via an 'Estimator'
  • First you'll import the model, the general form is :
    - from sklearn.{family} import {Model}
  • Estimator parameters : All the parameters of an estimator can be set when it is instantiated
    - It will have suitable values
    • model = LinearRegression(normalize=True)
      print(model) 

3. Available in all Estimators

  • model.fit() : fit training data
    - for supervised learning applications , this accepts two arguments : the data x and the labels y (e.g. model.fit(x,y))
    - for unsupervised learning applications, this accepts only a single argument (e.g. model.fit(x))

4. Available in supervised estimators

  • model.predict_proba() : returns the probability that a new observation has each categorical label. In this case, the label with the highest probability is returned by model.predict()
  • model.score() : for classification or regression problems, scores are between 0 and 1 (larger score = better fit)

5. Available in unsupervised estimators

  • model.predict() : predict labels in clustering algorithms
  • model.transform() : given an unsupervised model, transform new data into the new basis. This also accepts x_new, returns the new representation of the data based on the unsuprvised model
  • model.fit_transform() : for some estimators. which efficiently performs a fit and transform on the same input data

좋은 웹페이지 즐겨찾기