def install_package(pkg): # install weka package if necessary if not packages.is_installed(pkg): print("Installing %s..." % pkg) packages.install_package(pkg) print("Installed %s, please re-run script!" % pkg) jvm.stop() sys.exit(0) print('Package already installed.')
def main(): if not is_installed("CLOPE"): print("CLOPE is not installed, installing now") install_package("CLOPE") print("please restart") return cls = Clusterer(classname="weka.clusterers.CLOPE") print("CLOPE is installed:", cls.to_commandline())
def install_packages(path): """Install weka packages Arguments: path {str} -- path to install weka packages json """ with open(path, "r") as f: weka_packages = json.load(f) for package_name, package_path in weka_packages.items(): if not packages.is_installed(package_name): v.app.logger.info("Installing: %s %s", package_name, package_path) packages.install_package(package_path)
from weka.classifiers import Classifier from weka.classifiers import Evaluation from weka.core.classes import Random from weka.classifiers import PredictionOutput, KernelClassifier, Kernel import weka.core.packages as packages # start JVM with packages jvm.start(packages=True) # package install chisq_name = "EvolutionarySearch" chisq_installed = False for p in pkg.installed_packages(): if p.name == chisq_name: chisq_installed = True if not chisq_installed: pkg.install_package(chisq_name) print("pkg %s installed, please restart" % chisq_name) jvm.stop() sys.exit(1) data_dir = "\\\\egr-1l11qd2\\CLS_lab\\Junya Zhao\\GWAS SNPs_2018\\random50_combo_Nonoverlap_\\" globbed_files = glob.glob(data_dir + "*.csv") for csv in globbed_files: data = converters.load_any_file(csv) data.class_is_last() search = ASSearch(classname="weka.attributeSelection.BestFirst", options=["-D", "1", "-N", "10"]) evaluator = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval", options=["-P", "1", "E", "1"]) attsel = AttributeSelection() attsel.folds(10)
import weka.core.jvm as jvm import weka.core.packages as packages from weka.core.classes import complete_classname jvm.start(packages=True) pkg = "SMOTE" # install package if necessary if not packages.is_installed(pkg): print("Installing %s..." % pkg) packages.install_package(pkg) print("Installed %s, please re-run script!" % pkg) jvm.stop() # testing classname completion print(complete_classname(".SMOTE")) jvm.stop()
data_dir = os.environ.get("WEKAMOOC_DATA") if data_dir is None: data_dir = "." + os.sep + "data" import weka.core.jvm as jvm from weka.core.converters import Loader from weka.core.classes import Random import weka.core.packages as packages from weka.classifiers import Classifier, Evaluation jvm.start(packages=True) # install stackingC if necessary if not packages.is_installed("stackingC"): print("Installing stackingC...") packages.install_package("stackingC") jvm.stop() print("Installed package, please restart") exit() # load glass loader = Loader(classname="weka.core.converters.ArffLoader") fname = data_dir + os.sep + "glass.arff" print("\nLoading dataset: " + fname + "\n") data = loader.load_file(fname) data.class_is_last() # compare several meta-classifiers with J48 for classifier in [("weka.classifiers.trees.J48", []), ("weka.classifiers.meta.Bagging", []), ("weka.classifiers.trees.RandomForest", []),
if data_dir is None: data_dir = "." + os.sep + "data" import os import weka.core.jvm as jvm from weka.core.converters import Loader from weka.core.classes import Random import weka.core.packages as packages from weka.classifiers import Classifier, Evaluation jvm.start(packages=True) # install stackingC if necessary if not packages.is_installed("stackingC"): print("Installing stackingC...") packages.install_package("stackingC") jvm.stop() print("Please restart") exit() # load glass loader = Loader(classname="weka.core.converters.ArffLoader") fname = data_dir + os.sep + "glass.arff" print("\nLoading dataset: " + fname + "\n") data = loader.load_file(fname) data.set_class_index(data.num_attributes() - 1) # compare several meta-classifiers with J48 for classifier in [("weka.classifiers.trees.J48", []), ("weka.classifiers.meta.Bagging", []), ("weka.classifiers.trees.RandomForest", []), ("weka.classifiers.meta.AdaBoostM1", []), ("weka.classifiers.meta.Stacking", []),
data_dir = os.environ.get("WEKAMOOC_DATA") if data_dir is None: data_dir = "." + os.sep + "data" import os import weka.core.jvm as jvm import weka.core.packages as packages from weka.core.converters import Loader from weka.core.classes import Random from weka.classifiers import Classifier, Evaluation jvm.start(packages=True) pkg = "simpleEducationalLearningSchemes" if not packages.is_installed(pkg): packages.install_package(pkg): jvm.stop() print("Please restart") exit() # load weather.nominal fname = data_dir + os.sep + "weather.nominal.arff" print("\nLoading dataset: " + fname + "\n") loader = Loader(classname="weka.core.converters.ArffLoader") data = loader.load_file(fname) data.set_class_index(data.num_attributes() - 1) # cross-validate classifiers classifiers = [ "weka.classifiers.trees.J48", "weka.classifiers.rules.Prism" ]
import weka.core.jvm as jvm import weka.core.packages as packages jvm.start() # packages.refresh_cache() packages.install_package("CLOPE") print(packages.installed_packages()) jvm.stop()
from tqdm import tqdm import time import pandas as pd start_time = time.time() #jvm.start(packages=True, max_heap_size="12g") #max_heap_size 512m, 4g. packages=true searches for weka packages in installation program jvm.start(packages='C:/Users/rolan/wekafiles', max_heap_size='12g') pkg = "PBC4cip" pkg_source = 'D:/GoogleDrive/ITESM/3rd Semester/Tecnicas de ML/Assignment 3/PBC4cip-1.0-weka.zip' print(complete_classname("." + pkg)) # install package if necessary if not packages.is_installed(pkg): print("Installing %s..." % pkg) #packages.install_package("http://prdownloads.sourceforge.net/weka/discriminantAnalysis1.0.3.zip?download") packages.install_package(pkg_source) print("Installed %s, please re-run script!" % pkg) jvm.stop() sys.exit(0) # testing classname completion print("\n\n\n\n\n") print(">>> Start...") data_dir = "D:/GoogleDrive/ITESM/3rd Semester/Tecnicas de ML/Assignment 3/" arff_file = "universities.arff" loader = Loader(classname="weka.core.converters.ArffLoader") data = loader.load_file(data_dir + arff_file) data.class_is_last()
# -*- coding: utf-8 -*- import weka.core.jvm as jvm import weka.core.packages as packages jvm.start() # checking for installed packages #installed_packages = packages.installed_packages() #for item in installed_packages: # print item.name, item.url, "is installed\n" # # Search for GridSearch and LibSVM, just to check package's names # all_packages = packages.all_packages() # for item in all_packages: # if (item.name == "gridSearch") or (item.name == "LibSVM"): # print(item.name + " " + item.url) # To install gridSearch and LibSVM # packages.install_package("gridSearch", "1.0.8") #packages.install_package("LibSVM") packages.install_package("/home/sebastian/Descargas/LibSVM1.0.8.zip") # To install MultiSearch #packages.install_package("https://github.com/fracpete/multisearch-weka-package/releases/download/" + # "v2016.6.7/multisearch-2016.6.7.zip") #packages.install_package("/home/sebastian/Descargas/multisearch-2016.6.7.zip") #packages.uninstall_package("multisearch") jvm.stop()
import os data_dir = os.environ.get("WEKAMOOC_DATA") if data_dir is None: data_dir = "." + os.sep + "data" import weka.core.jvm as jvm import weka.core.packages as packages from weka.core.converters import Loader from weka.core.classes import Random from weka.classifiers import Classifier, Evaluation jvm.start(packages=True) pkg = "simpleEducationalLearningSchemes" if not packages.is_installed(pkg): packages.install_package(pkg) jvm.stop() print("Installed package, please restart") exit() # load weather.nominal fname = data_dir + os.sep + "weather.nominal.arff" print("\nLoading dataset: " + fname + "\n") loader = Loader(classname="weka.core.converters.ArffLoader") data = loader.load_file(fname) data.class_is_last() # cross-validate classifiers classifiers = [ "weka.classifiers.trees.J48", "weka.classifiers.rules.Prism"
Description: Training and Testing a Logistic Model Tree that compensates for class imbalancing using SMOTE by using the WEKA python wrapper. """ import weka.core.jvm as jvm import weka.core.converters as converters from weka.classifiers import Classifier, FilteredClassifier, Evaluation from weka.core.classes import Random from weka.filters import Filter import weka.plot.classifiers as plcls import weka.core.packages as packages # Starts the Java Handler with packages set to True jvm.start(packages=True) packages.install_package("SMOTE") # Loads the Data train = converters.load_any_file("imbalanced_train.arff") test = converters.load_any_file("imbalanced_test.arff") train.class_is_last() test.class_is_last() # Minority Class is getting Sampled 5x smote = Filter(classname="weka.filters.supervised.instance.SMOTE", options=["-P", "500.0"]) # Base Classifier cls = Classifier(classname="weka.classifiers.trees.LMT", options=["-B", "-I", "10"])
import os from weka.core.converters import Loader from weka.attribute_selection import ASSearch, ASEvaluation, AttributeSelection from weka.filters import Filter ########SetUp######################## os.environ["WEKA_HOME"] = os.path.abspath( "./weka-3-8-4") #point it to your weka instalation folder jvm.start(packages=True, max_heap_size='6g') ##################################### ########Install###################### packages.refresh_cache() if not packages.is_installed('discriminantAnalysis'): print("Installing discriminantAnalysis") packages.install_package('discriminantAnalysis') if not packages.is_installed('PBC4cip'): print("Installing PBC4cip") packages.install_package(os.path.abspath('./weka_packages/PBC4cip.zip')) ###################################### #############Data##################### loader = Loader(classname="weka.core.converters.ArffLoader") data = loader.load_file(os.path.abspath('./universities.arff')) data.class_is_last() ###################################### #######rub1######################## print("rub1") options = [ "-S", "1", "-miner",