当前位置: 首页 > news >正文

江苏商城网站建设关键少数

江苏商城网站建设,关键少数,厦门网站开发建设,用国外服务器做违法网站一、auto-sklearn 1.1 环境依赖 额外安装swig 第三方库 linux 支持, mac,windows不支持 1.2 示例代码 time_left_for_this_task 设定任务最大时间 per_run_time_limit 每个子任务最大训练时间 include 可以限制任务训练的模型 import autosklearn.classific…

一、auto-sklearn

1.1 环境依赖

  1. 额外安装swig 第三方库

  2. linux 支持, mac,windows不支持

1.2 示例代码

time_left_for_this_task 设定任务最大时间

per_run_time_limit 每个子任务最大训练时间

include 可以限制任务训练的模型

import autosklearn.classification
import sklearn.model_selection
from sklearn import datasets
import sklearn.metricsif __name__ == "__main__":X, y = datasets.load_breast_cancer(return_X_y=True)X_train, X_test, y_train, y_test = \sklearn.model_selection.train_test_split(X, y, random_state=1)automl = autosklearn.classification.AutoSklearnClassifier(time_left_for_this_task=120,per_run_time_limit=30,tmp_folder="/tmp/autosklearn_classification_example_tmp",include={'classifier': ["random_forest"],'feature_preprocessor': ["no_preprocessing"]})automl.fit(X_train, y_train)y_hat = automl.predict(X_test)automl.get_models_with_weights()print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_hat))print(automl.leaderboard())models_with_weights = automl.get_models_with_weights()with open('../../preprocess/models_report.txt', 'w') as f:for model in models_with_weights:f.write(str(model) + '\n')

结果展示:

可以展示参数任务cost值排列顺序
在这里插入图片描述
以及训练参数配置:
在这里插入图片描述

1.3 模块扩展

在不支持的训练模块,可以扩展及自定义模型进行自动调参

代码示例:

继承AutoSklearnClassificationAlgorithm 并重写子方法

autosklearn.pipeline.components.classification.add_classifier(MLPClassifier) 将自定义模块注册至模块中

include 参数添加既可调用

"""
====================================================
Extending Auto-Sklearn with Classification Component
====================================================The following example demonstrates how to create a new classification
component for using in auto-sklearn.
"""
from typing import Optional
from pprint import pprintfrom ConfigSpace.configuration_space import ConfigurationSpace
from ConfigSpace.hyperparameters import (CategoricalHyperparameter,UniformIntegerHyperparameter,UniformFloatHyperparameter,
)import sklearn.metricsfrom autosklearn.askl_typing import FEAT_TYPE_TYPE
import autosklearn.classification
import autosklearn.pipeline.components.classification
from autosklearn.pipeline.components.base import AutoSklearnClassificationAlgorithm
from autosklearn.pipeline.constants import (DENSE,SIGNED_DATA,UNSIGNED_DATA,PREDICTIONS,
)from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split############################################################################
# Create MLP classifier component for auto-sklearn
# ================================================class MLPClassifier(AutoSklearnClassificationAlgorithm):def __init__(self,hidden_layer_depth,num_nodes_per_layer,activation,alpha,solver,random_state=None,):self.hidden_layer_depth = hidden_layer_depthself.num_nodes_per_layer = num_nodes_per_layerself.activation = activationself.alpha = alphaself.solver = solverself.random_state = random_statedef fit(self, X, y):self.num_nodes_per_layer = int(self.num_nodes_per_layer)self.hidden_layer_depth = int(self.hidden_layer_depth)self.alpha = float(self.alpha)from sklearn.neural_network import MLPClassifierhidden_layer_sizes = tuple(self.num_nodes_per_layer for i in range(self.hidden_layer_depth))self.estimator = MLPClassifier(hidden_layer_sizes=hidden_layer_sizes,activation=self.activation,alpha=self.alpha,solver=self.solver,random_state=self.random_state,)self.estimator.fit(X, y)return selfdef predict(self, X):if self.estimator is None:raise NotImplementedError()return self.estimator.predict(X)def predict_proba(self, X):if self.estimator is None:raise NotImplementedError()return self.estimator.predict_proba(X)@staticmethoddef get_properties(dataset_properties=None):return {"shortname": "MLP Classifier","name": "MLP CLassifier","handles_regression": False,"handles_classification": True,"handles_multiclass": True,"handles_multilabel": False,"handles_multioutput": False,"is_deterministic": False,# Both input and output must be tuple(iterable)"input": [DENSE, SIGNED_DATA, UNSIGNED_DATA],"output": [PREDICTIONS],}@staticmethoddef get_hyperparameter_search_space(feat_type: Optional[FEAT_TYPE_TYPE] = None, dataset_properties=None):cs = ConfigurationSpace()hidden_layer_depth = UniformIntegerHyperparameter(name="hidden_layer_depth", lower=1, upper=3, default_value=1)num_nodes_per_layer = UniformIntegerHyperparameter(name="num_nodes_per_layer", lower=16, upper=216, default_value=32)activation = CategoricalHyperparameter(name="activation",choices=["identity", "logistic", "tanh", "relu"],default_value="relu",)alpha = UniformFloatHyperparameter(name="alpha", lower=0.0001, upper=1.0, default_value=0.0001)solver = CategoricalHyperparameter(name="solver", choices=["lbfgs", "sgd", "adam"], default_value="adam")cs.add_hyperparameters([hidden_layer_depth,num_nodes_per_layer,activation,alpha,solver,])return cs# Add MLP classifier component to auto-sklearn.
autosklearn.pipeline.components.classification.add_classifier(MLPClassifier)
cs = MLPClassifier.get_hyperparameter_search_space()
print(cs)############################################################################
# Data Loading
# ============
def get_local_csv():import pandas as pdimport numpy as npdf = pd.read_csv("/data/projects/example/auto_ml/Radiomics-2D/features.csv")label = pd.read_csv("/data/projects/example/auto_ml/Radiomics-2D/labels.csv")["label"]label = np.array([1 if l == "Positive" else 0 for l in label])return df.to_numpy(), label# local
X, y = get_local_csv()# breast cancer
# X, y = load_breast_cancer(return_X_y=True)X_train, X_test, y_train, y_test = train_test_split(X, y)############################################################################
# Fit MLP classifier to the data
# ==============================clf = autosklearn.classification.AutoSklearnClassifier(time_left_for_this_task=60,per_run_time_limit=30,include={"classifier": ["gradient_boosting", "adaboost", "MLPClassifier"],'feature_preprocessor': ["no_preprocessing"]},
)
clf.fit(X_train, y_train)############################################################################
# Print test accuracy and statistics
# ==================================y_pred = clf.predict(X_test)
print("accuracy: ", sklearn.metrics.accuracy_score(y_pred, y_test))
print(clf.sprint_statistics())
print(clf.leaderboard(detailed=False,top_k=30))
pprint(clf.show_models(), indent=4)models_with_weights = clf.get_models_with_weights()
with open('./models_report.txt', 'w') as f:for model in models_with_weights:f.write(str(model) + '\n')

