0

最近、scikit-learn モデルを PMML に変換する方法を探していたときに、sklearn2pmmljpmml-sklearnに出会いました。しかし、基本的な使用例を使用しようとするとエラーが発生し、理解できません。

sklearn2pmmlで例を使用しようとすると、 long を int としてキャストする際に次の問題が発生します。

Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
    at numpy.core.NDArrayUtil.getShape(NDArrayUtil.java:66)
    at org.jpmml.sklearn.ClassDictUtil.getShape(ClassDictUtil.java:92)
    at org.jpmml.sklearn.ClassDictUtil.getShape(ClassDictUtil.java:76)
    at sklearn.linear_model.BaseLinearClassifier.getCoefShape(BaseLinearClassifier.java:144)
    at sklearn.linear_model.BaseLinearClassifier.getNumberOfFeatures(BaseLinearClassifier.java:56)
    at sklearn.Classifier.createSchema(Classifier.java:50)
    at org.jpmml.sklearn.Main.run(Main.java:104)
    at org.jpmml.sklearn.Main.main(Main.java:87)
Traceback (most recent call last):
  File "C:\Users\user\workspace\sklearn_pmml\test.py", line 40, in <module>
    sklearn2pmml(iris_classifier, iris_mapper, "LogisticRegressionIris.pmml")
  File "C:\Python27\lib\site-packages\sklearn2pmml\__init__.py", line 49, in sklearn2pmml
    os.remove(dump)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\user\\appdata\\local\\temp\\tmpmxyp2y.pkl'

ここで何が起こっているかについての提案はありますか?

使用コード:

#
# Step 1: feature engineering
#

from sklearn.datasets import load_iris
from sklearn.decomposition import PCA

import pandas
import sklearn_pandas

iris = load_iris()

iris_df = pandas.concat((pandas.DataFrame(iris.data[:, :], columns = ["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"]), pandas.DataFrame(iris.target, columns = ["Species"])), axis = 1)

iris_mapper = sklearn_pandas.DataFrameMapper([
    (["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"], PCA(n_components = 3)),
    ("Species", None)
])

iris = iris_mapper.fit_transform(iris_df)

#
# Step 2: training a logistic regression model
#

from sklearn.linear_model import LogisticRegressionCV

iris_X = iris[:, 0:3]
iris_y = iris[:, 3]

iris_classifier = LogisticRegressionCV()
iris_classifier.fit(iris_X, iris_y)

#
# Step 3: conversion to PMML
#

from sklearn2pmml import sklearn2pmml

sklearn2pmml(iris_classifier, iris_mapper, "LogisticRegressionIris.pmml")

EDIT 12/6: 新しいアップデートの後、同じ問題がさらに先に発生します:

Dec 06, 2015 5:56:49 PM sklearn_pandas.DataFrameMapper updatePMML
INFO: Updating 1 target field and 3 active field(s)
Dec 06, 2015 5:56:49 PM sklearn_pandas.DataFrameMapper updatePMML
INFO: Mapping target field y to Species
Dec 06, 2015 5:56:49 PM sklearn_pandas.DataFrameMapper updatePMML
INFO: Mapping active field(s) [x1, x2, x3] to [Sepal.Length, Sepal.Width, Petal.Length, Petal.Width]
Traceback (most recent call last):
  File "C:\Users\user\workspace\sklearn_pmml\test.py", line 40, in <module>
    sklearn2pmml(iris_classifier, iris_mapper, "LogisticRegressionIris.pmml")
  File "C:\Python27\lib\site-packages\sklearn2pmml\__init__.py", line 49, in sklearn2pmml
    os.remove(dump)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\user\\appdata\\local\\temp\\tmpqeblat.pkl'
4

1 に答える 1