Scikit-Learn を使用して SVM アルゴリズムを適用し、顧客が住宅ローンを選択するかどうかを予測しています。モデルを PMML 形式にエクスポートしたい。データセットの
機能 とラベルを以下に示します
。 行われた EFT の数
8. 取得した資産
9. その他のローン行動
10. 収入
ラベル
は住宅ローンです
モデルは正しく生成されますが、PMML にエクスポートできません。コードを以下に貼り付けます:
コード:
from sklearn.decomposition import PCA
from sklearn2pmml.decoration import ContinuousDomain
import pandas
import sklearn_pandas
from sklearn.svm import SVC
home_loan = pandas.read_csv('home-loan-dataset.csv')
home_loan = home_loan.drop(['CustID'], axis=1)
home_loan_df = pandas.concat((pandas.DataFrame(home_loan[:], columns = ['Frequencyofvisits','Responsetooffers','UsageofOnlineBankingFacility','Numberofsavingsaccount','Numberofcheckingaccount','Numberofcheckswritten','NumberofEFTsdone','PropertyAcquired','OtherLoansBehaviour','Income']), pandas.DataFrame(home_loan['IsHouseLoan'], columns = ["IsHouseLoan"])), axis = 1)
home_loan_mapper = sklearn_pandas.DataFrameMapper([
(['Frequencyofvisits','Responsetooffers','UsageofOnlineBankingFacility','Numberofsavingsaccount','Numberofcheckingaccount','Numberofcheckswritten','NumberofEFTsdone','PropertyAcquired','OtherLoansBehaviour','Income'], [ContinuousDomain(), PCA(n_components = 3)]),
("IsHouseLoan", None)
])
home_loan = home_loan_df
home_loan_X = home_loan[['Frequencyofvisits','Responsetooffers','UsageofOnlineBankingFacility','Numberofsavingsaccount','Numberofcheckingaccount','Numberofcheckswritten','NumberofEFTsdone','PropertyAcquired','OtherLoansBehaviour','Income']]
home_loan_y = home_loan[['IsHouseLoan']]
# Classify using SVM
home_loan_classifier = SVC()
home_loan_classifier.fit(home_loan_X, home_loan_y.values.ravel())
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
#
# Conversion to PMML
#
from sklearn2pmml import sklearn2pmml
sklearn2pmml(home_loan_classifier, home_loan_mapper, "SVMHomeLoan.pmml", with_repr = True)
PMML への変換中に次のエラーが表示されます:
エラー:
C:\Python27\python.exe C:/Users/Admin/PycharmProjects/ML-Programs/Bank-Customer-Segmentation/svm-pmml.py
Aug 17, 2016 11:35:01 AM org.jpmml.sklearn.Main run
INFO: Parsing DataFrameMapper PKL..
Aug 17, 2016 11:35:01 AM org.jpmml.sklearn.Main run
INFO: Parsed DataFrameMapper PKL in 30 ms.
Aug 17, 2016 11:35:01 AM org.jpmml.sklearn.Main run
INFO: Converting DataFrameMapper..
Aug 17, 2016 11:35:01 AM org.jpmml.sklearn.Main run
SEVERE: Failed to convert DataFrameMapper
java.lang.IllegalArgumentException: The value of the sklearn2pmml.decoration.ContinuousDomain.data_min_ attribute (null) is not a supported array type
at org.jpmml.sklearn.ClassDictUtil.getArray(ClassDictUtil.java:51)
at sklearn2pmml.decoration.ContinuousDomain.getDataMin(ContinuousDomain.java:111)
at sklearn2pmml.decoration.ContinuousDomain.encodeFeatures(ContinuousDomain.java:50)
at sklearn_pandas.DataFrameMapper.encodeFeatures(DataFrameMapper.java:70)
at org.jpmml.sklearn.Main.run(Main.java:146)
at org.jpmml.sklearn.Main.main(Main.java:107)
Exception in thread "main" java.lang.IllegalArgumentException: The value of the sklearn2pmml.decoration.ContinuousDomain.data_min_ attribute (null) is not a supported array type
at org.jpmml.sklearn.ClassDictUtil.getArray(ClassDictUtil.java:51)
at sklearn2pmml.decoration.ContinuousDomain.getDataMin(ContinuousDomain.java:111)
at sklearn2pmml.decoration.ContinuousDomain.encodeFeatures(ContinuousDomain.java:50)
at sklearn_pandas.DataFrameMapper.encodeFeatures(DataFrameMapper.java:70)
at org.jpmml.sklearn.Main.run(Main.java:146)
at org.jpmml.sklearn.Main.main(Main.java:107)
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/ML-Programs/Bank-Customer-Segmentation/svm-pmml.py", line 52, in <module>
sklearn2pmml(home_loan_classifier, home_loan_mapper, "SVMHomeLoan.pmml", with_repr = True)
File "C:\Python27\lib\site-packages\sklearn2pmml\__init__.py", line 56, in sklearn2pmml
subprocess.check_call(cmd)
File "C:\Python27\lib\subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['java', '-cp', 'C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\guava-19.0.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\istack-commons-runtime-2.21.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jaxb-core-2.2.11.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jaxb-runtime-2.2.11.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jcommander-1.48.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jpmml-converter-1.0.7.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jpmml-sklearn-1.0-SNAPSHOT.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\jpmml-xgboost-1.0.5.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\pmml-agent-1.2.16.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\pmml-model-1.2.16.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\pmml-model-metro-1.2.16.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\pmml-schema-1.2.16.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\pyrolite-4.12.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\serpent-1.12.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\slf4j-api-1.7.21.jar;C:\\Python27\\lib\\site-packages\\sklearn2pmml\\resources\\slf4j-jdk14-1.7.21.jar', 'org.jpmml.sklearn.Main', '--pkl-estimator-input', 'c:\\users\\Admin\\appdata\\local\\temp\\tmplgmrjq.pkl', '--repr-estimator', "SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,\n decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',\n max_iter=-1, probability=False, random_state=None, shrinking=True,\n tol=0.001, verbose=False)", '--pkl-mapper-input', 'c:\\users\\Admin\\appdata\\local\\temp\\tmpobahse.pkl', '--repr-mapper', "DataFrameMapper(features=[(['Frequencyofvisits', 'Responsetooffers', 'UsageofOnlineBankingFacility', 'Numberofsavingsaccount', 'Numberofcheckingaccount', 'Numberofcheckswritten', 'NumberofEFTsdone', 'PropertyAcquired', 'OtherLoansBehavior', 'Income100000'], TransformerPipeline(steps=[('continuousdomain', ContinuousDomain(invalid_value_treatment='return_invalid')), ('pca', PCA(copy=True, n_components=3, whiten=False))])), ('IsHouseLoan', None)],\n sparse=False)", '--pmml-output', 'SVMHomeLoan.pmml']' returned non-zero exit status 1
何が原因でしょうか?