Python sklearn.__version__() Examples
The following are 30
code examples of sklearn.__version__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sklearn
, or try the search function
.

Example #1
Source File: utility.py From pyod with BSD 2-Clause "Simplified" License | 7 votes |
def _get_sklearn_version(): # pragma: no cover """ Utility function to decide the version of sklearn. PyOD will result in different behaviors with different sklearn version Returns ------- sk_learn version : int """ sklearn_version = str(sklearn.__version__) if int(sklearn_version.split(".")[1]) < 19 or int( sklearn_version.split(".")[1]) > 23: raise ValueError("Sklearn version error") return int(sklearn_version.split(".")[1])
Example #2
Source File: configuration.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def set_configuration(): # set python version config.ExternalDepFound('python', '.'.join([str(x) for x in sys.version_info])) version = mdp.__version__ if mdp.__revision__: version += ', ' + mdp.__revision__ config.ExternalDepFound('mdp', version) # parallel python dependency try: import pp # set pp secret if not there already # (workaround for debian patch to pp that disables pp's default password) pp_secret = os.getenv('MDP_PP_SECRET') or 'mdp-pp-support-password' # module 'user' has been deprecated since python 2.6 and deleted # completely as of python 3.0. # Basically pp can not work on python 3 at the moment. import user if not hasattr(user, 'pp_secret'): user.pp_secret = pp_secret except ImportError, exc: config.ExternalDepFailed('parallel_python', exc)
Example #3
Source File: utility.py From pyod with BSD 2-Clause "Simplified" License | 6 votes |
def _sklearn_version_21(): # pragma: no cover """ Utility function to decide the version of sklearn In sklearn 21.0, LOF is changed. Specifically, _decision_function is replaced by _score_samples Returns ------- sklearn_21_flag : bool True if sklearn.__version__ is newer than 0.21.0 """ sklearn_version = str(sklearn.__version__) if int(sklearn_version.split(".")[1]) > 20: return True else: return False
Example #4
Source File: extra_trees.py From mljar-supervised with MIT License | 6 votes |
def __init__(self, params): super(ExtraTreesAlgorithm, self).__init__(params) logger.debug("ExtraTreesAlgorithm.__init__") self.library_version = sklearn.__version__ self.trees_in_step = additional.get("trees_in_step", 100) self.max_steps = additional.get("max_steps", 50) self.early_stopping_rounds = additional.get("early_stopping_rounds", 50) self.model = ExtraTreesClassifier( n_estimators=self.trees_in_step, criterion=params.get("criterion", "gini"), max_features=params.get("max_features", 0.6), min_samples_split=params.get("min_samples_split", 30), warm_start=True, n_jobs=-1, random_state=params.get("seed", 1), )
Example #5
Source File: random_forest.py From mljar-supervised with MIT License | 6 votes |
def __init__(self, params): super(RandomForestAlgorithm, self).__init__(params) logger.debug("RandomForestAlgorithm.__init__") self.library_version = sklearn.__version__ self.trees_in_step = additional.get("trees_in_step", 5) self.max_steps = additional.get("max_steps", 3) self.early_stopping_rounds = additional.get("early_stopping_rounds", 50) self.model = RandomForestClassifier( n_estimators=self.trees_in_step, criterion=params.get("criterion", "gini"), max_features=params.get("max_features", 0.8), min_samples_split=params.get("min_samples_split", 4), warm_start=True, n_jobs=-1, random_state=params.get("seed", 1), )
Example #6
Source File: random_forest.py From mljar-supervised with MIT License | 6 votes |
def __init__(self, params): super(RandomForestRegressorAlgorithm, self).__init__(params) logger.debug("RandomForestRegressorAlgorithm.__init__") self.library_version = sklearn.__version__ self.trees_in_step = regression_additional.get("trees_in_step", 5) self.max_steps = regression_additional.get("max_steps", 3) self.early_stopping_rounds = regression_additional.get( "early_stopping_rounds", 50 ) self.model = RandomForestRegressor( n_estimators=self.trees_in_step, criterion=params.get("criterion", "mse"), max_features=params.get("max_features", 0.8), min_samples_split=params.get("min_samples_split", 4), warm_start=True, n_jobs=-1, random_state=params.get("seed", 1), )
Example #7
Source File: nanotron.py From picasso with MIT License | 6 votes |
def save_model(self): if self.mlp is not None: fname, ext = QtWidgets.QFileDialog.getSaveFileName( self, "Save mode file", "model.sav", ".sav", ) base, ext = _ospath.splitext(fname) fname = base + ".sav" self.train_log["Model"] = fname self.train_log["Generated by"] = "Picasso nanoTRON : Train" import sklearn self.train_log["Scikit-Learn Version"] = sklearn.__version__ self.train_log["Created on"] = datetime.datetime.now() if fname: joblib.dump(self.mlp, fname) print("Saving complete.") info_path = base + ".yaml" io.save_info(info_path, [self.train_log])
Example #8
Source File: RobustScaler.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, options): self.handle_options(options) out_params = convert_params( options.get('params', {}), bools=['with_centering', 'with_scaling'], strs=['quantile_range'], ) if StrictVersion(sklearn_version) < StrictVersion(quantile_range_required_version) and 'quantile_range' in out_params.keys(): out_params.pop('quantile_range') msg = 'The quantile_range option is ignored in this version of scikit-learn ({}): version {} or higher required' msg = msg.format(sklearn_version, quantile_range_required_version) messages.warn(msg) if 'quantile_range' in out_params.keys(): try: out_params['quantile_range'] = tuple(int(i) for i in out_params['quantile_range'].split('-')) assert len(out_params['quantile_range']) == 2 except: raise RuntimeError('Syntax Error: quantile_range requires a range, e.g., quantile_range=25-75') self.estimator = _RobustScaler(**out_params)
Example #9
Source File: dispatcher.py From daal4py with Apache License 2.0 | 6 votes |
def enable(name=None, verbose=True): if LooseVersion(sklearn_version) < LooseVersion("0.20.0"): raise NotImplementedError("daal4py patches apply for scikit-learn >= 0.20.0 only ...") elif LooseVersion(sklearn_version) > LooseVersion("0.23.1"): warn_msg = ("daal4py {daal4py_version} has only been tested " + "with scikit-learn 0.23.1, found version: {sklearn_version}") warnings.warn(warn_msg.format( daal4py_version=daal4py_version, sklearn_version=sklearn_version) ) if name is not None: do_patch(name) else: for key in _mapping: do_patch(key) if verbose and sys.stderr is not None: sys.stderr.write("Intel(R) Data Analytics Acceleration Library (Intel(R) DAAL) solvers for sklearn enabled: " "https://intelpython.github.io/daal4py/sklearn.html\n")
Example #10
Source File: sklearn.py From mlflow with Apache License 2.0 | 6 votes |
def get_default_conda_env(include_cloudpickle=False): """ :return: The default Conda environment for MLflow Models produced by calls to :func:`save_model()` and :func:`log_model()`. """ import sklearn pip_deps = None if include_cloudpickle: import cloudpickle pip_deps = ["cloudpickle=={}".format(cloudpickle.__version__)] return _mlflow_conda_env( additional_conda_deps=[ "scikit-learn={}".format(sklearn.__version__), ], additional_pip_deps=pip_deps, additional_conda_channels=None )
Example #11
Source File: embedders.py From nodevectors with MIT License | 5 votes |
def save(self, filename: str): """ Saves model to a custom file format filename : str Name of file to save. Don't include filename extensions Extensions are added automatically File format is a zipfile with joblib dump (pickle-like) + dependency metata Metadata is checked on load. Includes validation and metadata to avoid Pickle deserialization gotchas See here Alex Gaynor PyCon 2014 talk "Pickles are for Delis" for more info on why we introduce this additional check """ if '.zip' in filename: raise UserWarning("The file extension '.zip' is automatically added" + " to saved models. The name will have redundant extensions") sysverinfo = sys.version_info meta_data = { "python_": f'{sysverinfo[0]}.{sysverinfo[1]}', "skl_": sklearn.__version__[:-2], "pd_": pd.__version__[:-2], "csrg_": cg.__version__[:-2] } with tempfile.TemporaryDirectory() as temp_dir: joblib.dump(self, os.path.join(temp_dir, self.f_model), compress=True) with open(os.path.join(temp_dir, self.f_mdata), 'w') as f: json.dump(meta_data, f) filename = shutil.make_archive(filename, 'zip', temp_dir)
Example #12
Source File: embedders.py From nodevectors with MIT License | 5 votes |
def load(filename: str): """ Load model from NodeEmbedding model zip file. filename : str full filename of file to load (including extensions) The file should be the result of a `save()` call Loading checks for metadata and raises warnings if pkg versions are different than they were when saving the model. """ with tempfile.TemporaryDirectory() as temp_dir: shutil.unpack_archive(filename, temp_dir, 'zip') model = joblib.load(os.path.join(temp_dir, BaseNodeEmbedder.f_model)) with open(os.path.join(temp_dir, BaseNodeEmbedder.f_mdata)) as f: meta_data = json.load(f) # Validate the metadata sysverinfo = sys.version_info pyver = "{0}.{1}".format(sysverinfo[0], sysverinfo[1]) if meta_data["python_"] != pyver: raise UserWarning( "Invalid python version; {0}, required: {1}".format( pyver, meta_data["python_"])) sklver = sklearn.__version__[:-2] if meta_data["skl_"] != sklver: raise UserWarning( "Invalid sklearn version; {0}, required: {1}".format( sklver, meta_data["skl_"])) pdver = pd.__version__[:-2] if meta_data["pd_"] != pdver: raise UserWarning( "Invalid pandas version; {0}, required: {1}".format( pdver, meta_data["pd_"])) csrv = cg.__version__[:-2] if meta_data["csrg_"] != csrv: raise UserWarning( "Invalid csrgraph version; {0}, required: {1}".format( csrv, meta_data["csrg_"])) return model
Example #13
Source File: setup.py From skutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_pandas_status(): try: import pandas as pd return _check_version(pd.__version__, pandas_min_version) except ImportError: traceback.print_exc() return default_status
Example #14
Source File: setup.py From skutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_sklearn_status(): try: import sklearn as sk return _check_version(sk.__version__, sklearn_min_version) except ImportError: traceback.print_exc() return default_status
Example #15
Source File: setup.py From skutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_numpy_status(): try: import numpy as np return _check_version(np.__version__, numpy_min_version) except ImportError: traceback.print_exc() return default_status
Example #16
Source File: setup.py From skutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_scipy_status(): try: import scipy as sc return _check_version(sc.__version__, scipy_min_version) except ImportError: traceback.print_exc() return default_status
Example #17
Source File: setup.py From skutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_h2o_status(): try: import h2o return _check_version(h2o.__version__, h2o_min_version) except ImportError: traceback.print_exc() return default_status
Example #18
Source File: conftest.py From scikit-learn-extra with BSD 3-Clause "New" or "Revised" License | 5 votes |
def pytest_collection_modifyitems(config, items): # numpy changed the str/repr formatting of numpy arrays in 1.14. We want to # run doctests only for numpy >= 1.14. skip_doctests = False try: import numpy as np if LooseVersion(np.__version__) < LooseVersion("1.14") or LooseVersion( sklearn.__version__ ) < LooseVersion("0.23.0"): reason = ( "doctests are only run for numpy >= 1.14 " "and scikit-learn >=0.23.0" ) skip_doctests = True elif sys.platform.startswith("win32"): reason = ( "doctests are not run for Windows because numpy arrays " "repr is inconsistent across platforms." ) skip_doctests = True except ImportError: pass if skip_doctests: skip_marker = pytest.mark.skip(reason=reason) for item in items: if isinstance(item, DoctestItem): item.add_marker(skip_marker)
Example #19
Source File: test_encoders.py From category_encoders with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_sklearn_compliance(self): for encoder_name in encoders.__all__: with self.subTest(encoder_name=encoder_name): # in sklearn < 0.19.0, these methods require classes, # in sklearn >= 0.19.0, these methods require instances if sklearn.__version__ < '0.19.0': encoder = getattr(encoders, encoder_name) else: encoder = getattr(encoders, encoder_name)() check_transformer_general(encoder_name, encoder) check_transformers_unfitted(encoder_name, encoder)
Example #20
Source File: test_base.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_pickle_version_warning_is_issued_upon_different_version(): iris = datasets.load_iris() tree = TreeBadVersion().fit(iris.data, iris.target) tree_pickle_other = pickle.dumps(tree) message = pickle_error_message.format(estimator="TreeBadVersion", old_version="something", current_version=sklearn.__version__) assert_warns_message(UserWarning, message, pickle.loads, tree_pickle_other)
Example #21
Source File: test_base.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_pickle_version_warning_is_issued_when_no_version_info_in_pickle(): iris = datasets.load_iris() # TreeNoVersion has no getstate, like pre-0.18 tree = TreeNoVersion().fit(iris.data, iris.target) tree_pickle_noversion = pickle.dumps(tree) assert b"version" not in tree_pickle_noversion message = pickle_error_message.format(estimator="TreeNoVersion", old_version="pre-0.18", current_version=sklearn.__version__) # check we got the warning about using pre-0.18 pickle assert_warns_message(UserWarning, message, pickle.loads, tree_pickle_noversion)
Example #22
Source File: features_binarizer.py From tick with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _is_sklearn_older_than(self, ver): from packaging import version import sklearn return version.parse(sklearn.__version__) < version.parse(ver)
Example #23
Source File: plot.py From DensityPeakCluster with MIT License | 5 votes |
def plot_cluster(cluster): ''' Plot scatter diagram for final points that using multi-dimensional scaling for data Args: cluster : DensityPeakCluster object ''' logger.info("PLOT: cluster result, start multi-dimensional scaling") dp = np.zeros((cluster.max_id, cluster.max_id), dtype=np.float32) cls = [] for i in xrange(1, cluster.max_id): for j in xrange(i + 1, cluster.max_id + 1): dp[i - 1, j - 1] = cluster.distances[(i, j)] dp[j - 1, i - 1] = cluster.distances[(i, j)] cls.append(cluster.cluster[i]) cls.append(cluster.cluster[cluster.max_id]) cls = np.array(cls, dtype=np.float32) fo = open(r'./tmp.txt', 'w') fo.write('\n'.join(map(str, cls))) fo.close() version = versiontuple(sklearn_version)[1] > 14 if version[0] > 0 or version[1] > 14: mds = manifold.MDS(max_iter=200, eps=1e-4, n_init=1, dissimilarity='precomputed') else: mds = manifold.MDS(max_iter=200, eps=1e-4, n_init=1) dp_mds = mds.fit_transform(dp) logger.info("PLOT: end mds, start plot") plot_scatter_diagram(1, dp_mds[:, 0], dp_mds[ :, 1], title='cluster', style_list=cls)
Example #24
Source File: linear.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(LinearAlgorithm, self).__init__(params) logger.debug("LinearAlgorithm.__init__") self.max_iters = 1 self.library_version = sklearn.__version__ self.model = LogisticRegression(max_iter=1000, n_jobs=-1)
Example #25
Source File: linear.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(LinearRegressorAlgorithm, self).__init__(params) logger.debug("LinearRegressorAlgorithm.__init__") self.max_iters = 1 self.library_version = sklearn.__version__ self.model = LinearRegression(n_jobs=-1)
Example #26
Source File: knn.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(KNeighborsAlgorithm, self).__init__(params) logger.debug("KNeighborsAlgorithm.__init__") self.library_version = sklearn.__version__ self.max_iters = 1 self.model = KNeighborsClassifier( n_neighbors=params.get("n_neighbors", 3), weights=params.get("weights", "uniform"), algorithm="kd_tree", n_jobs=-1, )
Example #27
Source File: knn.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(KNeighborsRegressorAlgorithm, self).__init__(params) logger.debug("KNeighborsRegressorAlgorithm.__init__") self.library_version = sklearn.__version__ self.max_iters = 1 self.model = KNeighborsRegressor( n_neighbors=params.get("n_neighbors", 3), weights=params.get("weights", "uniform"), algorithm="ball_tree", n_jobs=-1, )
Example #28
Source File: decision_tree.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(DecisionTreeAlgorithm, self).__init__(params) logger.debug("DecisionTreeAlgorithm.__init__") self.library_version = sklearn.__version__ self.max_iters = additional.get("max_steps", 1) self.model = DecisionTreeClassifier( criterion=params.get("criterion", "gini"), max_depth=params.get("max_depth", 3), random_state=params.get("seed", 1), )
Example #29
Source File: decision_tree.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(DecisionTreeRegressorAlgorithm, self).__init__(params) logger.debug("DecisionTreeRegressorAlgorithm.__init__") self.library_version = sklearn.__version__ self.max_iters = additional.get("max_steps", 1) self.model = DecisionTreeRegressor( criterion=params.get("criterion", "mse"), max_depth=params.get("max_depth", 3), random_state=params.get("seed", 1), )
Example #30
Source File: baseline.py From mljar-supervised with MIT License | 5 votes |
def __init__(self, params): super(BaselineClassifierAlgorithm, self).__init__(params) logger.debug("BaselineClassifierAlgorithm.__init__") self.library_version = sklearn.__version__ self.max_iters = additional.get("max_steps", 1) self.model = DummyClassifier( strategy="prior", random_state=params.get("seed", 1) )