忍者ブログ

揺動経路の記録

   

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ModuleNotFoundError問題

機会学習モデルをpklで保存したあとに、クラスオブジェクト情報などを一緒に格納しようとしたときに生じうるエラー

保存するときの構成が引き継がれてしまう。実際にpklのバイナリを確認してみるとディレクトリ構成の情報が入っていることがわかる

解決策?

https://stackoverflow.com/questions/2121874/python-pickling-after-changing-a-modules-directory


import sys
from whyteboard import tools

sys
.modules['tools'] = tools
PR

GBDTを利用した特徴量変換スクリプト

サンプルコード
import numpy as np

from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import load_iris

def feature_transformation(gscv, x):
ret = [gscv.best_estimator_.estimators_[i, 0].tree_.apply(x.astype(np.float32)) for i in
range(gscv.best_estimator_.n_estimators)]
return np.array(ret)

def ft_gbdt():
data = load_iris()

x = data['data']
y = data['target']
x_train = x[0:130]
x_test = x[130:150]
y_train = y[0:130]
y_test = y[130:150]

print("x:{}".format(np.array(x).shape))
print("y:{}".format(np.array(y).shape))

# tune hyper parameters first
model = GradientBoostingClassifier(n_estimators=1000)
parameters = {'learning_rate' : [0.1],
'max_depth': [4, 6],
'min_samples_leaf': [3, 5],
'max_features': [1.0]}

gscv = GridSearchCV(model, parameters, verbose=10, n_jobs=-1, cv=4)
gscv.fit(x_train, y_train)
print("score:{}".format(gscv.score(x_test, y_test)))

# ------------------------------------------------
ret = feature_transformation(gscv, x_test)

print("ret:{}".format(ret))

プロフィール

HN:
stochaotic
性別:
非公開

最新記事

(06/17)
(05/31)
(11/09)
(03/23)
(02/11)

P R

Copyright ©  -- 揺動経路の記録 --  All Rights Reserved
Design by CriCri / Photo by Geralt / powered by NINJA TOOLS / 忍者ブログ / [PR]