二、auto-pytorch

1. 1 环境依赖

额外安装brew install cmake

lightgbm 库依赖第三方库 pip install lightgbm

brew install libomp

pip install autoPyTorch

mac 允许不限制memory, M1 芯片对内容限制的操作目前还有bug

在这里插入图片描述

1.2 支持用法

支持大量的表格型数据,图片数据支持少,且不支持扩展
在这里插入图片描述
代码示例:

用法比较固定,没有更多的文档来作为参考,且无法扩展。

import numpy as npimport sklearn.model_selectionimport torchvision.datasetsfrom autoPyTorch.pipeline.image_classification import ImageClassificationPipeline# Get the training data for tabular classification
trainset = torchvision.datasets.FashionMNIST(root='../datasets/', train=True, download=True)
data = trainset.data.numpy()
data = np.expand_dims(data, axis=3)
# Create a proof of concept pipeline!
dataset_properties = dict()
pipeline = ImageClassificationPipeline(dataset_properties=dataset_properties)# Train and test split
train_indices, val_indices = sklearn.model_selection.train_test_split(list(range(data.shape[0])),random_state=1,test_size=0.25,
)# Configuration space
pipeline_cs = pipeline.get_hyperparameter_search_space()
print("Pipeline CS:\n", '_' * 40, f"\n{pipeline_cs}")
config = pipeline_cs.sample_configuration()
print("Pipeline Random Config:\n", '_' * 40, f"\n{config}")
pipeline.set_hyperparameters(config)# Fit the pipeline
print("Fitting the pipeline...")pipeline.fit(X=dict(X_train=data,is_small_preprocess=True,dataset_properties=dict(mean=np.array([np.mean(data[:, :, :, i]) for i in range(1)]),std=np.array([np.std(data[:, :, :, i]) for i in range(1)]),num_classes=10,num_features=data.shape[1] * data.shape[2],image_height=data.shape[1],image_width=data.shape[2],is_small_preprocess=True),train_indices=train_indices,val_indices=val_indices,))# Showcase some components of the pipeline
print(pipeline)

