我正在使用Scikit-Learn来应用SVM算法来预测客户是否会选择房屋贷款。我希望将模型导出为PMML格式。数据集中的要素和标签如下所示:
功能
1。访问次数
2。对报价的回应
3。网上银行设施的使用
4。储蓄账户数量5。支票帐号数量6。书面支票数量7。完成的电子转帐数量
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
可能是什么原因?
答案 0 :(得分:1)
显然,您的某个数据列无法满足sklearn2pmml.decoration.ContinuousDomain
转换的期望。无法说出哪一列,以及问题的确切性质(例如,分类操作类型而不是连续的,错误的数值数据类型,列包含NA值等),这是不可能的。没有看到你的数据。
这里有两个选项:
ContinuousDomain
转换正常。ContinuousDomain
。目前您正在使用已从sklearn2pmml README.md文件直接复制的数据预处理逻辑。请重新设置它以匹配您的数据 - [ContinuousDomain(), PCA(n_components = 3)]
转换不太可能是您的用例的正确解决方案。
此外,此问题特别针对sklearn2pmml包。如果您在sklearn2pmml问题跟踪器中打开了问题,则可能会获得更好/更快的回复。