LoginSignup
4
2

More than 5 years have passed since last update.

scikit-learn使用まとめ

Last updated at Posted at 2018-02-11

scikit-learnの使い方について、使用したものを整理する。

ロジスティック回帰

参考はこのページ

sample
from sklearn.linear_model import LogisticRegression

#モデルの生成
clf = LogisticRegression()
#訓練データで学習 Xは説明変数のデータフレーム yは答え
clf.fit(X, y)
#学習したモデルの精度
clf.score(X,y)
#モデルの変数ごとの係数を表示
coeff_df = DataFrame([X.columns, clf.coef_[0]]).T
coeff_df
#テストデータから予測する test_dfはテストデータの説明変数のデータフレーム
clf.predict(test_df)

シリアライズ

モデルをpklファイルに出力する

sample
from sklearn.externals import joblib

joblib.dump(モデル, '〜.pkl') 

pklファイルから読み込む

sample
from sklearn.externals import joblib

モデル = joblib.load('〜.pkl') 
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2