Python機器學習筆記(十六):一次測完所有常見的ML演算法

本文參考自:

透過lazypredict這個套件,我們可以用短短幾行程式,針對我們的dataset,進行訓練,並呈現出多種Regression或Classification算法的測試結果

注意事項

根據這篇文章後段的說明,發現lazypredict和sklearn的程式做法不同,lazypredict有「自動」進行資料前處理;而sklearn在使用同個演算法的時候,若要達到與lazypredict一樣的效果,需要去套件原始碼裡面查詢資料前處理是怎麼進行的。

安裝

pip install lazypredict

使用

# Classificationfrom lazypredict.Supervised import LazyClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

data = load_breast_cancer()
X = data.data
y= data.target

X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=.5,random_state =123)

clf = LazyClassifier(verbose=0,ignore_warnings=True, custom_metric=None)
models,predictions = clf.fit(X_train, X_test, y_train, y_test)

print(models)
# Regressionfrom lazypredict.Supervised import LazyRegressor
from sklearn import datasets
from sklearn.utils import shuffle
import numpy as np

boston = datasets.load_boston()
X, y = shuffle(boston.data, boston.target, random_state=13)
X = X.astype(np.float32)

offset = int(X.shape[0] * 0.9)

X_train, y_train = X[:offset], y[:offset]
X_test, y_test = X[offset:], y[offset:]

reg = LazyRegressor(verbose=0, ignore_warnings=False, custom_metric=None)
models, predictions = reg.fit(X_train, X_test, y_train, y_test)

print(models)

Machine Learning | Deep Learning | https://linktr.ee/yanwei

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store