-2
私のプロジェクトでは、SVM classiferとPipelineを使用してクロスバリデーションの中で機能選択を行う必要があります。フィーチャ選択の方法は、相関ベースのフィーチャ選択です(私はPython-weka-wrapperを通じてWekaライブラリを使用しています)。だから、私は)(フィット()でこのクラスを書かれており、変換している方法:私は私のコードを実行するとパイプライン内のPython-Java仮想マシン
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from convertArff import arffOutput
import weka.core.jvm as jvm
from weka.attribute_selection import ASSearch, ASEvaluation, AttributeSelection
from weka.core.converters import Loader
class CorrelationFeatureSelection(BaseEstimator, TransformerMixin):
def __init__(self, names, array):
self.names = names
self.array = array
def _reset(self):
"""Reset internal data-dependent state of the scaler, if necessary.
__init__ parameters are not touched.
"""
# Checking one attribute is enough, becase they are all set together
# in partial_fit
if hasattr(self, 'attibutes_selected_'):
del self.attributes_selected_
def fit(self, X, y=None):
self._reset()
print type(self.array)
arffOutput("result", self.array, self.names)
jvm.start()
print "sono dentro"
loader = Loader(classname="weka.core.converters.ArffLoader")
data = loader.load_file("result.arff")
data.class_is_last()
print(data)
search = ASSearch(classname="weka.attributeSelection.BestFirst", options=["-D", "1", "-N", "5"])
evaluator = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval", options=["-P", "1", "-E", "1"])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluator)
attsel.select_attributes(data)
print("# attributes: " + str(attsel.number_attributes_selected))
print("attributes: " + str(attsel.selected_attributes))
print("result string:\n" + attsel.results_string)
attributes = attsel.selected_attributes
jvm.stop()
print attributes
print type(attributes)
self.attributes_selected_ = attributes[0:len(attributes) - 1]
print self.attributes_selected_
return self
def transform(self, X):
col_list = []
for c in self.attributes_selected_:
col_list.append(X[:, c:c + 1])
return np.concatenate(col_list, axis=1)
、私は次のエラーを取得:
RuntimeError: Failed to start Java VM
は、任意のはありますこの問題の解決策?