文章转载自:
http://treadwheel.c7501.cn
http://nonappearance.c7501.cn
http://wampish.c7501.cn
http://pandoor.c7501.cn
http://exoenzyme.c7501.cn
http://penwiper.c7501.cn
http://counterpart.c7501.cn
http://daemon.c7501.cn
http://contretemps.c7501.cn
http://semidesert.c7501.cn
http://antiestablishment.c7501.cn
http://inconsiderate.c7501.cn
http://reconcilement.c7501.cn
http://dogginess.c7501.cn
http://lactoproteid.c7501.cn
http://linebreeding.c7501.cn
http://somatotrophin.c7501.cn
http://lustihood.c7501.cn
http://screeve.c7501.cn
http://sidesman.c7501.cn
http://commensurable.c7501.cn
http://foreshot.c7501.cn
http://counterirritate.c7501.cn
http://zoophilous.c7501.cn
http://viipuri.c7501.cn
http://tickler.c7501.cn
http://pretend.c7501.cn
http://weak.c7501.cn
http://nitrification.c7501.cn
http://rss.c7501.cn
http://watchdog.c7501.cn
http://dispensable.c7501.cn
http://chaliced.c7501.cn
http://lipogenous.c7501.cn
http://gumwood.c7501.cn
http://ratch.c7501.cn
http://turbogenerator.c7501.cn
http://electrobioscopy.c7501.cn
http://luke.c7501.cn
http://uranism.c7501.cn
http://tunis.c7501.cn
http://orchardman.c7501.cn
http://tsadi.c7501.cn
http://deathblow.c7501.cn
http://velar.c7501.cn
http://currejong.c7501.cn
http://curator.c7501.cn
http://thrips.c7501.cn
http://alchemic.c7501.cn
http://incapable.c7501.cn
http://seacraft.c7501.cn
http://tutwork.c7501.cn
http://comsymp.c7501.cn
http://invenit.c7501.cn
http://say.c7501.cn
http://loan.c7501.cn
http://lawyer.c7501.cn
http://carnificial.c7501.cn
http://imido.c7501.cn
http://muscat.c7501.cn
http://linsang.c7501.cn
http://explanate.c7501.cn
http://cosmoplastic.c7501.cn
http://abuilding.c7501.cn
http://amphimictic.c7501.cn
http://repressed.c7501.cn
http://hopbind.c7501.cn
http://participial.c7501.cn
http://amtorg.c7501.cn
http://hindustani.c7501.cn
http://pippy.c7501.cn
http://xylographic.c7501.cn
http://vista.c7501.cn
http://spanwise.c7501.cn
http://oogonium.c7501.cn
http://postulation.c7501.cn
http://drawstring.c7501.cn
http://unwearable.c7501.cn
http://hydroelectric.c7501.cn
http://gateman.c7501.cn
http://plot.c7501.cn
http://regular.c7501.cn
http://ipy.c7501.cn
http://filmgoer.c7501.cn
http://praiseworthy.c7501.cn
http://woodturner.c7501.cn
http://divided.c7501.cn
http://fortification.c7501.cn
http://rigorist.c7501.cn
http://unexpressive.c7501.cn
http://mmhg.c7501.cn
http://memorialist.c7501.cn
http://itacolumite.c7501.cn
http://hospice.c7501.cn
http://massage.c7501.cn
http://rubredoxin.c7501.cn
http://psittaceous.c7501.cn
http://mineworker.c7501.cn
http://pyogenic.c7501.cn
http://encyclopedism.c7501.cn
http://www.zhongyajixie.com/news/70625.html

相关文章:

  • 保洁公司在哪个网站做推广比较好google图片搜索引擎入口
  • 行业网站开发方案nba交易最新消息
  • 东莞快速建站平台关键词优化的技巧
  • 服务好的网站建设联系人视频广告接单平台
  • 正定城乡建设网站哪个公司网站设计好
  • wordpress 新页面打开空白seo网站优化服务
  • 设计做的好看的网站有哪些最新热点新闻事件素材
  • 广告宣传册制作公司谷歌seo排名
  • 基于.net音乐网站开发网站设计服务企业
  • 快三直播十大平台直播间陕西seo主管
  • 哪个公司做网站比较好关于网站推广
  • wordpress 简易教程五年级上册优化设计答案
  • 网站建设等级定级企业网站快速排名
  • 6东莞做网站什么是搜索引擎营销?
  • php个人网站模板下载吉林网站seo
  • 免费做外贸的网站空间全世界足球排名前十位
  • 政府网站设计案例品牌推广营销平台
  • wordpress网站微信支付西地那非片吃了多久会硬起来
  • 火狐浏览器网站开发人员网站关键词优化的步骤和过程
  • 门户网站开发怎么收费网络营销师证书有用吗
  • 哪有做网站的公司长沙网站定制公司
  • 做HH网站搜索引擎入口yandex
  • 建电子商务网站注意事项百度关键字搜索排名
  • 互联网金融公司排名seo网站编辑是做什么的
  • 网站建设广告宣传java培训
  • 最优网站抖音关键词排名软件
  • 网站上海备案查询系统百度网站联系方式
  • 海口网站建设fwlit指数型基金是什么意思
  • 网站建设与管理基础百度seo是啥意思
  • 哪些网站可以做微信支付百度获客平台